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
= IDirectDrawSurface7_IsLost(primary
);
2475 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2476 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2477 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2478 hr
= IDirectDrawSurface7_IsLost(primary
);
2479 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2481 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2482 expect_messages
= NULL
;
2483 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2484 "Expected screen size %ux%u, got %ux%u.\n",
2485 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2487 GetWindowRect(window
, &r
);
2488 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2489 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2490 r
.left
, r
.top
, r
.right
, r
.bottom
);
2492 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2493 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2494 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2495 param
.user32_width
, ddsd
.dwWidth
);
2496 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2497 param
.user32_height
, ddsd
.dwHeight
);
2498 IDirectDrawSurface7_Release(primary
);
2500 memset(&ddsd
, 0, sizeof(ddsd
));
2501 ddsd
.dwSize
= sizeof(ddsd
);
2502 ddsd
.dwFlags
= DDSD_CAPS
;
2503 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2505 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2506 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2507 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2508 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2509 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2510 param
.ddraw_width
, ddsd
.dwWidth
);
2511 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2512 param
.ddraw_height
, ddsd
.dwHeight
);
2514 GetWindowRect(window
, &r
);
2515 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2516 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2517 r
.left
, r
.top
, r
.right
, r
.bottom
);
2519 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2520 expect_messages
= exclusive_messages
;
2524 hr
= IDirectDrawSurface7_IsLost(primary
);
2525 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2526 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2527 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2528 hr
= IDirectDrawSurface7_IsLost(primary
);
2529 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2531 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2532 expect_messages
= NULL
;
2533 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2534 "Expected screen size %ux%u, got %ux%u.\n",
2535 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2537 GetWindowRect(window
, &r
);
2538 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2539 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2540 r
.left
, r
.top
, r
.right
, r
.bottom
);
2542 expect_messages
= exclusive_focus_loss_messages
;
2543 ret
= SetForegroundWindow(GetDesktopWindow());
2544 ok(ret
, "Failed to set foreground window.\n");
2545 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2546 memset(&devmode
, 0, sizeof(devmode
));
2547 devmode
.dmSize
= sizeof(devmode
);
2548 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2549 ok(ret
, "Failed to get display mode.\n");
2550 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2551 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2552 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2554 expect_messages
= exclusive_focus_restore_messages
;
2555 ShowWindow(window
, SW_RESTORE
);
2556 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2558 GetWindowRect(window
, &r
);
2559 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2560 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2561 r
.left
, r
.top
, r
.right
, r
.bottom
);
2562 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2563 ok(ret
, "Failed to get display mode.\n");
2564 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2565 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2566 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2568 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2569 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2570 /* Normally the primary should be restored here. Unfortunately this causes the
2571 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2572 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2573 * the point of the GetSurfaceDesc call. */
2575 expect_messages
= sc_minimize_messages
;
2576 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2577 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2578 expect_messages
= NULL
;
2580 expect_messages
= sc_restore_messages
;
2581 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2582 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2583 expect_messages
= NULL
;
2585 expect_messages
= sc_maximize_messages
;
2586 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2587 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2588 expect_messages
= NULL
;
2590 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2591 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2593 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2594 expect_messages
= exclusive_messages
;
2598 hr
= IDirectDrawSurface7_IsLost(primary
);
2599 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2600 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
2601 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2602 hr
= IDirectDrawSurface7_IsLost(primary
);
2603 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2605 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2606 expect_messages
= NULL
;
2607 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2608 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2609 "Expected screen size %ux%u, got %ux%u.\n",
2610 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2612 GetWindowRect(window
, &r
);
2613 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2614 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2615 r
.left
, r
.top
, r
.right
, r
.bottom
);
2617 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2618 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2619 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2620 param
.ddraw_width
, ddsd
.dwWidth
);
2621 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2622 param
.ddraw_height
, ddsd
.dwHeight
);
2623 IDirectDrawSurface7_Release(primary
);
2626 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2627 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2629 memset(&ddsd
, 0, sizeof(ddsd
));
2630 ddsd
.dwSize
= sizeof(ddsd
);
2631 ddsd
.dwFlags
= DDSD_CAPS
;
2632 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2634 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2635 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2636 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2637 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2638 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2639 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2640 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2641 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2643 GetWindowRect(window
, &r
);
2644 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2645 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2646 r
.left
, r
.top
, r
.right
, r
.bottom
);
2648 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2649 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2651 GetWindowRect(window
, &r
);
2652 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2653 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2654 r
.left
, r
.top
, r
.right
, r
.bottom
);
2656 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2657 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2658 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2659 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2660 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2661 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2662 IDirectDrawSurface7_Release(primary
);
2664 memset(&ddsd
, 0, sizeof(ddsd
));
2665 ddsd
.dwSize
= sizeof(ddsd
);
2666 ddsd
.dwFlags
= DDSD_CAPS
;
2667 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2669 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2670 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2671 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2672 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2673 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2674 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2675 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2676 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2678 GetWindowRect(window
, &r
);
2679 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2680 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2681 r
.left
, r
.top
, r
.right
, r
.bottom
);
2683 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2684 expect_messages
= normal_messages
;
2688 hr
= IDirectDrawSurface7_IsLost(primary
);
2689 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2690 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2691 devmode
.dmPelsWidth
= param
.user32_width
;
2692 devmode
.dmPelsHeight
= param
.user32_height
;
2693 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2694 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2695 hr
= IDirectDrawSurface7_IsLost(primary
);
2696 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2698 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2699 expect_messages
= NULL
;
2700 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2702 GetWindowRect(window
, &r
);
2703 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2704 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2705 r
.left
, r
.top
, r
.right
, r
.bottom
);
2707 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2708 expect_messages
= normal_messages
;
2712 hr
= IDirectDrawSurface7_Restore(primary
);
2713 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2714 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2715 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2716 hr
= IDirectDrawSurface7_Restore(primary
);
2717 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2718 hr
= IDirectDrawSurface7_IsLost(primary
);
2719 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2721 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2722 expect_messages
= NULL
;
2723 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2725 GetWindowRect(window
, &r
);
2726 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2727 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2728 r
.left
, r
.top
, r
.right
, r
.bottom
);
2730 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2731 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2732 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2733 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2734 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2735 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2736 IDirectDrawSurface7_Release(primary
);
2738 memset(&ddsd
, 0, sizeof(ddsd
));
2739 ddsd
.dwSize
= sizeof(ddsd
);
2740 ddsd
.dwFlags
= DDSD_CAPS
;
2741 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2743 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2744 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2745 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2746 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2747 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2748 param
.ddraw_width
, ddsd
.dwWidth
);
2749 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2750 param
.ddraw_height
, ddsd
.dwHeight
);
2752 GetWindowRect(window
, &r
);
2753 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2754 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2755 r
.left
, r
.top
, r
.right
, r
.bottom
);
2757 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2758 expect_messages
= normal_messages
;
2762 hr
= IDirectDrawSurface7_IsLost(primary
);
2763 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2764 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
2765 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2766 hr
= IDirectDrawSurface7_IsLost(primary
);
2767 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2769 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2770 expect_messages
= NULL
;
2771 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2773 GetWindowRect(window
, &r
);
2774 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2775 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2776 r
.left
, r
.top
, r
.right
, r
.bottom
);
2778 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2779 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2780 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2781 param
.ddraw_width
, ddsd
.dwWidth
);
2782 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2783 param
.ddraw_height
, ddsd
.dwHeight
);
2784 IDirectDrawSurface7_Release(primary
);
2786 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2787 ok(ret
, "Failed to get display mode.\n");
2788 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2789 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2790 "Expected resolution %ux%u, got %ux%u.\n",
2791 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2792 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2793 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2794 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2796 memset(&ddsd
, 0, sizeof(ddsd
));
2797 ddsd
.dwSize
= sizeof(ddsd
);
2798 ddsd
.dwFlags
= DDSD_CAPS
;
2799 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2801 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2802 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2803 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2804 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2805 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2806 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2807 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2808 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2810 GetWindowRect(window
, &r
);
2811 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2812 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2813 r
.left
, r
.top
, r
.right
, r
.bottom
);
2815 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2816 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2817 * not DDSCL_FULLSCREEN. */
2818 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2819 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2821 GetWindowRect(window
, &r
);
2822 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2823 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2824 r
.left
, r
.top
, r
.right
, r
.bottom
);
2826 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2827 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2828 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2829 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2830 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2831 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2832 IDirectDrawSurface7_Release(primary
);
2834 memset(&ddsd
, 0, sizeof(ddsd
));
2835 ddsd
.dwSize
= sizeof(ddsd
);
2836 ddsd
.dwFlags
= DDSD_CAPS
;
2837 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2839 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2840 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2841 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2842 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2843 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2844 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2845 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2846 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2848 GetWindowRect(window
, &r
);
2849 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2850 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2851 r
.left
, r
.top
, r
.right
, r
.bottom
);
2853 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2854 expect_messages
= normal_messages
;
2858 hr
= IDirectDrawSurface7_IsLost(primary
);
2859 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2860 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2861 devmode
.dmPelsWidth
= param
.user32_width
;
2862 devmode
.dmPelsHeight
= param
.user32_height
;
2863 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2864 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2865 hr
= IDirectDrawSurface7_IsLost(primary
);
2866 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2868 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2869 expect_messages
= NULL
;
2870 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2872 GetWindowRect(window
, &r
);
2873 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2874 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2875 r
.left
, r
.top
, r
.right
, r
.bottom
);
2877 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2878 expect_messages
= normal_messages
;
2882 hr
= IDirectDrawSurface7_Restore(primary
);
2883 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2884 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2885 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2886 hr
= IDirectDrawSurface7_Restore(primary
);
2887 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2888 hr
= IDirectDrawSurface7_IsLost(primary
);
2889 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2891 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2892 expect_messages
= NULL
;
2893 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2895 GetWindowRect(window
, &r
);
2896 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2897 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2898 r
.left
, r
.top
, r
.right
, r
.bottom
);
2900 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2901 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2902 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2903 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2904 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2905 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2906 IDirectDrawSurface7_Release(primary
);
2908 memset(&ddsd
, 0, sizeof(ddsd
));
2909 ddsd
.dwSize
= sizeof(ddsd
);
2910 ddsd
.dwFlags
= DDSD_CAPS
;
2911 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2913 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2914 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2915 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2916 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2917 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2918 param
.ddraw_width
, ddsd
.dwWidth
);
2919 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2920 param
.ddraw_height
, ddsd
.dwHeight
);
2922 GetWindowRect(window
, &r
);
2923 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2924 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2925 r
.left
, r
.top
, r
.right
, r
.bottom
);
2927 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2928 expect_messages
= normal_messages
;
2932 hr
= IDirectDrawSurface7_IsLost(primary
);
2933 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2934 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
2935 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2936 hr
= IDirectDrawSurface7_IsLost(primary
);
2937 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2939 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2940 expect_messages
= NULL
;
2941 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2943 GetWindowRect(window
, &r
);
2944 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2945 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2946 r
.left
, r
.top
, r
.right
, r
.bottom
);
2948 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2949 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2950 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2951 param
.ddraw_width
, ddsd
.dwWidth
);
2952 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2953 param
.ddraw_height
, ddsd
.dwHeight
);
2954 IDirectDrawSurface7_Release(primary
);
2956 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2957 ok(ret
, "Failed to get display mode.\n");
2958 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2959 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2960 "Expected resolution %ux%u, got %ux%u.\n",
2961 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2962 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2963 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2964 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2966 memset(&ddsd
, 0, sizeof(ddsd
));
2967 ddsd
.dwSize
= sizeof(ddsd
);
2968 ddsd
.dwFlags
= DDSD_CAPS
;
2969 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2971 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2972 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2973 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2974 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2975 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2976 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2977 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2978 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2979 IDirectDrawSurface7_Release(primary
);
2981 GetWindowRect(window
, &r
);
2982 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2983 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2984 r
.left
, r
.top
, r
.right
, r
.bottom
);
2986 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2987 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2988 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2989 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2990 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2992 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2993 expect_messages
= exclusive_messages
;
2997 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2998 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3000 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3001 expect_messages
= NULL
;
3002 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
3003 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
3004 "Expected screen size %ux%u, got %ux%u.\n",
3005 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3006 screen_size
.cx
, screen_size
.cy
);
3008 GetWindowRect(window
, &r
);
3009 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3010 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3011 r
.left
, r
.top
, r
.right
, r
.bottom
);
3013 memset(&ddsd
, 0, sizeof(ddsd
));
3014 ddsd
.dwSize
= sizeof(ddsd
);
3015 ddsd
.dwFlags
= DDSD_CAPS
;
3016 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3018 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3019 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3020 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
3021 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3022 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3023 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3024 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3025 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3026 IDirectDrawSurface7_Release(primary
);
3028 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3029 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3030 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3031 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3032 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3034 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3035 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3037 memset(&ddsd
, 0, sizeof(ddsd
));
3038 ddsd
.dwSize
= sizeof(ddsd
);
3039 ddsd
.dwFlags
= DDSD_CAPS
;
3040 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3042 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3043 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3044 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
3045 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3046 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3047 param
.ddraw_width
, ddsd
.dwWidth
);
3048 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3049 param
.ddraw_height
, ddsd
.dwHeight
);
3050 IDirectDrawSurface7_Release(primary
);
3052 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
3053 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3055 /* If the window is changed at the same time, messages are sent to the new window. */
3056 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3057 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3058 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3059 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3061 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3062 expect_messages
= exclusive_messages
;
3065 screen_size2
.cx
= 0;
3066 screen_size2
.cy
= 0;
3068 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3069 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3071 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3072 expect_messages
= NULL
;
3073 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
3074 screen_size
.cx
, screen_size
.cy
);
3075 ok(screen_size2
.cx
== registry_mode
.dmPelsWidth
&& screen_size2
.cy
== registry_mode
.dmPelsHeight
,
3076 "Expected screen size 2 %ux%u, got %ux%u.\n",
3077 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size2
.cx
, screen_size2
.cy
);
3079 GetWindowRect(window
, &r
);
3080 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3081 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
3082 r
.left
, r
.top
, r
.right
, r
.bottom
);
3083 GetWindowRect(window2
, &r
);
3084 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3085 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3086 r
.left
, r
.top
, r
.right
, r
.bottom
);
3088 memset(&ddsd
, 0, sizeof(ddsd
));
3089 ddsd
.dwSize
= sizeof(ddsd
);
3090 ddsd
.dwFlags
= DDSD_CAPS
;
3091 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3093 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3094 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3095 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
3096 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3097 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3098 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3099 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3100 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3101 IDirectDrawSurface7_Release(primary
);
3103 ref
= IDirectDraw7_Release(ddraw
);
3104 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3106 GetWindowRect(window
, &r
);
3107 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3108 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
3109 r
.left
, r
.top
, r
.right
, r
.bottom
);
3111 expect_messages
= NULL
;
3112 DestroyWindow(window
);
3113 DestroyWindow(window2
);
3114 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3115 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3118 static void test_coop_level_mode_set_multi(void)
3120 IDirectDraw7
*ddraw1
, *ddraw2
;
3126 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3127 0, 0, 100, 100, 0, 0, 0, 0);
3128 ddraw1
= create_ddraw();
3129 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3131 /* With just a single ddraw object, the display mode is restored on
3133 hr
= set_display_mode(ddraw1
, 800, 600);
3134 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3135 w
= GetSystemMetrics(SM_CXSCREEN
);
3136 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3137 h
= GetSystemMetrics(SM_CYSCREEN
);
3138 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3140 ref
= IDirectDraw7_Release(ddraw1
);
3141 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3142 w
= GetSystemMetrics(SM_CXSCREEN
);
3143 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3144 h
= GetSystemMetrics(SM_CYSCREEN
);
3145 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3147 /* When there are multiple ddraw objects, the display mode is restored to
3148 * the initial mode, before the first SetDisplayMode() call. */
3149 ddraw1
= create_ddraw();
3150 hr
= set_display_mode(ddraw1
, 800, 600);
3151 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3152 w
= GetSystemMetrics(SM_CXSCREEN
);
3153 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3154 h
= GetSystemMetrics(SM_CYSCREEN
);
3155 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3157 ddraw2
= create_ddraw();
3158 hr
= set_display_mode(ddraw2
, 640, 480);
3159 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3160 w
= GetSystemMetrics(SM_CXSCREEN
);
3161 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3162 h
= GetSystemMetrics(SM_CYSCREEN
);
3163 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3165 ref
= IDirectDraw7_Release(ddraw2
);
3166 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3167 w
= GetSystemMetrics(SM_CXSCREEN
);
3168 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3169 h
= GetSystemMetrics(SM_CYSCREEN
);
3170 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3172 ref
= IDirectDraw7_Release(ddraw1
);
3173 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3174 w
= GetSystemMetrics(SM_CXSCREEN
);
3175 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3176 h
= GetSystemMetrics(SM_CYSCREEN
);
3177 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3179 /* Regardless of release ordering. */
3180 ddraw1
= create_ddraw();
3181 hr
= set_display_mode(ddraw1
, 800, 600);
3182 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3183 w
= GetSystemMetrics(SM_CXSCREEN
);
3184 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3185 h
= GetSystemMetrics(SM_CYSCREEN
);
3186 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3188 ddraw2
= create_ddraw();
3189 hr
= set_display_mode(ddraw2
, 640, 480);
3190 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3191 w
= GetSystemMetrics(SM_CXSCREEN
);
3192 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3193 h
= GetSystemMetrics(SM_CYSCREEN
);
3194 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3196 ref
= IDirectDraw7_Release(ddraw1
);
3197 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3198 w
= GetSystemMetrics(SM_CXSCREEN
);
3199 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3200 h
= GetSystemMetrics(SM_CYSCREEN
);
3201 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3203 ref
= IDirectDraw7_Release(ddraw2
);
3204 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3205 w
= GetSystemMetrics(SM_CXSCREEN
);
3206 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3207 h
= GetSystemMetrics(SM_CYSCREEN
);
3208 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3210 /* But only for ddraw objects that called SetDisplayMode(). */
3211 ddraw1
= create_ddraw();
3212 ddraw2
= create_ddraw();
3213 hr
= set_display_mode(ddraw2
, 640, 480);
3214 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3215 w
= GetSystemMetrics(SM_CXSCREEN
);
3216 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3217 h
= GetSystemMetrics(SM_CYSCREEN
);
3218 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3220 ref
= IDirectDraw7_Release(ddraw1
);
3221 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3222 w
= GetSystemMetrics(SM_CXSCREEN
);
3223 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3224 h
= GetSystemMetrics(SM_CYSCREEN
);
3225 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3227 ref
= IDirectDraw7_Release(ddraw2
);
3228 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3229 w
= GetSystemMetrics(SM_CXSCREEN
);
3230 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3231 h
= GetSystemMetrics(SM_CYSCREEN
);
3232 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3234 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3235 * restoring the display mode. */
3236 ddraw1
= create_ddraw();
3237 hr
= set_display_mode(ddraw1
, 800, 600);
3238 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3239 w
= GetSystemMetrics(SM_CXSCREEN
);
3240 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3241 h
= GetSystemMetrics(SM_CYSCREEN
);
3242 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3244 ddraw2
= create_ddraw();
3245 hr
= set_display_mode(ddraw2
, 640, 480);
3246 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3247 w
= GetSystemMetrics(SM_CXSCREEN
);
3248 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3249 h
= GetSystemMetrics(SM_CYSCREEN
);
3250 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3252 hr
= IDirectDraw7_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3253 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3255 ref
= IDirectDraw7_Release(ddraw1
);
3256 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3257 w
= GetSystemMetrics(SM_CXSCREEN
);
3258 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3259 h
= GetSystemMetrics(SM_CYSCREEN
);
3260 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3262 ref
= IDirectDraw7_Release(ddraw2
);
3263 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3264 w
= GetSystemMetrics(SM_CXSCREEN
);
3265 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3266 h
= GetSystemMetrics(SM_CYSCREEN
);
3267 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3269 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3270 ddraw1
= create_ddraw();
3271 hr
= set_display_mode(ddraw1
, 800, 600);
3272 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3273 w
= GetSystemMetrics(SM_CXSCREEN
);
3274 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3275 h
= GetSystemMetrics(SM_CYSCREEN
);
3276 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3278 hr
= IDirectDraw7_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3279 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3281 ddraw2
= create_ddraw();
3282 hr
= set_display_mode(ddraw2
, 640, 480);
3283 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3285 ref
= IDirectDraw7_Release(ddraw1
);
3286 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3287 w
= GetSystemMetrics(SM_CXSCREEN
);
3288 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3289 h
= GetSystemMetrics(SM_CYSCREEN
);
3290 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3292 ref
= IDirectDraw7_Release(ddraw2
);
3293 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3294 w
= GetSystemMetrics(SM_CXSCREEN
);
3295 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3296 h
= GetSystemMetrics(SM_CYSCREEN
);
3297 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3299 DestroyWindow(window
);
3302 static void test_initialize(void)
3304 IDirectDraw7
*ddraw
;
3307 ddraw
= create_ddraw();
3308 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3310 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
3311 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3312 IDirectDraw7_Release(ddraw
);
3315 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw7
, (void **)&ddraw
);
3316 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr
);
3317 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
3318 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3319 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
3320 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3321 IDirectDraw7_Release(ddraw
);
3325 static void test_coop_level_surf_create(void)
3327 IDirectDrawSurface7
*surface
;
3328 IDirectDraw7
*ddraw
;
3329 DDSURFACEDESC2 ddsd
;
3332 ddraw
= create_ddraw();
3333 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3335 memset(&ddsd
, 0, sizeof(ddsd
));
3336 ddsd
.dwSize
= sizeof(ddsd
);
3337 ddsd
.dwFlags
= DDSD_CAPS
;
3338 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3339 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3340 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3342 IDirectDraw7_Release(ddraw
);
3345 static void test_vb_discard(void)
3347 static const struct vec4 quad
[] =
3349 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
3350 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
3351 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
3352 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
3355 IDirect3DDevice7
*device
;
3357 IDirect3DVertexBuffer7
*buffer
;
3360 D3DVERTEXBUFFERDESC desc
;
3362 static const unsigned int vbsize
= 16;
3365 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3366 0, 0, 640, 480, 0, 0, 0, 0);
3368 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3370 skip("Failed to create a 3D device, skipping test.\n");
3371 DestroyWindow(window
);
3375 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
3376 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
3378 memset(&desc
, 0, sizeof(desc
));
3379 desc
.dwSize
= sizeof(desc
);
3380 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
3381 desc
.dwFVF
= D3DFVF_XYZRHW
;
3382 desc
.dwNumVertices
= vbsize
;
3383 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0);
3384 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3386 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3387 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3388 memcpy(data
, quad
, sizeof(quad
));
3389 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3390 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3392 hr
= IDirect3DDevice7_BeginScene(device
);
3393 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3394 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
3395 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3396 hr
= IDirect3DDevice7_EndScene(device
);
3397 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3399 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3400 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3401 memset(data
, 0xaa, sizeof(struct vec4
) * vbsize
);
3402 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3403 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3405 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3406 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3407 for (i
= 0; i
< sizeof(struct vec4
) * vbsize
; i
++)
3409 if (data
[i
] != 0xaa)
3411 ok(FALSE
, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i
, data
[i
]);
3415 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3416 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3418 IDirect3DVertexBuffer7_Release(buffer
);
3419 IDirect3D7_Release(d3d
);
3420 IDirect3DDevice7_Release(device
);
3421 DestroyWindow(window
);
3424 static void test_coop_level_multi_window(void)
3426 HWND window1
, window2
;
3427 IDirectDraw7
*ddraw
;
3430 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3431 0, 0, 640, 480, 0, 0, 0, 0);
3432 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3433 0, 0, 640, 480, 0, 0, 0, 0);
3434 ddraw
= create_ddraw();
3435 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3437 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3438 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3439 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3440 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3441 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3442 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3444 IDirectDraw7_Release(ddraw
);
3445 DestroyWindow(window2
);
3446 DestroyWindow(window1
);
3449 static void test_draw_strided(void)
3451 static struct vec3 position
[] =
3458 static DWORD diffuse
[] =
3460 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3462 static WORD indices
[] =
3467 IDirectDrawSurface7
*rt
;
3468 IDirect3DDevice7
*device
;
3472 D3DDRAWPRIMITIVESTRIDEDDATA strided
;
3474 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3475 0, 0, 640, 480, 0, 0, 0, 0);
3477 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3479 skip("Failed to create a 3D device, skipping test.\n");
3480 DestroyWindow(window
);
3484 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3485 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3487 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3488 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3489 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 1.0f
, 0);
3490 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3491 hr
= IDirect3DDevice7_BeginScene(device
);
3492 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3494 memset(&strided
, 0x55, sizeof(strided
));
3495 strided
.position
.lpvData
= position
;
3496 strided
.position
.dwStride
= sizeof(*position
);
3497 strided
.diffuse
.lpvData
= diffuse
;
3498 strided
.diffuse
.dwStride
= sizeof(*diffuse
);
3499 hr
= IDirect3DDevice7_DrawIndexedPrimitiveStrided(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
3500 &strided
, 4, indices
, 6, 0);
3501 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3503 hr
= IDirect3DDevice7_EndScene(device
);
3504 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3506 color
= get_surface_color(rt
, 320, 240);
3507 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3509 IDirectDrawSurface7_Release(rt
);
3510 IDirect3DDevice7_Release(device
);
3511 DestroyWindow(window
);
3514 static void test_lighting(void)
3516 static D3DMATRIX mat
=
3518 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3519 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3520 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3521 0.0f
, 0.0f
, 0.0f
, 1.0f
,
3525 1.0f
, 0.0f
, 1.0f
, 0.0f
,
3526 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3527 1.0f
, 0.0f
, 1.0f
, 0.0f
,
3528 0.0f
, 0.0f
, 0.5f
, 1.0f
,
3532 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3533 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3534 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
3535 10.f
, 10.0f
, 10.0f
, 1.0f
,
3539 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3540 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3541 0.0f
, 0.0f
, 1.0f
, -1.0f
,
3542 10.f
, 10.0f
, 10.0f
, 0.0f
,
3546 struct vec3 position
;
3551 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
3552 {{-1.0f
, 0.0f
, 0.1f
}, 0xffff0000},
3553 {{ 0.0f
, 0.0f
, 0.1f
}, 0xffff0000},
3554 {{ 0.0f
, -1.0f
, 0.1f
}, 0xffff0000},
3558 {{-1.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
3559 {{-1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
3560 {{ 0.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
3561 {{ 0.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
3565 struct vec3 position
;
3571 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3572 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3573 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3574 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3578 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3579 {{0.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3580 {{1.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3581 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3585 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3586 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3587 {{ 1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3588 {{ 1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3592 {{-10.0f
, -11.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3593 {{-10.0f
, -9.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3594 {{-10.0f
, -9.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3595 {{-10.0f
, -11.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3599 {{-11.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3600 {{-11.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3601 {{ -9.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3602 {{ -9.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3604 static WORD indices
[] = {0, 1, 2, 2, 3, 0};
3607 D3DMATRIX
*world_matrix
;
3610 const char *message
;
3614 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
3615 {&mat_singular
, nquad
, 0x000000ff, "Lit quad with singular world matrix"},
3616 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
3617 {&mat_nonaffine
, translatedquad
, 0x00000000, "Lit quad with non-affine matrix"},
3621 IDirect3DDevice7
*device
;
3622 IDirectDrawSurface7
*rt
;
3624 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
3625 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
3630 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3631 0, 0, 640, 480, 0, 0, 0, 0);
3632 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3634 skip("Failed to create a 3D device, skipping test.\n");
3635 DestroyWindow(window
);
3639 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3640 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3642 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
3643 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3645 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
3646 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
3647 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
3648 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
3649 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
3650 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
3651 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3652 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
3653 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
3654 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
3655 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
3656 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
3657 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
3658 ok(SUCCEEDED(hr
), "Failed to disable stencil buffering, hr %#x.\n", hr
);
3659 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
3660 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
3662 hr
= IDirect3DDevice7_BeginScene(device
);
3663 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3665 /* No lights are defined... That means, lit vertices should be entirely black. */
3666 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3667 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3668 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, unlitquad
, 4,
3670 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3672 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
3673 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
3674 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, litquad
, 4,
3676 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3678 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3679 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3680 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, unlitnquad
, 4,
3682 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3684 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
3685 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
3686 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, litnquad
, 4,
3688 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3690 hr
= IDirect3DDevice7_EndScene(device
);
3691 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3693 color
= get_surface_color(rt
, 160, 360);
3694 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color
);
3695 color
= get_surface_color(rt
, 160, 120);
3696 ok(color
== 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color
);
3697 color
= get_surface_color(rt
, 480, 360);
3698 ok(color
== 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color
);
3699 color
= get_surface_color(rt
, 480, 120);
3700 ok(color
== 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color
);
3702 hr
= IDirect3DDevice7_LightEnable(device
, 0, TRUE
);
3703 ok(SUCCEEDED(hr
), "Failed to enable light 0, hr %#x.\n", hr
);
3705 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
3707 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, tests
[i
].world_matrix
);
3708 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
3710 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
3711 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3713 hr
= IDirect3DDevice7_BeginScene(device
);
3714 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3716 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, tests
[i
].quad
,
3718 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3720 hr
= IDirect3DDevice7_EndScene(device
);
3721 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3723 color
= get_surface_color(rt
, 320, 240);
3724 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
3727 IDirectDrawSurface7_Release(rt
);
3729 refcount
= IDirect3DDevice7_Release(device
);
3730 ok(!refcount
, "Device has %u references left.\n", refcount
);
3731 DestroyWindow(window
);
3734 static void test_specular_lighting(void)
3736 static const unsigned int vertices_side
= 5;
3737 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
3738 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_NORMAL
;
3739 static D3DMATRIX mat
=
3741 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3742 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3743 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3744 0.0f
, 0.0f
, 0.0f
, 1.0f
,
3746 static D3DLIGHT7 directional
=
3748 D3DLIGHT_DIRECTIONAL
,
3749 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3750 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3751 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3752 {{0.0f
}, {0.0f
}, {0.0f
}},
3753 {{0.0f
}, {0.0f
}, {1.0f
}},
3758 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3759 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3760 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3761 {{0.0f
}, {0.0f
}, {0.0f
}},
3762 {{0.0f
}, {0.0f
}, {0.0f
}},
3770 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3771 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3772 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3773 {{0.0f
}, {0.0f
}, {0.0f
}},
3774 {{0.0f
}, {0.0f
}, {1.0f
}},
3778 M_PI
/ 12.0f
, M_PI
/ 3.0f
3780 /* The chosen range value makes the test fail when using a manhattan
3781 * distance metric vs the correct euclidean distance. */
3785 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3786 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3787 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3788 {{0.0f
}, {0.0f
}, {0.0f
}},
3789 {{0.0f
}, {0.0f
}, {0.0f
}},
3794 static const struct expected_color
3799 expected_directional
[] =
3801 {160, 120, 0x00ffffff},
3802 {320, 120, 0x00ffffff},
3803 {480, 120, 0x00ffffff},
3804 {160, 240, 0x00ffffff},
3805 {320, 240, 0x00ffffff},
3806 {480, 240, 0x00ffffff},
3807 {160, 360, 0x00ffffff},
3808 {320, 360, 0x00ffffff},
3809 {480, 360, 0x00ffffff},
3811 expected_directional_local
[] =
3813 {160, 120, 0x003c3c3c},
3814 {320, 120, 0x00717171},
3815 {480, 120, 0x003c3c3c},
3816 {160, 240, 0x00717171},
3817 {320, 240, 0x00ffffff},
3818 {480, 240, 0x00717171},
3819 {160, 360, 0x003c3c3c},
3820 {320, 360, 0x00717171},
3821 {480, 360, 0x003c3c3c},
3825 {160, 120, 0x00282828},
3826 {320, 120, 0x005a5a5a},
3827 {480, 120, 0x00282828},
3828 {160, 240, 0x005a5a5a},
3829 {320, 240, 0x00ffffff},
3830 {480, 240, 0x005a5a5a},
3831 {160, 360, 0x00282828},
3832 {320, 360, 0x005a5a5a},
3833 {480, 360, 0x00282828},
3835 expected_point_local
[] =
3837 {160, 120, 0x00000000},
3838 {320, 120, 0x00070707},
3839 {480, 120, 0x00000000},
3840 {160, 240, 0x00070707},
3841 {320, 240, 0x00ffffff},
3842 {480, 240, 0x00070707},
3843 {160, 360, 0x00000000},
3844 {320, 360, 0x00070707},
3845 {480, 360, 0x00000000},
3849 {160, 120, 0x00000000},
3850 {320, 120, 0x00141414},
3851 {480, 120, 0x00000000},
3852 {160, 240, 0x00141414},
3853 {320, 240, 0x00ffffff},
3854 {480, 240, 0x00141414},
3855 {160, 360, 0x00000000},
3856 {320, 360, 0x00141414},
3857 {480, 360, 0x00000000},
3859 expected_spot_local
[] =
3861 {160, 120, 0x00000000},
3862 {320, 120, 0x00020202},
3863 {480, 120, 0x00000000},
3864 {160, 240, 0x00020202},
3865 {320, 240, 0x00ffffff},
3866 {480, 240, 0x00020202},
3867 {160, 360, 0x00000000},
3868 {320, 360, 0x00020202},
3869 {480, 360, 0x00000000},
3871 expected_point_range
[] =
3873 {160, 120, 0x00000000},
3874 {320, 120, 0x005a5a5a},
3875 {480, 120, 0x00000000},
3876 {160, 240, 0x005a5a5a},
3877 {320, 240, 0x00ffffff},
3878 {480, 240, 0x005a5a5a},
3879 {160, 360, 0x00000000},
3880 {320, 360, 0x005a5a5a},
3881 {480, 360, 0x00000000},
3887 const struct expected_color
*expected
;
3888 unsigned int expected_count
;
3892 {&directional
, FALSE
, expected_directional
,
3893 sizeof(expected_directional
) / sizeof(expected_directional
[0])},
3894 {&directional
, TRUE
, expected_directional_local
,
3895 sizeof(expected_directional_local
) / sizeof(expected_directional_local
[0])},
3896 {&point
, FALSE
, expected_point
,
3897 sizeof(expected_point
) / sizeof(expected_point
[0])},
3898 {&point
, TRUE
, expected_point_local
,
3899 sizeof(expected_point_local
) / sizeof(expected_point_local
[0])},
3900 {&spot
, FALSE
, expected_spot
,
3901 sizeof(expected_spot
) / sizeof(expected_spot
[0])},
3902 {&spot
, TRUE
, expected_spot_local
,
3903 sizeof(expected_spot_local
) / sizeof(expected_spot_local
[0])},
3904 {&point_range
, FALSE
, expected_point_range
,
3905 sizeof(expected_point_range
) / sizeof(expected_point_range
[0])},
3907 IDirect3DDevice7
*device
;
3908 IDirectDrawSurface7
*rt
;
3909 D3DMATERIAL7 material
;
3914 unsigned int i
, j
, x
, y
;
3917 struct vec3 position
;
3922 quad
= HeapAlloc(GetProcessHeap(), 0, vertices_side
* vertices_side
* sizeof(*quad
));
3923 indices
= HeapAlloc(GetProcessHeap(), 0, indices_count
* sizeof(*indices
));
3924 for (i
= 0, y
= 0; y
< vertices_side
; ++y
)
3926 for (x
= 0; x
< vertices_side
; ++x
)
3928 quad
[i
].position
.x
= x
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
3929 quad
[i
].position
.y
= y
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
3930 quad
[i
].position
.z
= 1.0f
;
3931 quad
[i
].normal
.x
= 0.0f
;
3932 quad
[i
].normal
.y
= 0.0f
;
3933 quad
[i
++].normal
.z
= -1.0f
;
3936 for (i
= 0, y
= 0; y
< (vertices_side
- 1); ++y
)
3938 for (x
= 0; x
< (vertices_side
- 1); ++x
)
3940 indices
[i
++] = y
* vertices_side
+ x
+ 1;
3941 indices
[i
++] = y
* vertices_side
+ x
;
3942 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
3943 indices
[i
++] = y
* vertices_side
+ x
+ 1;
3944 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
3945 indices
[i
++] = (y
+ 1) * vertices_side
+ x
+ 1;
3949 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3950 0, 0, 640, 480, 0, 0, 0, 0);
3951 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3953 skip("Failed to create a 3D device, skipping test.\n");
3954 DestroyWindow(window
);
3958 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3959 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3961 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
3962 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
3963 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
3964 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
3965 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
3966 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
3967 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3968 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
3969 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
3970 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
3971 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
3972 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
3974 memset(&material
, 0, sizeof(material
));
3975 U1(U2(material
).specular
).r
= 1.0f
;
3976 U2(U2(material
).specular
).g
= 1.0f
;
3977 U3(U2(material
).specular
).b
= 1.0f
;
3978 U4(U2(material
).specular
).a
= 1.0f
;
3979 U4(material
).power
= 30.0f
;
3980 hr
= IDirect3DDevice7_SetMaterial(device
, &material
);
3981 ok(SUCCEEDED(hr
), "Failed to set material, hr %#x.\n", hr
);
3983 hr
= IDirect3DDevice7_LightEnable(device
, 0, TRUE
);
3984 ok(SUCCEEDED(hr
), "Failed to enable light 0, hr %#x.\n", hr
);
3985 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, TRUE
);
3986 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
3988 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
3990 hr
= IDirect3DDevice7_SetLight(device
, 0, tests
[i
].light
);
3991 ok(SUCCEEDED(hr
), "Failed to set light parameters, hr %#x.\n", hr
);
3993 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LOCALVIEWER
, tests
[i
].local_viewer
);
3994 ok(SUCCEEDED(hr
), "Failed to set local viewer state, hr %#x.\n", hr
);
3996 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
3997 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
3999 hr
= IDirect3DDevice7_BeginScene(device
);
4000 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4002 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, quad
,
4003 vertices_side
* vertices_side
, indices
, indices_count
, 0);
4004 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4006 hr
= IDirect3DDevice7_EndScene(device
);
4007 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4009 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
4011 color
= get_surface_color(rt
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
4012 ok(compare_color(color
, tests
[i
].expected
[j
].color
, 1),
4013 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
4014 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
4015 tests
[i
].expected
[j
].y
, color
, i
);
4019 IDirectDrawSurface7_Release(rt
);
4021 refcount
= IDirect3DDevice7_Release(device
);
4022 ok(!refcount
, "Device has %u references left.\n", refcount
);
4023 DestroyWindow(window
);
4024 HeapFree(GetProcessHeap(), 0, indices
);
4025 HeapFree(GetProcessHeap(), 0, quad
);
4028 static void test_clear_rect_count(void)
4030 IDirectDrawSurface7
*rt
;
4031 IDirect3DDevice7
*device
;
4035 D3DRECT rect
= {{0}, {0}, {640}, {480}};
4037 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4038 0, 0, 640, 480, 0, 0, 0, 0);
4039 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4041 skip("Failed to create a 3D device, skipping test.\n");
4042 DestroyWindow(window
);
4046 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
4047 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4049 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ffffff, 1.0f
, 0);
4050 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4051 hr
= IDirect3DDevice7_Clear(device
, 0, &rect
, D3DCLEAR_TARGET
, 0x00ff0000, 1.0f
, 0);
4052 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4054 color
= get_surface_color(rt
, 320, 240);
4055 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x00ff0000, 1)),
4056 "Clear with count = 0, rect != NULL has color %#08x.\n", color
);
4058 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ffffff, 1.0f
, 0);
4059 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4060 hr
= IDirect3DDevice7_Clear(device
, 1, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 1.0f
, 0);
4061 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4063 color
= get_surface_color(rt
, 320, 240);
4064 ok(compare_color(color
, 0x0000ff00, 1),
4065 "Clear with count = 1, rect = NULL has color %#08x.\n", color
);
4067 IDirectDrawSurface7_Release(rt
);
4068 IDirect3DDevice7_Release(device
);
4069 DestroyWindow(window
);
4072 static BOOL
test_mode_restored(IDirectDraw7
*ddraw
, HWND window
)
4074 DDSURFACEDESC2 ddsd1
, ddsd2
;
4077 memset(&ddsd1
, 0, sizeof(ddsd1
));
4078 ddsd1
.dwSize
= sizeof(ddsd1
);
4079 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &ddsd1
);
4080 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
4082 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4083 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4084 hr
= set_display_mode(ddraw
, 640, 480);
4085 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
4086 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4087 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4089 memset(&ddsd2
, 0, sizeof(ddsd2
));
4090 ddsd2
.dwSize
= sizeof(ddsd2
);
4091 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &ddsd2
);
4092 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
4093 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
4094 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
4096 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
4099 static void test_coop_level_versions(void)
4105 IDirectDrawSurface
*surface
;
4106 IDirectDraw7
*ddraw7
;
4109 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
4110 0, 0, 640, 480, 0, 0, 0, 0);
4112 ddraw7
= create_ddraw();
4113 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4114 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
4115 restored
= test_mode_restored(ddraw7
, window
);
4116 ok(restored
, "Display mode not restored in new ddraw object\n");
4118 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
4119 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4120 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4122 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4123 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
4124 restored
= test_mode_restored(ddraw7
, window
);
4125 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
4127 /* A successful one does */
4128 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4129 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4130 restored
= test_mode_restored(ddraw7
, window
);
4131 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
4133 IDirectDraw_Release(ddraw
);
4134 IDirectDraw7_Release(ddraw7
);
4136 ddraw7
= create_ddraw();
4137 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4138 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4139 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4141 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
4142 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4143 restored
= test_mode_restored(ddraw7
, window
);
4144 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
4146 IDirectDraw_Release(ddraw
);
4147 IDirectDraw7_Release(ddraw7
);
4149 /* A failing call does not restore the ddraw2+ behavior */
4150 ddraw7
= create_ddraw();
4151 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4152 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4153 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4155 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4156 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4157 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4158 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
4159 restored
= test_mode_restored(ddraw7
, window
);
4160 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
4162 IDirectDraw_Release(ddraw
);
4163 IDirectDraw7_Release(ddraw7
);
4165 /* Neither does a sequence of successful calls with the new interface */
4166 ddraw7
= create_ddraw();
4167 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4168 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4169 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4171 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4172 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4173 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4174 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4175 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_NORMAL
);
4176 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4178 restored
= test_mode_restored(ddraw7
, window
);
4179 ok(!restored
, "Display mode restored after ddraw1-ddraw7 SetCooperativeLevel() call sequence\n");
4180 IDirectDraw_Release(ddraw
);
4181 IDirectDraw7_Release(ddraw7
);
4183 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
4184 ddraw7
= create_ddraw();
4185 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4186 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4187 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4189 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_NORMAL
);
4190 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4192 memset(&ddsd
, 0, sizeof(ddsd
));
4193 ddsd
.dwSize
= sizeof(ddsd
);
4194 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4195 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4196 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
4197 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4198 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
4199 IDirectDrawSurface_Release(surface
);
4200 restored
= test_mode_restored(ddraw7
, window
);
4201 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
4203 IDirectDraw_Release(ddraw
);
4204 IDirectDraw7_Release(ddraw7
);
4205 DestroyWindow(window
);
4208 static void test_fog_special(void)
4212 struct vec3 position
;
4217 {{ -1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
4218 {{ 1.0f
, 1.0f
, 1.0f
}, 0xff00ff00},
4219 {{ -1.0f
, -1.0f
, 0.0f
}, 0xff00ff00},
4220 {{ 1.0f
, -1.0f
, 1.0f
}, 0xff00ff00},
4224 DWORD vertexmode
, tablemode
;
4225 D3DCOLOR color_left
, color_right
;
4229 {D3DFOG_LINEAR
, D3DFOG_NONE
, 0x00ff0000, 0x00ff0000},
4230 {D3DFOG_NONE
, D3DFOG_LINEAR
, 0x0000ff00, 0x00ff0000},
4241 IDirect3DDevice7
*device
;
4242 IDirectDrawSurface7
*rt
;
4244 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4245 0, 0, 640, 480, 0, 0, 0, 0);
4247 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4249 skip("Failed to create a 3D device, skipping test.\n");
4250 DestroyWindow(window
);
4254 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
4255 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4257 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
4258 ok(SUCCEEDED(hr
), "Failed to enable fog, hr %#x.\n", hr
);
4259 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0xffff0000);
4260 ok(SUCCEEDED(hr
), "Failed to set fog color, hr %#x.\n", hr
);
4261 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
4262 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
4263 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
4264 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
4267 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, conv
.d
);
4268 ok(SUCCEEDED(hr
), "Failed to set fog start, hr %#x.\n", hr
);
4269 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, conv
.d
);
4270 ok(SUCCEEDED(hr
), "Failed to set fog end, hr %#x.\n", hr
);
4272 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4274 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 1.0f
, 0);
4275 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4277 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, tests
[i
].vertexmode
);
4278 ok(SUCCEEDED(hr
), "Failed to set fogvertexmode, hr %#x.\n", hr
);
4279 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, tests
[i
].tablemode
);
4280 ok(SUCCEEDED(hr
), "Failed to set fogtablemode, hr %#x.\n", hr
);
4282 hr
= IDirect3DDevice7_BeginScene(device
);
4283 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4284 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad
, 4, 0);
4285 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4286 hr
= IDirect3DDevice7_EndScene(device
);
4287 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4289 color
= get_surface_color(rt
, 310, 240);
4290 ok(compare_color(color
, tests
[i
].color_left
, 1),
4291 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests
[i
].color_left
, color
, i
);
4292 color
= get_surface_color(rt
, 330, 240);
4293 ok(compare_color(color
, tests
[i
].color_right
, 1),
4294 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests
[i
].color_right
, color
, i
);
4297 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
4298 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
4300 IDirectDrawSurface7_Release(rt
);
4301 IDirect3DDevice7_Release(device
);
4302 DestroyWindow(window
);
4305 static void test_lighting_interface_versions(void)
4307 IDirect3DDevice7
*device
;
4308 IDirectDrawSurface7
*rt
;
4315 D3DMATERIAL7 material
;
4316 static D3DVERTEX quad
[] =
4318 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4319 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4320 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4321 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4324 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
4327 struct vec3 position
;
4329 DWORD diffuse
, specular
;
4333 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4334 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4335 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4336 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4339 static D3DLVERTEX lquad
[] =
4341 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4342 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4343 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4344 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4347 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
4350 struct vec3 position
;
4351 DWORD diffuse
, specular
;
4352 struct vec2 texcoord
;
4356 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4357 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4358 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4359 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4362 static D3DTLVERTEX tlquad
[] =
4364 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4365 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4366 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4367 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4374 DWORD d3drs_lighting
, d3drs_specular
;
4380 /* Lighting is enabled when D3DFVF_XYZ is used and D3DRENDERSTATE_LIGHTING is
4381 * enabled. D3DDP_DONOTLIGHT is ignored. Lighting is also enabled when normals
4384 * Note that the specular result is 0x00000000 when lighting is on even if the
4385 * input vertex has specular color because D3DRENDERSTATE_COLORVERTEX is not
4389 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x00ffffff},
4390 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
4391 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4392 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4393 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x00ffffff},
4394 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
4395 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4396 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4399 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, 0, 0x00ff0000},
4400 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, 0, 0x0000ff00},
4401 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4402 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4403 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, 0, 0x00ff8080},
4404 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, 0, 0x0000ff00},
4405 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4406 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4409 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
4410 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x0000ff00},
4411 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4412 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4413 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
4414 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x0000ff00},
4415 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4416 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4419 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, 0, 0x00ff0000},
4420 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, 0, 0x0000ff00},
4421 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4422 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4423 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, 0, 0x00ff8080},
4424 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, 0, 0x0000ff00},
4425 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4426 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4429 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
4430 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
4431 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
4432 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
4433 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
4434 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
4435 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
4436 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
4439 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4440 0, 0, 640, 480, 0, 0, 0, 0);
4442 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4444 skip("Failed to create a 3D device, skipping test.\n");
4445 DestroyWindow(window
);
4449 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
4450 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4452 memset(&material
, 0, sizeof(material
));
4453 U2(U3(material
).emissive
).g
= 1.0f
;
4454 hr
= IDirect3DDevice7_SetMaterial(device
, &material
);
4455 ok(SUCCEEDED(hr
), "Failed set material, hr %#x.\n", hr
);
4456 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
4457 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
4459 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_LIGHTING
, &rs
);
4460 ok(SUCCEEDED(hr
), "Failed to get lighting render state, hr %#x.\n", hr
);
4461 ok(rs
== TRUE
, "Initial D3DRENDERSTATE_LIGHTING is %#x, expected TRUE.\n", rs
);
4462 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
4463 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
4464 ok(rs
== FALSE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs
);
4466 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4468 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff202020, 0.0f
, 0);
4469 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
4471 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
4472 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
4473 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
4474 tests
[i
].d3drs_specular
);
4475 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
4477 hr
= IDirect3DDevice7_BeginScene(device
);
4478 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4479 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
4480 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
4481 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4482 hr
= IDirect3DDevice7_EndScene(device
);
4483 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4485 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_LIGHTING
, &rs
);
4486 ok(SUCCEEDED(hr
), "Failed to get lighting render state, hr %#x.\n", hr
);
4487 ok(rs
== tests
[i
].d3drs_lighting
, "D3DRENDERSTATE_LIGHTING is %#x, expected %#x.\n",
4488 rs
, tests
[i
].d3drs_lighting
);
4490 color
= get_surface_color(rt
, 320, 240);
4491 ok(compare_color(color
, tests
[i
].color
, 1),
4492 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
4493 color
, tests
[i
].color
, i
);
4496 IDirectDrawSurface7_Release(rt
);
4497 ref
= IDirect3DDevice7_Release(device
);
4498 ok(ref
== 0, "Device not properly released, refcount %u.\n", ref
);
4499 DestroyWindow(window
);
4505 IDirectDraw7
*ddraw
;
4508 } activateapp_testdata
;
4510 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
4512 if (message
== WM_ACTIVATEAPP
)
4514 if (activateapp_testdata
.ddraw
)
4517 activateapp_testdata
.received
= FALSE
;
4518 hr
= IDirectDraw7_SetCooperativeLevel(activateapp_testdata
.ddraw
,
4519 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
4520 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
4521 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
4523 activateapp_testdata
.received
= TRUE
;
4526 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
4529 static void test_coop_level_activateapp(void)
4531 IDirectDraw7
*ddraw
;
4535 DDSURFACEDESC2 ddsd
;
4536 IDirectDrawSurface7
*surface
;
4538 ddraw
= create_ddraw();
4539 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4541 wc
.lpfnWndProc
= activateapp_test_proc
;
4542 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
4543 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
4545 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
4546 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
4548 /* Exclusive with window already active. */
4549 SetForegroundWindow(window
);
4550 activateapp_testdata
.received
= FALSE
;
4551 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4552 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4553 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
4554 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4555 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4557 /* Exclusive with window not active. */
4558 SetForegroundWindow(GetDesktopWindow());
4559 activateapp_testdata
.received
= FALSE
;
4560 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4561 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4562 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4563 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4564 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4566 /* Normal with window not active, then exclusive with the same window. */
4567 SetForegroundWindow(GetDesktopWindow());
4568 activateapp_testdata
.received
= FALSE
;
4569 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4570 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4571 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
4572 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4573 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4574 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4575 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4576 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4578 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
4579 SetForegroundWindow(GetDesktopWindow());
4580 activateapp_testdata
.received
= FALSE
;
4581 activateapp_testdata
.ddraw
= ddraw
;
4582 activateapp_testdata
.window
= window
;
4583 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
4584 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4585 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4586 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4587 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4588 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4590 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
4591 * succeeding. Another switch to exclusive and back to normal is needed to release the
4592 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
4593 * WM_ACTIVATEAPP messages. */
4594 activateapp_testdata
.ddraw
= NULL
;
4595 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4596 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4597 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4598 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4600 /* Setting DDSCL_NORMAL with recursive invocation. */
4601 SetForegroundWindow(GetDesktopWindow());
4602 activateapp_testdata
.received
= FALSE
;
4603 activateapp_testdata
.ddraw
= ddraw
;
4604 activateapp_testdata
.window
= window
;
4605 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
4606 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4607 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4608 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4610 /* DDraw is in exlusive mode now. */
4611 memset(&ddsd
, 0, sizeof(ddsd
));
4612 ddsd
.dwSize
= sizeof(ddsd
);
4613 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4614 U5(ddsd
).dwBackBufferCount
= 1;
4615 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4616 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4617 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4618 IDirectDrawSurface7_Release(surface
);
4620 /* Recover again, just to be sure. */
4621 activateapp_testdata
.ddraw
= NULL
;
4622 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4623 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4624 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4625 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4627 DestroyWindow(window
);
4628 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
4629 IDirectDraw7_Release(ddraw
);
4632 static void test_texturemanage(void)
4634 IDirectDraw7
*ddraw
;
4636 DDSURFACEDESC2 ddsd
;
4637 IDirectDrawSurface7
*surface
;
4639 DDCAPS hal_caps
, hel_caps
;
4640 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
4643 DWORD caps_in
, caps2_in
;
4645 DWORD caps_out
, caps2_out
;
4649 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4651 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4653 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4655 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4657 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DD_OK
,
4658 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
},
4659 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DD_OK
,
4660 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
},
4661 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
4662 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_LOCALVIDMEM
, 0},
4663 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
4664 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0},
4666 {0, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4668 {0, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4670 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4672 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4674 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4676 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4678 {DDSCAPS_VIDEOMEMORY
, 0, DD_OK
,
4679 DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
, 0},
4680 {DDSCAPS_SYSTEMMEMORY
, 0, DD_OK
,
4681 DDSCAPS_SYSTEMMEMORY
, 0},
4684 ddraw
= create_ddraw();
4685 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4686 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4687 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4689 memset(&hal_caps
, 0, sizeof(hal_caps
));
4690 hal_caps
.dwSize
= sizeof(hal_caps
);
4691 memset(&hel_caps
, 0, sizeof(hel_caps
));
4692 hel_caps
.dwSize
= sizeof(hel_caps
);
4693 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, &hel_caps
);
4694 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4695 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
4697 skip("Managed textures not supported, skipping managed texture test.\n");
4698 IDirectDraw7_Release(ddraw
);
4702 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4704 memset(&ddsd
, 0, sizeof(ddsd
));
4705 ddsd
.dwSize
= sizeof(ddsd
);
4706 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4707 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps_in
;
4708 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2_in
;
4712 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4713 if (tests
[i
].hr
== DD_OK
&& is_ddraw64
&& (tests
[i
].caps_in
& DDSCAPS_TEXTURE
))
4714 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4716 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, tests
[i
].hr
);
4720 memset(&ddsd
, 0, sizeof(ddsd
));
4721 ddsd
.dwSize
= sizeof(ddsd
);
4722 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
4723 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4725 ok(ddsd
.ddsCaps
.dwCaps
== tests
[i
].caps_out
,
4726 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4727 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps_out
, ddsd
.ddsCaps
.dwCaps
, i
);
4728 ok(ddsd
.ddsCaps
.dwCaps2
== tests
[i
].caps2_out
,
4729 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4730 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps2_out
, ddsd
.ddsCaps
.dwCaps2
, i
);
4732 IDirectDrawSurface7_Release(surface
);
4735 IDirectDraw7_Release(ddraw
);
4738 #define SUPPORT_DXT1 0x01
4739 #define SUPPORT_DXT2 0x02
4740 #define SUPPORT_DXT3 0x04
4741 #define SUPPORT_DXT4 0x08
4742 #define SUPPORT_DXT5 0x10
4743 #define SUPPORT_YUY2 0x20
4744 #define SUPPORT_UYVY 0x40
4746 static HRESULT WINAPI
test_block_formats_creation_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
4748 DWORD
*supported_fmts
= ctx
;
4750 if (!(fmt
->dwFlags
& DDPF_FOURCC
))
4751 return DDENUMRET_OK
;
4753 switch (fmt
->dwFourCC
)
4755 case MAKEFOURCC('D','X','T','1'):
4756 *supported_fmts
|= SUPPORT_DXT1
;
4758 case MAKEFOURCC('D','X','T','2'):
4759 *supported_fmts
|= SUPPORT_DXT2
;
4761 case MAKEFOURCC('D','X','T','3'):
4762 *supported_fmts
|= SUPPORT_DXT3
;
4764 case MAKEFOURCC('D','X','T','4'):
4765 *supported_fmts
|= SUPPORT_DXT4
;
4767 case MAKEFOURCC('D','X','T','5'):
4768 *supported_fmts
|= SUPPORT_DXT5
;
4770 case MAKEFOURCC('Y','U','Y','2'):
4771 *supported_fmts
|= SUPPORT_YUY2
;
4773 case MAKEFOURCC('U','Y','V','Y'):
4774 *supported_fmts
|= SUPPORT_UYVY
;
4780 return DDENUMRET_OK
;
4783 static void test_block_formats_creation(void)
4785 HRESULT hr
, expect_hr
;
4786 unsigned int i
, j
, w
, h
;
4788 IDirectDraw7
*ddraw
;
4790 IDirect3DDevice7
*device
;
4791 IDirectDrawSurface7
*surface
;
4792 DWORD supported_fmts
= 0, supported_overlay_fmts
= 0;
4793 DWORD num_fourcc_codes
= 0, *fourcc_codes
;
4794 DDSURFACEDESC2 ddsd
;
4803 unsigned int block_width
;
4804 unsigned int block_height
;
4805 unsigned int block_size
;
4806 BOOL create_size_checked
, overlay
;
4810 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1
, 4, 4, 8, TRUE
, FALSE
},
4811 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2
, 4, 4, 16, TRUE
, FALSE
},
4812 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3
, 4, 4, 16, TRUE
, FALSE
},
4813 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4
, 4, 4, 16, TRUE
, FALSE
},
4814 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5
, 4, 4, 16, TRUE
, FALSE
},
4815 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2
, 2, 1, 4, FALSE
, TRUE
},
4816 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY
, 2, 1, 4, FALSE
, TRUE
},
4826 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4827 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4829 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4830 * Other hw / drivers successfully create those surfaces. Ignore them, this
4831 * suggests that no game uses this, otherwise Nvidia would support it. */
4833 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0,
4834 "videomemory texture", FALSE
4837 DDSCAPS_VIDEOMEMORY
| DDSCAPS_OVERLAY
, 0,
4838 "videomemory overlay", TRUE
4841 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0,
4842 "systemmemory texture", FALSE
4845 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
4846 "managed texture", FALSE
4858 enum size_type size_type
;
4864 {DDSD_LINEARSIZE
, SIZE_TYPE_ZERO
, 0, DD_OK
},
4865 {DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
4866 {DDSD_PITCH
, SIZE_TYPE_ZERO
, 0, DD_OK
},
4867 {DDSD_PITCH
, SIZE_TYPE_PITCH
, 0, DD_OK
},
4868 {DDSD_LPSURFACE
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
4869 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
4870 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_PITCH
, 0, DDERR_INVALIDPARAMS
},
4871 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
4872 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 1, DD_OK
},
4873 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, -1, DDERR_INVALIDPARAMS
},
4874 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
4875 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_PITCH
, 0, DDERR_INVALIDPARAMS
},
4876 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_SIZE
, 0, DDERR_INVALIDPARAMS
},
4877 {DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DDERR_INVALIDPARAMS
},
4880 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4881 0, 0, 640, 480, 0, 0, 0, 0);
4883 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4885 skip("Failed to create a 3D device, skipping test.\n");
4886 DestroyWindow(window
);
4890 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
4891 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
4892 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
4893 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
4894 IDirect3D7_Release(d3d
);
4896 hr
= IDirect3DDevice7_EnumTextureFormats(device
, test_block_formats_creation_cb
,
4898 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4900 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
4901 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
4902 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
4903 num_fourcc_codes
* sizeof(*fourcc_codes
));
4906 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
4907 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
4908 for (i
= 0; i
< num_fourcc_codes
; i
++)
4910 for (j
= 0; j
< sizeof(formats
) / sizeof(*formats
); j
++)
4912 if (fourcc_codes
[i
] == formats
[j
].fourcc
)
4913 supported_overlay_fmts
|= formats
[j
].support_flag
;
4916 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
4918 memset(&hal_caps
, 0, sizeof(hal_caps
));
4919 hal_caps
.dwSize
= sizeof(hal_caps
);
4920 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
4921 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4923 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 2 * 2 * 16 + 1);
4925 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
4927 for (j
= 0; j
< sizeof(types
) / sizeof(*types
); j
++)
4931 if (formats
[i
].overlay
!= types
[j
].overlay
4932 || (types
[j
].overlay
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
)))
4935 if (formats
[i
].overlay
)
4936 support
= supported_overlay_fmts
& formats
[i
].support_flag
;
4938 support
= supported_fmts
& formats
[i
].support_flag
;
4940 for (w
= 1; w
<= 8; w
++)
4942 for (h
= 1; h
<= 8; h
++)
4944 BOOL block_aligned
= TRUE
;
4947 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
4948 block_aligned
= FALSE
;
4950 memset(&ddsd
, 0, sizeof(ddsd
));
4951 ddsd
.dwSize
= sizeof(ddsd
);
4952 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4953 ddsd
.ddsCaps
.dwCaps
= types
[j
].caps
;
4954 ddsd
.ddsCaps
.dwCaps2
= types
[j
].caps2
;
4955 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
4956 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
4957 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
4961 /* TODO: Handle power of two limitations. I cannot test the pow2
4962 * behavior on windows because I have no hardware that doesn't at
4963 * least support np2_conditional. There's probably no HW that
4964 * supports DXTN textures but no conditional np2 textures. */
4965 if (!support
&& !(types
[j
].caps
& DDSCAPS_SYSTEMMEMORY
))
4966 expect_hr
= DDERR_INVALIDPARAMS
;
4967 else if (formats
[i
].create_size_checked
&& !block_aligned
)
4969 expect_hr
= DDERR_INVALIDPARAMS
;
4970 if (!(types
[j
].caps
& DDSCAPS_TEXTURE
))
4976 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4978 todo_wine
ok(hr
== expect_hr
,
4979 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4980 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
4983 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4984 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
4987 IDirectDrawSurface7_Release(surface
);
4992 if (formats
[i
].overlay
)
4995 for (j
= 0; j
< sizeof(user_mem_tests
) / sizeof(*user_mem_tests
); ++j
)
4997 memset(&ddsd
, 0, sizeof(ddsd
));
4998 ddsd
.dwSize
= sizeof(ddsd
);
4999 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| user_mem_tests
[j
].flags
;
5000 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
;
5002 switch (user_mem_tests
[j
].size_type
)
5004 case SIZE_TYPE_ZERO
:
5005 U1(ddsd
).dwLinearSize
= 0;
5008 case SIZE_TYPE_PITCH
:
5009 U1(ddsd
).dwLinearSize
= 2 * formats
[i
].block_size
;
5012 case SIZE_TYPE_SIZE
:
5013 U1(ddsd
).dwLinearSize
= 2 * 2 * formats
[i
].block_size
;
5016 U1(ddsd
).dwLinearSize
+= user_mem_tests
[j
].rel_size
;
5018 ddsd
.lpSurface
= mem
;
5019 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5020 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
5021 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
5025 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5026 ok(hr
== user_mem_tests
[j
].hr
, "Test %u: Got unexpected hr %#x, format %s.\n", j
, hr
, formats
[i
].name
);
5031 memset(&ddsd
, 0, sizeof(ddsd
));
5032 ddsd
.dwSize
= sizeof(ddsd
);
5033 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
5034 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", j
, hr
);
5035 ok(ddsd
.dwFlags
== (DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_LINEARSIZE
),
5036 "Test %u: Got unexpected flags %#x.\n", j
, ddsd
.dwFlags
);
5037 if (user_mem_tests
[j
].flags
& DDSD_LPSURFACE
)
5038 ok(U1(ddsd
).dwLinearSize
== ~0u, "Test %u: Got unexpected linear size %#x.\n",
5039 j
, U1(ddsd
).dwLinearSize
);
5041 ok(U1(ddsd
).dwLinearSize
== 2 * 2 * formats
[i
].block_size
,
5042 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
5043 j
, U1(ddsd
).dwLinearSize
, 2 * 2 * formats
[i
].block_size
);
5044 IDirectDrawSurface7_Release(surface
);
5048 HeapFree(GetProcessHeap(), 0, mem
);
5050 IDirectDraw7_Release(ddraw
);
5051 IDirect3DDevice7_Release(device
);
5052 DestroyWindow(window
);
5055 struct format_support_check
5057 const DDPIXELFORMAT
*format
;
5061 static HRESULT WINAPI
test_unsupported_formats_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
5063 struct format_support_check
*format
= ctx
;
5065 if (!memcmp(format
->format
, fmt
, sizeof(*fmt
)))
5067 format
->supported
= TRUE
;
5068 return DDENUMRET_CANCEL
;
5071 return DDENUMRET_OK
;
5074 static void test_unsupported_formats(void)
5077 BOOL expect_success
;
5079 IDirectDraw7
*ddraw
;
5081 IDirect3DDevice7
*device
;
5082 IDirectDrawSurface7
*surface
;
5083 DDSURFACEDESC2 ddsd
;
5085 DWORD expected_caps
;
5096 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
5097 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
5103 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
5104 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
5108 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
5110 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5111 0, 0, 640, 480, 0, 0, 0, 0);
5113 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5115 skip("Failed to create a 3D device, skipping test.\n");
5116 DestroyWindow(window
);
5120 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
5121 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5122 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
5123 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5124 IDirect3D7_Release(d3d
);
5126 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
5128 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
5129 hr
= IDirect3DDevice7_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
5130 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
5132 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
5134 memset(&ddsd
, 0, sizeof(ddsd
));
5135 ddsd
.dwSize
= sizeof(ddsd
);
5136 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5137 U4(ddsd
).ddpfPixelFormat
= formats
[i
].fmt
;
5140 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
5142 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
5143 expect_success
= FALSE
;
5145 expect_success
= TRUE
;
5147 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5148 ok(SUCCEEDED(hr
) == expect_success
,
5149 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
5150 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
5154 memset(&ddsd
, 0, sizeof(ddsd
));
5155 ddsd
.dwSize
= sizeof(ddsd
);
5156 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
5157 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5159 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
5160 expected_caps
= DDSCAPS_VIDEOMEMORY
;
5161 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
5162 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
5163 else if (check
.supported
)
5164 expected_caps
= DDSCAPS_VIDEOMEMORY
;
5166 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
5168 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
5169 "Expected capability %#x, format %s, input cap %#x.\n",
5170 expected_caps
, formats
[i
].name
, caps
[j
]);
5172 IDirectDrawSurface7_Release(surface
);
5176 IDirectDraw7_Release(ddraw
);
5177 IDirect3DDevice7_Release(device
);
5178 DestroyWindow(window
);
5181 static void test_rt_caps(void)
5183 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
5184 PALETTEENTRY palette_entries
[256];
5185 IDirectDrawPalette
*palette
;
5186 IDirectDraw7
*ddraw
;
5187 BOOL hal_ok
= FALSE
;
5188 DDPIXELFORMAT z_fmt
;
5195 static const DDPIXELFORMAT p8_fmt
=
5197 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
5198 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
5203 const DDPIXELFORMAT
*pf
;
5206 HRESULT create_device_hr
;
5207 HRESULT set_rt_hr
, alternative_set_rt_hr
;
5213 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
5214 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5221 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5222 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5229 DDSCAPS_OFFSCREENPLAIN
,
5230 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5237 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5238 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5239 D3DERR_SURFACENOTINVIDMEM
,
5240 DDERR_INVALIDPARAMS
,
5245 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5246 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5253 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
5254 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5262 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5270 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5277 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5278 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5279 D3DERR_SURFACENOTINVIDMEM
,
5280 DDERR_INVALIDPARAMS
,
5285 DDSCAPS_SYSTEMMEMORY
,
5286 DDSCAPS_SYSTEMMEMORY
,
5294 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5301 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5303 DDERR_NOPALETTEATTACHED
,
5309 DDSCAPS_OFFSCREENPLAIN
,
5310 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5317 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5318 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5319 DDERR_NOPALETTEATTACHED
,
5325 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5326 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5333 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
5334 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5336 DDERR_INVALIDPIXELFORMAT
,
5337 DDERR_INVALIDPIXELFORMAT
,
5341 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5342 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5344 DDERR_INVALIDPIXELFORMAT
,
5345 DDERR_INVALIDPIXELFORMAT
,
5350 DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5357 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5358 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5360 DDERR_INVALIDPARAMS
,
5361 DDERR_INVALIDPIXELFORMAT
,
5365 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
5366 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
5373 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5374 0, 0, 640, 480, 0, 0, 0, 0);
5375 ddraw
= create_ddraw();
5376 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5377 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5378 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5380 if (FAILED(IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
5382 skip("D3D interface is not available, skipping test.\n");
5386 hr
= IDirect3D7_EnumDevices(d3d
, enum_devtype_cb
, &hal_ok
);
5387 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
5389 devtype
= &IID_IDirect3DTnLHalDevice
;
5391 memset(&z_fmt
, 0, sizeof(z_fmt
));
5392 hr
= IDirect3D7_EnumZBufferFormats(d3d
, devtype
, enum_z_fmt
, &z_fmt
);
5393 if (FAILED(hr
) || !z_fmt
.dwSize
)
5395 skip("No depth buffer formats available, skipping test.\n");
5396 IDirect3D7_Release(d3d
);
5400 memset(palette_entries
, 0, sizeof(palette_entries
));
5401 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
5402 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5404 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5406 IDirectDrawSurface7
*surface
, *rt
, *expected_rt
, *tmp
;
5407 DDSURFACEDESC2 surface_desc
;
5408 IDirect3DDevice7
*device
;
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
= test_data
[i
].caps_in
;
5414 if (test_data
[i
].pf
)
5416 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5417 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
5419 surface_desc
.dwWidth
= 640;
5420 surface_desc
.dwHeight
= 480;
5421 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5422 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5423 i
, test_data
[i
].caps_in
, hr
);
5425 memset(&surface_desc
, 0, sizeof(surface_desc
));
5426 surface_desc
.dwSize
= sizeof(surface_desc
);
5427 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
5428 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5429 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
5430 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5431 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
5433 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5434 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
5435 i
, hr
, test_data
[i
].create_device_hr
);
5438 if (hr
== DDERR_NOPALETTEATTACHED
)
5440 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
5441 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
5442 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5443 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5444 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5446 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5448 IDirectDrawSurface7_Release(surface
);
5450 memset(&surface_desc
, 0, sizeof(surface_desc
));
5451 surface_desc
.dwSize
= sizeof(surface_desc
);
5452 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5453 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5454 surface_desc
.dwWidth
= 640;
5455 surface_desc
.dwHeight
= 480;
5456 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5457 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
5459 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5460 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
5463 memset(&surface_desc
, 0, sizeof(surface_desc
));
5464 surface_desc
.dwSize
= sizeof(surface_desc
);
5465 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5466 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5467 if (test_data
[i
].pf
)
5469 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5470 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
5472 surface_desc
.dwWidth
= 640;
5473 surface_desc
.dwHeight
= 480;
5474 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
5475 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5476 i
, test_data
[i
].caps_in
, hr
);
5478 hr
= IDirect3DDevice7_SetRenderTarget(device
, rt
, 0);
5479 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
5480 "Test %u: Got unexpected hr %#x, expected %#x.\n",
5481 i
, hr
, test_data
[i
].set_rt_hr
);
5482 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
5485 expected_rt
= surface
;
5487 hr
= IDirect3DDevice7_GetRenderTarget(device
, &tmp
);
5488 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
5489 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
5491 IDirectDrawSurface7_Release(tmp
);
5492 IDirectDrawSurface7_Release(rt
);
5493 refcount
= IDirect3DDevice7_Release(device
);
5494 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
5495 refcount
= IDirectDrawSurface7_Release(surface
);
5496 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
5499 IDirectDrawPalette_Release(palette
);
5500 IDirect3D7_Release(d3d
);
5503 refcount
= IDirectDraw7_Release(ddraw
);
5504 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5505 DestroyWindow(window
);
5508 static void test_primary_caps(void)
5510 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
5511 IDirectDrawSurface7
*surface
;
5512 DDSURFACEDESC2 surface_desc
;
5513 IDirectDraw7
*ddraw
;
5523 DWORD back_buffer_count
;
5531 DDSCAPS_PRIMARYSURFACE
,
5534 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
5538 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
5545 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
5552 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
5559 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
5566 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
5573 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5580 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5587 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5589 DDERR_NOEXCLUSIVEMODE
,
5593 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5594 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5600 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5601 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5604 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
5607 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5608 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
5614 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5615 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
5622 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5623 0, 0, 640, 480, 0, 0, 0, 0);
5624 ddraw
= create_ddraw();
5625 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5627 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5629 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
5630 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5632 memset(&surface_desc
, 0, sizeof(surface_desc
));
5633 surface_desc
.dwSize
= sizeof(surface_desc
);
5634 surface_desc
.dwFlags
= DDSD_CAPS
;
5635 if (test_data
[i
].back_buffer_count
!= ~0u)
5636 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
5637 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5638 U5(surface_desc
).dwBackBufferCount
= test_data
[i
].back_buffer_count
;
5639 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5640 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
5644 memset(&surface_desc
, 0, sizeof(surface_desc
));
5645 surface_desc
.dwSize
= sizeof(surface_desc
);
5646 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
5647 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5648 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
5649 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5650 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
5652 IDirectDrawSurface7_Release(surface
);
5655 refcount
= IDirectDraw7_Release(ddraw
);
5656 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5657 DestroyWindow(window
);
5660 static void test_surface_lock(void)
5662 IDirectDraw7
*ddraw
;
5663 IDirect3D7
*d3d
= NULL
;
5664 IDirectDrawSurface7
*surface
;
5665 IDirect3DDevice7
*device
;
5669 DDSURFACEDESC2 ddsd
;
5671 DDPIXELFORMAT z_fmt
;
5672 BOOL hal_ok
= FALSE
;
5673 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
5674 D3DDEVICEDESC7 device_desc
;
5675 BOOL cubemap_supported
;
5685 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
5687 "videomemory offscreenplain"
5690 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5692 "systemmemory offscreenplain"
5695 DDSCAPS_PRIMARYSURFACE
,
5700 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
5702 "videomemory texture"
5705 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
5707 "opaque videomemory texture"
5710 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
5712 "systemmemory texture"
5716 DDSCAPS2_TEXTUREMANAGE
,
5721 DDSCAPS2_D3DTEXTUREMANAGE
,
5726 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
5727 "opaque managed texture"
5731 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
5732 "opaque managed texture"
5735 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5745 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_VIDEOMEMORY
,
5746 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5750 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_VIDEOMEMORY
,
5751 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
5752 "opaque videomemory cube"
5755 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_SYSTEMMEMORY
,
5756 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5760 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5761 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5765 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5766 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5770 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5771 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
5772 "opaque managed cube"
5775 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5776 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
5777 "opaque managed cube"
5781 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5782 0, 0, 640, 480, 0, 0, 0, 0);
5783 ddraw
= create_ddraw();
5784 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5785 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5786 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5788 if (FAILED(IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
5790 skip("D3D interface is not available, skipping test.\n");
5794 hr
= IDirect3D7_EnumDevices(d3d
, enum_devtype_cb
, &hal_ok
);
5795 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
5797 devtype
= &IID_IDirect3DTnLHalDevice
;
5799 memset(&z_fmt
, 0, sizeof(z_fmt
));
5800 hr
= IDirect3D7_EnumZBufferFormats(d3d
, devtype
, enum_z_fmt
, &z_fmt
);
5801 if (FAILED(hr
) || !z_fmt
.dwSize
)
5803 skip("No depth buffer formats available, skipping test.\n");
5807 memset(&ddsd
, 0, sizeof(ddsd
));
5808 ddsd
.dwSize
= sizeof(ddsd
);
5809 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5812 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5813 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5814 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5816 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5817 ok(SUCCEEDED(hr
), "Failed to create device, hr %#x.\n", hr
);
5818 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
5819 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
5820 cubemap_supported
= !!(device_desc
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
);
5821 IDirect3DDevice7_Release(device
);
5823 IDirectDrawSurface7_Release(surface
);
5825 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5827 if (!cubemap_supported
&& tests
[i
].caps2
& DDSCAPS2_CUBEMAP
)
5830 memset(&ddsd
, 0, sizeof(ddsd
));
5831 ddsd
.dwSize
= sizeof(ddsd
);
5832 ddsd
.dwFlags
= DDSD_CAPS
;
5833 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5835 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5839 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
5841 ddsd
.dwFlags
|= DDSD_PIXELFORMAT
;
5842 U4(ddsd
).ddpfPixelFormat
= z_fmt
;
5844 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
5845 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
5847 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5848 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5850 memset(&ddsd
, 0, sizeof(ddsd
));
5851 ddsd
.dwSize
= sizeof(ddsd
);
5852 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
5853 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5856 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5857 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5860 IDirectDrawSurface7_Release(surface
);
5865 IDirect3D7_Release(d3d
);
5866 refcount
= IDirectDraw7_Release(ddraw
);
5867 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5868 DestroyWindow(window
);
5871 static void test_surface_discard(void)
5873 IDirect3DDevice7
*device
;
5875 IDirectDraw7
*ddraw
;
5878 DDSURFACEDESC2 ddsd
;
5879 IDirectDrawSurface7
*surface
, *target
;
5888 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
5889 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
5890 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
5891 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
5892 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
},
5893 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
5894 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
},
5895 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
5899 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5900 0, 0, 640, 480, 0, 0, 0, 0);
5902 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5904 skip("Failed to create a 3D device, skipping test.\n");
5905 DestroyWindow(window
);
5908 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
5909 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5910 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
5911 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5912 hr
= IDirect3DDevice7_GetRenderTarget(device
, &target
);
5913 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
5915 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5919 memset(&ddsd
, 0, sizeof(ddsd
));
5920 ddsd
.dwSize
= sizeof(ddsd
);
5921 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5922 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
5923 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
5926 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5927 ok(SUCCEEDED(hr
), "Failed to create offscreen surface, hr %#x, case %u.\n", hr
, i
);
5929 memset(&ddsd
, 0, sizeof(ddsd
));
5930 ddsd
.dwSize
= sizeof(ddsd
);
5931 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
5932 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5933 addr
= ddsd
.lpSurface
;
5934 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5935 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5937 memset(&ddsd
, 0, sizeof(ddsd
));
5938 ddsd
.dwSize
= sizeof(ddsd
);
5939 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
5940 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5941 discarded
= ddsd
.lpSurface
!= addr
;
5942 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5943 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5945 hr
= IDirectDrawSurface7_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
5946 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
5948 memset(&ddsd
, 0, sizeof(ddsd
));
5949 ddsd
.dwSize
= sizeof(ddsd
);
5950 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
5951 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5952 discarded
|= ddsd
.lpSurface
!= addr
;
5953 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5954 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5956 IDirectDrawSurface7_Release(surface
);
5958 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
5959 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
5960 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
5963 IDirectDrawSurface7_Release(target
);
5964 IDirectDraw7_Release(ddraw
);
5965 IDirect3D7_Release(d3d
);
5966 IDirect3DDevice7_Release(device
);
5967 DestroyWindow(window
);
5970 static void test_flip(void)
5972 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
5973 IDirectDrawSurface7
*primary
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
5974 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
5975 DDSURFACEDESC2 surface_desc
;
5976 BOOL sysmem_primary
;
5977 IDirectDraw7
*ddraw
;
5984 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5985 0, 0, 640, 480, 0, 0, 0, 0);
5986 ddraw
= create_ddraw();
5987 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5989 hr
= set_display_mode(ddraw
, 640, 480);
5990 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
5991 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5992 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5994 memset(&surface_desc
, 0, sizeof(surface_desc
));
5995 surface_desc
.dwSize
= sizeof(surface_desc
);
5996 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
5997 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
5998 U5(surface_desc
).dwBackBufferCount
= 3;
5999 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6000 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6002 memset(&surface_desc
, 0, sizeof(surface_desc
));
6003 surface_desc
.dwSize
= sizeof(surface_desc
);
6004 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &surface_desc
);
6005 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6006 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
)
6007 == (DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
6008 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6009 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
6011 hr
= IDirectDrawSurface7_GetAttachedSurface(primary
, &caps
, &backbuffer1
);
6012 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6013 memset(&surface_desc
, 0, sizeof(surface_desc
));
6014 surface_desc
.dwSize
= sizeof(surface_desc
);
6015 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer1
, &surface_desc
);
6016 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6017 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
6018 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
| DDSCAPS_BACKBUFFER
),
6019 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6021 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
6022 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6023 memset(&surface_desc
, 0, sizeof(surface_desc
));
6024 surface_desc
.dwSize
= sizeof(surface_desc
);
6025 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer2
, &surface_desc
);
6026 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6027 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
6028 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
6029 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6031 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
6032 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6033 memset(&surface_desc
, 0, sizeof(surface_desc
));
6034 surface_desc
.dwSize
= sizeof(surface_desc
);
6035 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer3
, &surface_desc
);
6036 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6037 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
6038 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
6039 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6041 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
6042 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6043 ok(surface
== primary
, "Got unexpected surface %p, expected %p.\n", surface
, primary
);
6044 IDirectDrawSurface7_Release(surface
);
6046 memset(&surface_desc
, 0, sizeof(surface_desc
));
6047 surface_desc
.dwSize
= sizeof(surface_desc
);
6048 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6049 surface_desc
.ddsCaps
.dwCaps
= 0;
6050 surface_desc
.dwWidth
= 640;
6051 surface_desc
.dwHeight
= 480;
6052 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6053 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6054 hr
= IDirectDrawSurface7_Flip(primary
, surface
, DDFLIP_WAIT
);
6055 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6056 IDirectDrawSurface7_Release(surface
);
6058 hr
= IDirectDrawSurface7_Flip(primary
, primary
, DDFLIP_WAIT
);
6059 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6060 hr
= IDirectDrawSurface7_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
6061 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6062 hr
= IDirectDrawSurface7_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
6063 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6064 hr
= IDirectDrawSurface7_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
6065 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6067 memset(&fx
, 0, sizeof(fx
));
6068 fx
.dwSize
= sizeof(fx
);
6069 U5(fx
).dwFillColor
= 0xffff0000;
6070 hr
= IDirectDrawSurface7_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6071 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6072 U5(fx
).dwFillColor
= 0xff00ff00;
6073 hr
= IDirectDrawSurface7_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6074 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6075 U5(fx
).dwFillColor
= 0xff0000ff;
6076 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6077 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6079 hr
= IDirectDrawSurface7_Flip(primary
, NULL
, DDFLIP_WAIT
);
6080 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6081 color
= get_surface_color(backbuffer1
, 320, 240);
6082 /* The testbot seems to just copy the contents of one surface to all the
6083 * others, instead of properly flipping. */
6084 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6085 "Got unexpected color 0x%08x.\n", color
);
6086 color
= get_surface_color(backbuffer2
, 320, 240);
6087 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
6088 U5(fx
).dwFillColor
= 0xffff0000;
6089 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6090 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6092 hr
= IDirectDrawSurface7_Flip(primary
, NULL
, DDFLIP_WAIT
);
6093 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6094 color
= get_surface_color(backbuffer1
, 320, 240);
6095 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6096 "Got unexpected color 0x%08x.\n", color
);
6097 color
= get_surface_color(backbuffer2
, 320, 240);
6098 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6099 U5(fx
).dwFillColor
= 0xff00ff00;
6100 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6101 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6103 hr
= IDirectDrawSurface7_Flip(primary
, NULL
, DDFLIP_WAIT
);
6104 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6105 color
= get_surface_color(backbuffer1
, 320, 240);
6106 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6107 "Got unexpected color 0x%08x.\n", color
);
6108 color
= get_surface_color(backbuffer2
, 320, 240);
6109 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
6110 U5(fx
).dwFillColor
= 0xff0000ff;
6111 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6112 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6114 hr
= IDirectDrawSurface7_Flip(primary
, backbuffer1
, DDFLIP_WAIT
);
6115 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6116 color
= get_surface_color(backbuffer2
, 320, 240);
6117 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6118 "Got unexpected color 0x%08x.\n", color
);
6119 color
= get_surface_color(backbuffer3
, 320, 240);
6120 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
6121 U5(fx
).dwFillColor
= 0xffff0000;
6122 hr
= IDirectDrawSurface7_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6123 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6125 hr
= IDirectDrawSurface7_Flip(primary
, backbuffer2
, DDFLIP_WAIT
);
6126 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6127 color
= get_surface_color(backbuffer1
, 320, 240);
6128 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6129 color
= get_surface_color(backbuffer3
, 320, 240);
6130 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6131 "Got unexpected color 0x%08x.\n", color
);
6132 U5(fx
).dwFillColor
= 0xff00ff00;
6133 hr
= IDirectDrawSurface7_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6134 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6136 hr
= IDirectDrawSurface7_Flip(primary
, backbuffer3
, DDFLIP_WAIT
);
6137 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6138 color
= get_surface_color(backbuffer1
, 320, 240);
6139 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6140 "Got unexpected color 0x%08x.\n", color
);
6141 color
= get_surface_color(backbuffer2
, 320, 240);
6142 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
6144 IDirectDrawSurface7_Release(backbuffer3
);
6145 IDirectDrawSurface7_Release(backbuffer2
);
6146 IDirectDrawSurface7_Release(backbuffer1
);
6147 IDirectDrawSurface7_Release(primary
);
6148 refcount
= IDirectDraw7_Release(ddraw
);
6149 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
6150 DestroyWindow(window
);
6153 static void reset_ddsd(DDSURFACEDESC2
*ddsd
)
6155 memset(ddsd
, 0, sizeof(*ddsd
));
6156 ddsd
->dwSize
= sizeof(*ddsd
);
6159 static void test_set_surface_desc(void)
6161 IDirectDraw7
*ddraw
;
6164 DDSURFACEDESC2 ddsd
;
6165 IDirectDrawSurface7
*surface
;
6175 invalid_caps_tests
[] =
6177 {DDSCAPS_VIDEOMEMORY
, 0, FALSE
, "videomemory plain"},
6178 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, TRUE
, "systemmemory texture"},
6179 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
, "managed texture"},
6180 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
, "managed texture"},
6181 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
, "systemmemory primary"},
6184 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6185 0, 0, 640, 480, 0, 0, 0, 0);
6186 ddraw
= create_ddraw();
6187 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6188 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6189 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6192 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6195 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6196 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6197 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6198 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6199 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6200 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6201 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6203 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6204 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6207 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6208 ddsd
.lpSurface
= data
;
6209 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6210 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6212 /* Redundantly setting the same lpSurface is not an error. */
6213 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6214 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6216 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6217 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6218 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6219 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
6221 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
6222 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6223 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6224 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
6225 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
6226 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6229 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6230 ddsd
.lpSurface
= data
;
6231 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 1);
6232 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
6234 ddsd
.lpSurface
= NULL
;
6235 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6236 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
6238 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, NULL
, 0);
6239 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
6241 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6242 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6243 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6244 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6245 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6247 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
6248 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6249 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
6251 ddsd
.dwFlags
= DDSD_CAPS
;
6252 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6253 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6255 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
6256 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
6257 ddsd
.lpSurface
= data
;
6258 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6259 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6260 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6261 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6262 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6263 ddsd
.ddsCaps
.dwCaps
= 0;
6264 ddsd
.ddsCaps
.dwCaps2
= 0xdeadbeef;
6265 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6266 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6268 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6269 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6270 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6271 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6272 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6274 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
6276 ddsd
.dwFlags
= DDSD_HEIGHT
;
6278 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6279 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
6281 ddsd
.lpSurface
= data
;
6282 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
6283 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6284 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6287 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6288 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
6291 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6292 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
6293 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6294 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6296 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
6298 ddsd
.dwFlags
= DDSD_PITCH
;
6299 U1(ddsd
).lPitch
= 8 * 4;
6300 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6301 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
6303 ddsd
.dwFlags
= DDSD_WIDTH
;
6305 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6306 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
6308 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
6309 ddsd
.lpSurface
= data
;
6310 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6311 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
6313 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
6314 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6315 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
6317 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6318 U1(ddsd
).lPitch
= 16 * 4;
6320 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6321 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6324 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6325 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6326 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6327 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6328 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
6330 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
6332 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
6333 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6334 U1(ddsd
).lPitch
= 4 * 4;
6335 ddsd
.lpSurface
= data
;
6336 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6337 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6339 U1(ddsd
).lPitch
= 4;
6340 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6341 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6343 U1(ddsd
).lPitch
= 16 * 4 + 1;
6344 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6345 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6347 U1(ddsd
).lPitch
= 16 * 4 + 3;
6348 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6349 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6351 U1(ddsd
).lPitch
= -4;
6352 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6353 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
6355 U1(ddsd
).lPitch
= 16 * 4;
6356 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6357 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6360 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6361 U1(ddsd
).lPitch
= 0;
6363 ddsd
.lpSurface
= data
;
6364 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6365 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
6367 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6368 U1(ddsd
).lPitch
= 16 * 4;
6370 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6371 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
6373 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
6374 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
6375 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6376 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6377 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6378 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6379 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6380 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6381 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6382 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
6384 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
6385 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6386 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6388 /* Can't set color keys. */
6390 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
6391 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
6392 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
6393 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6394 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6396 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
6397 ddsd
.lpSurface
= data
;
6398 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6399 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6401 IDirectDrawSurface7_Release(surface
);
6403 /* SetSurfaceDesc needs systemmemory surfaces.
6405 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
6406 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
6409 ddsd
.dwFlags
= DDSD_CAPS
;
6410 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
6411 ddsd
.ddsCaps
.dwCaps2
= invalid_caps_tests
[i
].caps2
;
6412 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
6414 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6417 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6418 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6419 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6420 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6421 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6422 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6425 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6426 if (is_ddraw64
&& (invalid_caps_tests
[i
].caps
& DDSCAPS_TEXTURE
))
6427 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
6429 ok(hr
== DD_OK
|| hr
== DDERR_NODIRECTDRAWHW
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
6434 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6435 ddsd
.lpSurface
= data
;
6436 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6437 if (invalid_caps_tests
[i
].supported
)
6439 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6443 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6444 invalid_caps_tests
[i
].name
, hr
);
6446 /* Check priority of error conditions. */
6447 ddsd
.dwFlags
= DDSD_WIDTH
;
6448 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6449 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6450 invalid_caps_tests
[i
].name
, hr
);
6453 IDirectDrawSurface7_Release(surface
);
6456 ref
= IDirectDraw7_Release(ddraw
);
6457 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6458 DestroyWindow(window
);
6461 static void test_user_memory_getdc(void)
6463 IDirectDraw7
*ddraw
;
6466 DDSURFACEDESC2 ddsd
;
6467 IDirectDrawSurface7
*surface
;
6473 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6474 0, 0, 640, 480, 0, 0, 0, 0);
6475 ddraw
= create_ddraw();
6476 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6477 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6478 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6481 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6484 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6485 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6486 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6487 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6488 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6489 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6490 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6491 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6492 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6494 memset(data
, 0xaa, sizeof(data
));
6496 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6497 ddsd
.lpSurface
= data
;
6498 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6499 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6501 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
6502 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6503 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
6504 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
6505 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
6506 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6508 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
6509 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
6511 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
6512 ddsd
.lpSurface
= data
;
6515 U1(ddsd
).lPitch
= sizeof(*data
);
6516 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6517 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6519 memset(data
, 0xaa, sizeof(data
));
6520 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
6521 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6522 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
6523 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
6524 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
6525 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6527 for (y
= 0; y
< 4; y
++)
6529 for (x
= 0; x
< 4; x
++)
6531 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
6532 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6535 ok(data
[y
][x
] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6539 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6541 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6543 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6545 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6548 IDirectDrawSurface7_Release(surface
);
6549 ref
= IDirectDraw7_Release(ddraw
);
6550 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6551 DestroyWindow(window
);
6554 static void test_sysmem_overlay(void)
6556 IDirectDraw7
*ddraw
;
6559 DDSURFACEDESC2 ddsd
;
6560 IDirectDrawSurface7
*surface
;
6563 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6564 0, 0, 640, 480, 0, 0, 0, 0);
6565 ddraw
= create_ddraw();
6566 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6567 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6568 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6571 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
6574 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
6575 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6576 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6577 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6578 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6579 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6580 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6581 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6582 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
6584 ref
= IDirectDraw7_Release(ddraw
);
6585 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6586 DestroyWindow(window
);
6589 static void test_primary_palette(void)
6591 DDSCAPS2 surface_caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
6592 IDirectDrawSurface7
*primary
, *backbuffer
;
6593 PALETTEENTRY palette_entries
[256];
6594 IDirectDrawPalette
*palette
, *tmp
;
6595 DDSURFACEDESC2 surface_desc
;
6596 IDirectDraw7
*ddraw
;
6602 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6603 0, 0, 640, 480, 0, 0, 0, 0);
6604 ddraw
= create_ddraw();
6605 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6606 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
6608 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6609 IDirectDraw7_Release(ddraw
);
6610 DestroyWindow(window
);
6613 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6614 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6616 memset(&surface_desc
, 0, sizeof(surface_desc
));
6617 surface_desc
.dwSize
= sizeof(surface_desc
);
6618 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6619 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6620 U5(surface_desc
).dwBackBufferCount
= 1;
6621 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6622 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6623 hr
= IDirectDrawSurface7_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
6624 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6626 memset(palette_entries
, 0, sizeof(palette_entries
));
6627 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
6628 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6629 refcount
= get_refcount((IUnknown
*)palette
);
6630 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6632 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6633 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6634 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6636 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
6637 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6639 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6640 * and is generally somewhat broken with respect to 8 bpp / palette
6642 if (SUCCEEDED(IDirectDrawSurface7_GetPalette(backbuffer
, &tmp
)))
6644 win_skip("Broken palette handling detected, skipping tests.\n");
6645 IDirectDrawPalette_Release(tmp
);
6646 IDirectDrawPalette_Release(palette
);
6647 /* The Windows 8 testbot keeps extra references to the primary and
6648 * backbuffer while in 8 bpp mode. */
6649 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
6650 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
6654 refcount
= get_refcount((IUnknown
*)palette
);
6655 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6657 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6658 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6659 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
6660 "Got unexpected palette caps %#x.\n", palette_caps
);
6662 hr
= IDirectDrawSurface7_SetPalette(primary
, NULL
);
6663 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6664 refcount
= get_refcount((IUnknown
*)palette
);
6665 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6667 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6668 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6669 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6671 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
6672 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6673 refcount
= get_refcount((IUnknown
*)palette
);
6674 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6676 hr
= IDirectDrawSurface7_GetPalette(primary
, &tmp
);
6677 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6678 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
6679 IDirectDrawPalette_Release(tmp
);
6680 hr
= IDirectDrawSurface7_GetPalette(backbuffer
, &tmp
);
6681 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6683 refcount
= IDirectDrawPalette_Release(palette
);
6684 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6685 refcount
= IDirectDrawPalette_Release(palette
);
6686 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6688 /* Note that this only seems to work when the palette is attached to the
6689 * primary surface. When attached to a regular surface, attempting to get
6690 * the palette here will cause an access violation. */
6691 hr
= IDirectDrawSurface7_GetPalette(primary
, &tmp
);
6692 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6695 refcount
= IDirectDrawSurface7_Release(backbuffer
);
6696 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6697 refcount
= IDirectDrawSurface7_Release(primary
);
6698 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6699 refcount
= IDirectDraw7_Release(ddraw
);
6700 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6701 DestroyWindow(window
);
6704 static HRESULT WINAPI
surface_counter(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
6706 UINT
*surface_count
= context
;
6709 IDirectDrawSurface_Release(surface
);
6711 return DDENUMRET_OK
;
6714 static void test_surface_attachment(void)
6716 IDirectDrawSurface7
*surface1
, *surface2
, *surface3
, *surface4
;
6717 IDirectDrawSurface
*surface1v1
, *surface2v1
;
6718 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, {0}};
6719 DDSURFACEDESC2 surface_desc
;
6720 IDirectDraw7
*ddraw
;
6726 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6727 0, 0, 640, 480, 0, 0, 0, 0);
6728 ddraw
= create_ddraw();
6729 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6730 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6731 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6733 memset(&surface_desc
, 0, sizeof(surface_desc
));
6734 surface_desc
.dwSize
= sizeof(surface_desc
);
6735 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
6736 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6737 U2(surface_desc
).dwMipMapCount
= 3;
6738 surface_desc
.dwWidth
= 128;
6739 surface_desc
.dwHeight
= 128;
6740 if (FAILED(IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
)))
6742 skip("Failed to create a texture, skipping tests.\n");
6743 IDirectDraw7_Release(ddraw
);
6744 DestroyWindow(window
);
6748 hr
= IDirectDrawSurface7_GetAttachedSurface(surface1
, &caps
, &surface2
);
6749 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6750 hr
= IDirectDrawSurface7_GetAttachedSurface(surface2
, &caps
, &surface3
);
6751 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6752 hr
= IDirectDrawSurface7_GetAttachedSurface(surface3
, &caps
, &surface4
);
6753 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6756 IDirectDrawSurface7_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
6757 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6759 IDirectDrawSurface7_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
6760 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6762 IDirectDrawSurface7_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
6763 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
6765 memset(&surface_desc
, 0, sizeof(surface_desc
));
6766 surface_desc
.dwSize
= sizeof(surface_desc
);
6767 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6768 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6769 surface_desc
.dwWidth
= 16;
6770 surface_desc
.dwHeight
= 16;
6771 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6772 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6774 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
6775 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6776 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
6777 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6778 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
);
6779 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6780 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
6781 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6782 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
);
6783 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6784 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
6785 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6787 IDirectDrawSurface7_Release(surface4
);
6789 memset(&surface_desc
, 0, sizeof(surface_desc
));
6790 surface_desc
.dwSize
= sizeof(surface_desc
);
6791 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6792 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6793 surface_desc
.dwWidth
= 16;
6794 surface_desc
.dwHeight
= 16;
6795 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6796 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6798 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
6799 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6800 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
6801 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6802 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
);
6803 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6804 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
6805 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6806 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
);
6807 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6808 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
6809 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6811 IDirectDrawSurface7_Release(surface4
);
6812 IDirectDrawSurface7_Release(surface3
);
6813 IDirectDrawSurface7_Release(surface2
);
6814 IDirectDrawSurface7_Release(surface1
);
6816 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6817 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6819 /* Try a single primary and two offscreen plain surfaces. */
6820 memset(&surface_desc
, 0, sizeof(surface_desc
));
6821 surface_desc
.dwSize
= sizeof(surface_desc
);
6822 surface_desc
.dwFlags
= DDSD_CAPS
;
6823 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6824 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6825 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6827 memset(&surface_desc
, 0, sizeof(surface_desc
));
6828 surface_desc
.dwSize
= sizeof(surface_desc
);
6829 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6830 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6831 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6832 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6833 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
6834 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6836 memset(&surface_desc
, 0, sizeof(surface_desc
));
6837 surface_desc
.dwSize
= sizeof(surface_desc
);
6838 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6839 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6840 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6841 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6842 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6843 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6845 /* This one has a different size. */
6846 memset(&surface_desc
, 0, sizeof(surface_desc
));
6847 surface_desc
.dwSize
= sizeof(surface_desc
);
6848 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6849 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6850 surface_desc
.dwWidth
= 128;
6851 surface_desc
.dwHeight
= 128;
6852 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6853 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6855 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
6856 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6857 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface1
);
6858 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6859 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface3
);
6860 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6861 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
6862 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6863 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
6864 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6866 IDirectDrawSurface7_Release(surface4
);
6867 IDirectDrawSurface7_Release(surface3
);
6868 IDirectDrawSurface7_Release(surface2
);
6869 IDirectDrawSurface7_Release(surface1
);
6871 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
6872 memset(&surface_desc
, 0, sizeof(surface_desc
));
6873 surface_desc
.dwSize
= sizeof(surface_desc
);
6874 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6875 surface_desc
.dwWidth
= 64;
6876 surface_desc
.dwHeight
= 64;
6877 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
6878 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6879 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
6880 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
6881 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
6882 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
6883 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
6884 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6885 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6886 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6887 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6889 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
6890 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
6891 U1(U4(surface_desc
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
6892 U3(U4(surface_desc
).ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
6893 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
6894 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6896 hr
= IDirectDrawSurface7_QueryInterface(surface1
, &IID_IDirectDrawSurface
, (void **)&surface1v1
);
6897 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
6898 hr
= IDirectDrawSurface7_QueryInterface(surface2
, &IID_IDirectDrawSurface
, (void **)&surface2v1
);
6899 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
6901 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
6902 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6903 refcount
= get_refcount((IUnknown
*)surface2
);
6904 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6905 refcount
= get_refcount((IUnknown
*)surface2v1
);
6906 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6907 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
6908 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
6909 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
6910 todo_wine
ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6911 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
6912 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
6914 /* Attaching while already attached to other surface. */
6915 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface2
);
6916 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6917 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface3
, 0, surface2
);
6918 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6919 IDirectDrawSurface7_Release(surface3
);
6921 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface2
);
6922 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6923 refcount
= get_refcount((IUnknown
*)surface2
);
6924 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6925 refcount
= get_refcount((IUnknown
*)surface2v1
);
6926 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6928 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
6929 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
6930 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6931 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface2
);
6932 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
6933 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
6934 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6935 refcount
= IDirectDrawSurface7_Release(surface2
);
6936 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6937 refcount
= IDirectDrawSurface7_Release(surface1
);
6938 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6940 /* Automatic detachment on release. */
6941 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
6942 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6943 refcount
= get_refcount((IUnknown
*)surface2v1
);
6944 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6945 refcount
= IDirectDrawSurface_Release(surface1v1
);
6946 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6947 refcount
= IDirectDrawSurface_Release(surface2v1
);
6948 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6949 refcount
= IDirectDraw7_Release(ddraw
);
6950 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6951 DestroyWindow(window
);
6954 static void test_private_data(void)
6956 IDirectDraw7
*ddraw
;
6957 IDirectDrawSurface7
*surface
, *surface2
;
6958 DDSURFACEDESC2 surface_desc
;
6959 ULONG refcount
, refcount2
, refcount3
;
6961 DWORD size
= sizeof(ptr
);
6964 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
6965 DWORD data
[] = {1, 2, 3, 4};
6967 static const GUID ddraw_private_data_test_guid
=
6972 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
6974 static const GUID ddraw_private_data_test_guid2
=
6979 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
6982 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6983 0, 0, 640, 480, 0, 0, 0, 0);
6984 ddraw
= create_ddraw();
6985 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6986 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6987 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6989 reset_ddsd(&surface_desc
);
6990 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
6991 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
6992 surface_desc
.dwHeight
= 4;
6993 surface_desc
.dwWidth
= 4;
6994 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6995 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6997 /* NULL pointers are not valid, but don't cause a crash. */
6998 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
,
6999 sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
7000 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7001 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 0, 0);
7002 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7003 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 1, 0);
7004 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7006 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
7007 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7008 0, DDSPD_IUNKNOWNPOINTER
);
7009 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7010 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7011 5, DDSPD_IUNKNOWNPOINTER
);
7012 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7013 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7014 sizeof(ddraw
) * 2, DDSPD_IUNKNOWNPOINTER
);
7015 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7017 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
7018 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
7019 * erases the old content and returns an error. This behavior has
7020 * been fixed in d3d8 and d3d9. Unless an application is found
7021 * that depends on this we don't care about this behavior. */
7022 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7023 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7024 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7025 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7026 0, DDSPD_IUNKNOWNPOINTER
);
7027 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7029 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7030 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7031 hr
= IDirectDrawSurface7_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7032 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7034 refcount
= get_refcount((IUnknown
*)ddraw
);
7035 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7036 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7037 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7038 refcount2
= get_refcount((IUnknown
*)ddraw
);
7039 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7041 hr
= IDirectDrawSurface7_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7042 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7043 refcount2
= get_refcount((IUnknown
*)ddraw
);
7044 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7046 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7047 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7048 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7049 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, surface
,
7050 sizeof(surface
), DDSPD_IUNKNOWNPOINTER
);
7051 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7052 refcount2
= get_refcount((IUnknown
*)ddraw
);
7053 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7055 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7056 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7057 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7058 size
= 2 * sizeof(ptr
);
7059 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7060 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7061 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7062 refcount2
= get_refcount(ptr
);
7063 /* Object is NOT addref'ed by the getter. */
7064 ok(ptr
== (IUnknown
*)ddraw
, "Returned interface pointer is %p, expected %p.\n", ptr
, ddraw
);
7065 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7067 ptr
= (IUnknown
*)0xdeadbeef;
7069 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7070 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7071 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7072 size
= 2 * sizeof(ptr
);
7073 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7074 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7075 ok(size
== 2 * sizeof(ptr
), "Got unexpected size %u.\n", size
);
7077 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7078 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7079 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7080 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7081 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, NULL
, NULL
);
7082 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7084 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, &ptr
, &size
);
7085 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7086 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7087 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
7088 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7089 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7091 refcount3
= IDirectDrawSurface7_Release(surface
);
7092 ok(!refcount3
, "Got unexpected refcount %u.\n", refcount3
);
7094 /* Destroying the surface frees the reference held on the private data. It also frees
7095 * the reference the surface is holding on its creating object. */
7096 refcount2
= get_refcount((IUnknown
*)ddraw
);
7097 ok(refcount2
== refcount
- 1, "Got unexpected refcount %u.\n", refcount2
);
7099 memset(&hal_caps
, 0, sizeof(hal_caps
));
7100 hal_caps
.dwSize
= sizeof(hal_caps
);
7101 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7102 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7103 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) == (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)
7106 reset_ddsd(&surface_desc
);
7107 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_MIPMAPCOUNT
;
7108 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7109 surface_desc
.dwHeight
= 4;
7110 surface_desc
.dwWidth
= 4;
7111 U2(surface_desc
).dwMipMapCount
= 2;
7112 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7113 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7114 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &surface2
);
7115 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7117 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, data
, sizeof(data
), 0);
7118 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7119 hr
= IDirectDrawSurface7_GetPrivateData(surface2
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7120 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7122 IDirectDrawSurface7_Release(surface2
);
7123 IDirectDrawSurface7_Release(surface
);
7126 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7128 refcount
= IDirectDraw7_Release(ddraw
);
7129 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7130 DestroyWindow(window
);
7133 static void test_pixel_format(void)
7135 HWND window
, window2
= NULL
;
7136 HDC hdc
, hdc2
= NULL
;
7138 int format
, test_format
;
7139 PIXELFORMATDESCRIPTOR pfd
;
7140 IDirectDraw7
*ddraw
= NULL
;
7141 IDirectDrawClipper
*clipper
= NULL
;
7142 DDSURFACEDESC2 ddsd
;
7143 IDirectDrawSurface7
*primary
= NULL
;
7147 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7148 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7151 skip("Failed to create window\n");
7155 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7156 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7158 hdc
= GetDC(window
);
7161 skip("Failed to get DC\n");
7166 hdc2
= GetDC(window2
);
7168 gl
= LoadLibraryA("opengl32.dll");
7169 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7171 format
= GetPixelFormat(hdc
);
7172 ok(format
== 0, "new window has pixel format %d\n", format
);
7174 ZeroMemory(&pfd
, sizeof(pfd
));
7175 pfd
.nSize
= sizeof(pfd
);
7177 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
7178 pfd
.iPixelType
= PFD_TYPE_RGBA
;
7179 pfd
.iLayerType
= PFD_MAIN_PLANE
;
7180 format
= ChoosePixelFormat(hdc
, &pfd
);
7183 skip("no pixel format available\n");
7187 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
7189 skip("failed to set pixel format\n");
7193 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
7195 skip("failed to set pixel format on second window\n");
7198 ReleaseDC(window2
, hdc2
);
7203 ddraw
= create_ddraw();
7204 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7206 test_format
= GetPixelFormat(hdc
);
7207 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7209 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7212 skip("Failed to set cooperative level, hr %#x.\n", hr
);
7216 test_format
= GetPixelFormat(hdc
);
7217 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7221 hr
= IDirectDraw7_CreateClipper(ddraw
, 0, &clipper
, NULL
);
7222 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
7223 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
7224 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
7226 test_format
= GetPixelFormat(hdc
);
7227 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7229 test_format
= GetPixelFormat(hdc2
);
7230 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7233 memset(&ddsd
, 0, sizeof(ddsd
));
7234 ddsd
.dwSize
= sizeof(ddsd
);
7235 ddsd
.dwFlags
= DDSD_CAPS
;
7236 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7238 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
7239 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
7241 test_format
= GetPixelFormat(hdc
);
7242 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7246 test_format
= GetPixelFormat(hdc2
);
7247 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7252 hr
= IDirectDrawSurface7_SetClipper(primary
, clipper
);
7253 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
7255 test_format
= GetPixelFormat(hdc
);
7256 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7258 test_format
= GetPixelFormat(hdc2
);
7259 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7262 memset(&fx
, 0, sizeof(fx
));
7263 fx
.dwSize
= sizeof(fx
);
7264 hr
= IDirectDrawSurface7_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7265 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
7267 test_format
= GetPixelFormat(hdc
);
7268 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7272 test_format
= GetPixelFormat(hdc2
);
7273 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7277 if (primary
) IDirectDrawSurface7_Release(primary
);
7278 if (clipper
) IDirectDrawClipper_Release(clipper
);
7279 if (ddraw
) IDirectDraw7_Release(ddraw
);
7280 if (gl
) FreeLibrary(gl
);
7281 if (hdc
) ReleaseDC(window
, hdc
);
7282 if (hdc2
) ReleaseDC(window2
, hdc2
);
7283 if (window
) DestroyWindow(window
);
7284 if (window2
) DestroyWindow(window2
);
7287 static void test_create_surface_pitch(void)
7289 IDirectDrawSurface7
*surface
;
7290 DDSURFACEDESC2 surface_desc
;
7291 IDirectDraw7
*ddraw
;
7310 {DDSCAPS_VIDEOMEMORY
, 0, 0, DD_OK
,
7311 DDSD_PITCH
, 0x100, 0x100},
7312 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
7313 DDSD_PITCH
, 0x100, 0x100},
7314 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
7315 DDSD_PITCH
, 0x100, 0x100},
7316 {DDSCAPS_VIDEOMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7318 {DDSCAPS_SYSTEMMEMORY
, 0, 0, DD_OK
,
7319 DDSD_PITCH
, 0x100, 0x0fc},
7320 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
7321 DDSD_PITCH
, 0x100, 0x0fc},
7322 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
7323 DDSD_PITCH
, 0x100, 0x0fc},
7324 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
7325 DDSD_PITCH
, 0x100, 0x0fc},
7326 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
7328 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7329 DDSD_PITCH
, 0x100, 0x100},
7330 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fe, DDERR_INVALIDPARAMS
,
7332 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fc, DD_OK
,
7333 DDSD_PITCH
, 0x0fc, 0x0fc},
7334 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0f8, DDERR_INVALIDPARAMS
,
7336 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x100, DDERR_INVALIDPARAMS
,
7338 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x3f00, DDERR_INVALIDPARAMS
,
7340 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, 0x100, DD_OK
,
7341 DDSD_PITCH
, 0x100, 0x100},
7343 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
7345 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7346 0, 0, 640, 480, 0, 0, 0, 0);
7347 ddraw
= create_ddraw();
7348 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7349 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7350 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7352 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
7354 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
7356 memset(&surface_desc
, 0, sizeof(surface_desc
));
7357 surface_desc
.dwSize
= sizeof(surface_desc
);
7358 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
7359 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| test_data
[i
].placement
;
7360 surface_desc
.dwWidth
= 63;
7361 surface_desc
.dwHeight
= 63;
7362 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
7363 surface_desc
.lpSurface
= mem
;
7364 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7365 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7366 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7367 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7368 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7369 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7370 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7371 ok(hr
== test_data
[i
].hr
|| (test_data
[i
].placement
== DDSCAPS_VIDEOMEMORY
&& hr
== DDERR_NODIRECTDRAWHW
),
7372 "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
7376 memset(&surface_desc
, 0, sizeof(surface_desc
));
7377 surface_desc
.dwSize
= sizeof(surface_desc
);
7378 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
7379 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7380 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
7381 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7382 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
7383 if (sizeof(void *) != sizeof(DWORD
) && test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
7384 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
7385 "Test %u: Got unexpected pitch %u, expected %u.\n",
7386 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
7388 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
7389 "Test %u: Got unexpected pitch %u, expected %u.\n",
7390 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
7391 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
7393 IDirectDrawSurface7_Release(surface
);
7396 HeapFree(GetProcessHeap(), 0, mem
);
7397 refcount
= IDirectDraw7_Release(ddraw
);
7398 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7399 DestroyWindow(window
);
7402 static void test_mipmap_lock(void)
7404 IDirectDrawSurface7
*surface
, *surface2
;
7405 DDSURFACEDESC2 surface_desc
;
7406 IDirectDraw7
*ddraw
;
7410 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7413 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7414 0, 0, 640, 480, 0, 0, 0, 0);
7415 ddraw
= create_ddraw();
7416 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7417 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7418 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7420 memset(&hal_caps
, 0, sizeof(hal_caps
));
7421 hal_caps
.dwSize
= sizeof(hal_caps
);
7422 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7423 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7424 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)
7427 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
7428 IDirectDraw7_Release(ddraw
);
7429 DestroyWindow(window
);
7433 memset(&surface_desc
, 0, sizeof(surface_desc
));
7434 surface_desc
.dwSize
= sizeof(surface_desc
);
7435 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
7436 surface_desc
.dwWidth
= 4;
7437 surface_desc
.dwHeight
= 4;
7438 U2(surface_desc
).dwMipMapCount
= 2;
7439 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
7440 | DDSCAPS_SYSTEMMEMORY
;
7441 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7442 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7443 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &surface2
);
7444 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7446 memset(&surface_desc
, 0, sizeof(surface_desc
));
7447 surface_desc
.dwSize
= sizeof(surface_desc
);
7448 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7449 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7450 memset(&surface_desc
, 0, sizeof(surface_desc
));
7451 surface_desc
.dwSize
= sizeof(surface_desc
);
7452 hr
= IDirectDrawSurface7_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
7453 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7454 IDirectDrawSurface7_Unlock(surface2
, NULL
);
7455 IDirectDrawSurface7_Unlock(surface
, NULL
);
7457 IDirectDrawSurface7_Release(surface2
);
7458 IDirectDrawSurface7_Release(surface
);
7459 refcount
= IDirectDraw7_Release(ddraw
);
7460 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7461 DestroyWindow(window
);
7464 static void test_palette_complex(void)
7466 IDirectDrawSurface7
*surface
, *mipmap
, *tmp
;
7467 DDSURFACEDESC2 surface_desc
;
7468 IDirectDraw7
*ddraw
;
7469 IDirectDrawPalette
*palette
, *palette2
;
7473 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7475 PALETTEENTRY palette_entries
[256];
7478 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7479 0, 0, 640, 480, 0, 0, 0, 0);
7480 ddraw
= create_ddraw();
7481 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7482 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7483 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7485 memset(&hal_caps
, 0, sizeof(hal_caps
));
7486 hal_caps
.dwSize
= sizeof(hal_caps
);
7487 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7488 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7489 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)
7492 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7493 IDirectDraw7_Release(ddraw
);
7494 DestroyWindow(window
);
7498 memset(&surface_desc
, 0, sizeof(surface_desc
));
7499 surface_desc
.dwSize
= sizeof(surface_desc
);
7500 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7501 surface_desc
.dwWidth
= 128;
7502 surface_desc
.dwHeight
= 128;
7503 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7504 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7505 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7506 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7507 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7508 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7510 memset(palette_entries
, 0, sizeof(palette_entries
));
7511 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7512 palette_entries
, &palette
, NULL
);
7513 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7515 palette2
= (void *)0xdeadbeef;
7516 hr
= IDirectDrawSurface7_GetPalette(surface
, &palette2
);
7517 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
7518 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
7519 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
7520 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7521 hr
= IDirectDrawSurface7_GetPalette(surface
, &palette2
);
7522 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
7523 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
7524 IDirectDrawPalette_Release(palette2
);
7527 IDirectDrawSurface7_AddRef(mipmap
);
7528 for (i
= 0; i
< 7; ++i
)
7530 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7531 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
7532 palette2
= (void *)0xdeadbeef;
7533 hr
= IDirectDrawSurface7_GetPalette(tmp
, &palette2
);
7534 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7535 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
7537 hr
= IDirectDrawSurface7_SetPalette(tmp
, palette
);
7538 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7540 hr
= IDirectDrawSurface7_GetPalette(tmp
, &palette2
);
7541 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7542 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
7544 /* Ddraw7 uses the palette of the mipmap for GetDC, just like previous
7545 * ddraw versions. Combined with the test results above this means no
7546 * palette is available. So depending on the driver either GetDC fails
7547 * or the DIB color table contains random data. */
7549 IDirectDrawSurface7_Release(mipmap
);
7553 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7554 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7555 IDirectDrawSurface7_Release(mipmap
);
7556 refcount
= IDirectDrawSurface7_Release(surface
);
7557 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7559 /* Test DDERR_INVALIDPIXELFORMAT vs DDERR_NOTONMIPMAPSUBLEVEL. */
7560 memset(&surface_desc
, 0, sizeof(surface_desc
));
7561 surface_desc
.dwSize
= sizeof(surface_desc
);
7562 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7563 surface_desc
.dwWidth
= 128;
7564 surface_desc
.dwHeight
= 128;
7565 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7566 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7567 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7568 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7569 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7570 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7571 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7572 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7573 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7575 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &mipmap
);
7576 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7577 hr
= IDirectDrawSurface7_SetPalette(mipmap
, palette
);
7578 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x.\n", hr
);
7580 IDirectDrawSurface7_Release(mipmap
);
7581 refcount
= IDirectDrawSurface7_Release(surface
);
7582 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7583 refcount
= IDirectDrawPalette_Release(palette
);
7584 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7586 refcount
= IDirectDraw7_Release(ddraw
);
7587 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7588 DestroyWindow(window
);
7591 static void test_p8_rgb_blit(void)
7593 IDirectDrawSurface7
*src
, *dst
;
7594 DDSURFACEDESC2 surface_desc
;
7595 IDirectDraw7
*ddraw
;
7596 IDirectDrawPalette
*palette
;
7600 PALETTEENTRY palette_entries
[256];
7602 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7603 static const D3DCOLOR expected
[] =
7605 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7606 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7610 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7611 0, 0, 640, 480, 0, 0, 0, 0);
7612 ddraw
= create_ddraw();
7613 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7614 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7615 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7617 memset(palette_entries
, 0, sizeof(palette_entries
));
7618 palette_entries
[1].peGreen
= 0xff;
7619 palette_entries
[2].peBlue
= 0xff;
7620 palette_entries
[3].peFlags
= 0xff;
7621 palette_entries
[4].peRed
= 0xff;
7622 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7623 palette_entries
, &palette
, NULL
);
7624 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7626 memset(&surface_desc
, 0, sizeof(surface_desc
));
7627 surface_desc
.dwSize
= sizeof(surface_desc
);
7628 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7629 surface_desc
.dwWidth
= 8;
7630 surface_desc
.dwHeight
= 1;
7631 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7632 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7633 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7634 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7635 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
7636 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7638 memset(&surface_desc
, 0, sizeof(surface_desc
));
7639 surface_desc
.dwSize
= sizeof(surface_desc
);
7640 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7641 surface_desc
.dwWidth
= 8;
7642 surface_desc
.dwHeight
= 1;
7643 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7644 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7645 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
7646 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7647 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7648 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7649 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7650 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
7651 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
7652 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7654 memset(&surface_desc
, 0, sizeof(surface_desc
));
7655 surface_desc
.dwSize
= sizeof(surface_desc
);
7656 hr
= IDirectDrawSurface7_Lock(src
, NULL
, &surface_desc
, 0, NULL
);
7657 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
7658 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
7659 hr
= IDirectDrawSurface7_Unlock(src
, NULL
);
7660 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
7662 hr
= IDirectDrawSurface7_SetPalette(src
, palette
);
7663 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7664 hr
= IDirectDrawSurface7_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
7665 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
7666 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
7667 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
7668 "Failed to blit, hr %#x.\n", hr
);
7672 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
7674 color
= get_surface_color(dst
, x
, 0);
7675 todo_wine
ok(compare_color(color
, expected
[x
], 0),
7676 "Pixel %u: Got color %#x, expected %#x.\n",
7677 x
, color
, expected
[x
]);
7681 IDirectDrawSurface7_Release(src
);
7682 IDirectDrawSurface7_Release(dst
);
7683 IDirectDrawPalette_Release(palette
);
7685 refcount
= IDirectDraw7_Release(ddraw
);
7686 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7687 DestroyWindow(window
);
7690 static void test_material(void)
7692 static const D3DCOLORVALUE null_color
;
7693 IDirect3DDevice7
*device
;
7694 D3DMATERIAL7 material
;
7699 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7700 0, 0, 640, 480, 0, 0, 0, 0);
7701 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
7703 skip("Failed to create a 3D device, skipping test.\n");
7704 DestroyWindow(window
);
7708 hr
= IDirect3DDevice7_GetMaterial(device
, &material
);
7709 ok(SUCCEEDED(hr
), "Failed to get material, hr %#x.\n", hr
);
7710 ok(!memcmp(&U(material
).diffuse
, &null_color
, sizeof(null_color
)),
7711 "Got unexpected diffuse color {%.8e, %.8e, %.8e, %.8e}.\n",
7712 U1(U(material
).diffuse
).r
, U2(U(material
).diffuse
).g
,
7713 U3(U(material
).diffuse
).b
, U4(U(material
).diffuse
).a
);
7714 ok(!memcmp(&U1(material
).ambient
, &null_color
, sizeof(null_color
)),
7715 "Got unexpected ambient color {%.8e, %.8e, %.8e, %.8e}.\n",
7716 U1(U1(material
).ambient
).r
, U2(U1(material
).ambient
).g
,
7717 U3(U1(material
).ambient
).b
, U4(U1(material
).ambient
).a
);
7718 ok(!memcmp(&U2(material
).specular
, &null_color
, sizeof(null_color
)),
7719 "Got unexpected specular color {%.8e, %.8e, %.8e, %.8e}.\n",
7720 U1(U2(material
).specular
).r
, U2(U2(material
).specular
).g
,
7721 U3(U2(material
).specular
).b
, U4(U2(material
).specular
).a
);
7722 ok(!memcmp(&U3(material
).emissive
, &null_color
, sizeof(null_color
)),
7723 "Got unexpected emissive color {%.8e, %.8e, %.8e, %.8e}.\n",
7724 U1(U3(material
).emissive
).r
, U2(U3(material
).emissive
).g
,
7725 U3(U3(material
).emissive
).b
, U4(U3(material
).emissive
).a
);
7726 ok(U4(material
).power
== 0.0f
, "Got unexpected power %.8e.\n", U4(material
).power
);
7728 refcount
= IDirect3DDevice7_Release(device
);
7729 ok(!refcount
, "Device has %u references left.\n", refcount
);
7730 DestroyWindow(window
);
7733 static void test_palette_gdi(void)
7735 IDirectDrawSurface7
*surface
, *primary
;
7736 DDSURFACEDESC2 surface_desc
;
7737 IDirectDraw7
*ddraw
;
7738 IDirectDrawPalette
*palette
, *palette2
;
7742 PALETTEENTRY palette_entries
[256];
7745 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7746 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7747 * not the point of this test. */
7748 static const RGBQUAD expected1
[] =
7750 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7751 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7753 static const RGBQUAD expected2
[] =
7755 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7756 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7758 static const RGBQUAD expected3
[] =
7760 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7761 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7763 HPALETTE ddraw_palette_handle
;
7764 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7765 RGBQUAD rgbquad
[255];
7766 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
7768 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7769 0, 0, 640, 480, 0, 0, 0, 0);
7770 ddraw
= create_ddraw();
7771 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7772 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7773 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7775 memset(&surface_desc
, 0, sizeof(surface_desc
));
7776 surface_desc
.dwSize
= sizeof(surface_desc
);
7777 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7778 surface_desc
.dwWidth
= 16;
7779 surface_desc
.dwHeight
= 16;
7780 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7781 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7782 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7783 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7784 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7785 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7787 /* Avoid colors from the Windows default palette. */
7788 memset(palette_entries
, 0, sizeof(palette_entries
));
7789 palette_entries
[1].peRed
= 0x01;
7790 palette_entries
[2].peGreen
= 0x02;
7791 palette_entries
[3].peBlue
= 0x03;
7792 palette_entries
[4].peRed
= 0x13;
7793 palette_entries
[4].peGreen
= 0x14;
7794 palette_entries
[4].peBlue
= 0x15;
7795 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7796 palette_entries
, &palette
, NULL
);
7797 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7799 /* If there is no palette assigned and the display mode is not 8 bpp, some
7800 * drivers refuse to create a DC while others allow it. If a DC is created,
7801 * the DIB color table is uninitialized and contains random colors. No error
7802 * is generated when trying to read pixels and random garbage is returned.
7804 * The most likely explanation is that if the driver creates a DC, it (or
7805 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7806 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7807 * contains uninitialized garbage. See comments below for the P8 case. */
7809 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
7810 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7811 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
7812 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7813 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7814 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7815 "Got unexpected palette %p, expected %p.\n",
7816 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7818 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7819 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7820 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
7822 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
7823 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7824 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7825 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
7827 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7829 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7830 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7831 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7834 /* Update the palette while the DC is in use. This does not modify the DC. */
7835 palette_entries
[4].peRed
= 0x23;
7836 palette_entries
[4].peGreen
= 0x24;
7837 palette_entries
[4].peBlue
= 0x25;
7838 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
7839 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
7841 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7842 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7843 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7844 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7845 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7846 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7848 /* Neither does re-setting the palette. */
7849 hr
= IDirectDrawSurface7_SetPalette(surface
, NULL
);
7850 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7851 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
7852 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7854 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7855 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7856 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7857 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7858 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7859 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7861 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
7862 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7864 /* Refresh the DC. This updates the palette. */
7865 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
7866 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7867 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7868 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7869 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7871 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7872 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7873 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7874 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7876 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7878 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7879 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7880 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7882 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
7883 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7885 refcount
= IDirectDrawSurface7_Release(surface
);
7886 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7888 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7890 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7891 IDirectDrawPalette_Release(palette
);
7892 IDirectDraw7_Release(ddraw
);
7893 DestroyWindow(window
);
7896 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
7897 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
7898 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7900 memset(&surface_desc
, 0, sizeof(surface_desc
));
7901 surface_desc
.dwSize
= sizeof(surface_desc
);
7902 surface_desc
.dwFlags
= DDSD_CAPS
;
7903 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7904 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
7905 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7907 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
7908 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7909 hr
= IDirectDrawSurface7_GetDC(primary
, &dc
);
7910 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7911 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7912 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
7913 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
7914 "Got unexpected palette %p, expected %p.\n",
7915 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7916 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
7918 /* The primary uses the system palette. In exclusive mode, the system palette matches
7919 * the ddraw palette attached to the primary, so the result is what you would expect
7920 * from a regular surface. Tests for the interaction between the ddraw palette and
7921 * the system palette are not included pending an application that depends on this.
7922 * The relation between those causes problems on Windows Vista and newer for games
7923 * like Age of Empires or StarcCaft. Don't emulate it without a real need. */
7924 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7925 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7926 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7928 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7929 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7930 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7931 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7933 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7935 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7936 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7937 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7939 hr
= IDirectDrawSurface7_ReleaseDC(primary
, dc
);
7940 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7942 memset(&surface_desc
, 0, sizeof(surface_desc
));
7943 surface_desc
.dwSize
= sizeof(surface_desc
);
7944 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7945 surface_desc
.dwWidth
= 16;
7946 surface_desc
.dwHeight
= 16;
7947 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7948 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7949 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7951 /* Here the offscreen surface appears to use the primary's palette,
7952 * but in all likelihood it is actually the system palette. */
7953 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
7954 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7955 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7956 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7957 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7959 ok(!memcmp(&rgbquad
[i
], &expected2
[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 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[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 /* On real hardware a change to the primary surface's palette applies immediately,
7974 * even on device contexts from offscreen surfaces that do not have their own
7975 * palette. On the testbot VMs this is not the case. Don't test this until we
7976 * know of an application that depends on this. */
7978 memset(palette_entries
, 0, sizeof(palette_entries
));
7979 palette_entries
[1].peBlue
= 0x40;
7980 palette_entries
[2].peRed
= 0x40;
7981 palette_entries
[3].peGreen
= 0x40;
7982 palette_entries
[4].peRed
= 0x12;
7983 palette_entries
[4].peGreen
= 0x34;
7984 palette_entries
[4].peBlue
= 0x56;
7985 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7986 palette_entries
, &palette2
, NULL
);
7987 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7988 hr
= IDirectDrawSurface7_SetPalette(surface
, palette2
);
7989 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7991 /* A palette assigned to the offscreen surface overrides the primary / system
7993 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
7994 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7995 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7996 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7997 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
7999 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
8000 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8001 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8002 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
8004 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8006 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8007 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8008 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8010 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
8011 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8013 refcount
= IDirectDrawSurface7_Release(surface
);
8014 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8016 /* The Windows 8 testbot keeps extra references to the primary and
8017 * backbuffer while in 8 bpp mode. */
8018 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
8019 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8021 refcount
= IDirectDrawSurface7_Release(primary
);
8022 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8023 refcount
= IDirectDrawPalette_Release(palette2
);
8024 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8025 refcount
= IDirectDrawPalette_Release(palette
);
8026 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8027 refcount
= IDirectDraw7_Release(ddraw
);
8028 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8029 DestroyWindow(window
);
8032 static void test_palette_alpha(void)
8034 IDirectDrawSurface7
*surface
;
8035 DDSURFACEDESC2 surface_desc
;
8036 IDirectDraw7
*ddraw
;
8037 IDirectDrawPalette
*palette
;
8041 PALETTEENTRY palette_entries
[256];
8046 BOOL attach_allowed
;
8051 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
8052 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
8053 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
8056 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8057 0, 0, 640, 480, 0, 0, 0, 0);
8058 ddraw
= create_ddraw();
8059 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8060 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8062 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8063 IDirectDraw7_Release(ddraw
);
8064 DestroyWindow(window
);
8067 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8068 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8070 memset(palette_entries
, 0, sizeof(palette_entries
));
8071 palette_entries
[1].peFlags
= 0x42;
8072 palette_entries
[2].peFlags
= 0xff;
8073 palette_entries
[3].peFlags
= 0x80;
8074 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
8075 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8077 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8078 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8079 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8080 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8081 palette_entries
[0].peFlags
);
8082 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8083 palette_entries
[1].peFlags
);
8084 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8085 palette_entries
[2].peFlags
);
8086 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8087 palette_entries
[3].peFlags
);
8089 IDirectDrawPalette_Release(palette
);
8091 memset(palette_entries
, 0, sizeof(palette_entries
));
8092 palette_entries
[1].peFlags
= 0x42;
8093 palette_entries
[1].peRed
= 0xff;
8094 palette_entries
[2].peFlags
= 0xff;
8095 palette_entries
[3].peFlags
= 0x80;
8096 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
8097 palette_entries
, &palette
, NULL
);
8098 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8100 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8101 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8102 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8103 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8104 palette_entries
[0].peFlags
);
8105 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8106 palette_entries
[1].peFlags
);
8107 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8108 palette_entries
[2].peFlags
);
8109 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8110 palette_entries
[3].peFlags
);
8112 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
8114 memset(&surface_desc
, 0, sizeof(surface_desc
));
8115 surface_desc
.dwSize
= sizeof(surface_desc
);
8116 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
8117 surface_desc
.dwWidth
= 128;
8118 surface_desc
.dwHeight
= 128;
8119 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
8120 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8121 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8123 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
8124 if (test_data
[i
].attach_allowed
)
8125 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8127 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8135 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
8136 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8137 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
8138 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
8139 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8140 rgbquad
.rgbRed
, test_data
[i
].name
);
8141 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8142 rgbquad
.rgbGreen
, test_data
[i
].name
);
8143 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8144 rgbquad
.rgbBlue
, test_data
[i
].name
);
8145 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8146 rgbquad
.rgbReserved
, test_data
[i
].name
);
8147 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
8148 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8150 IDirectDrawSurface7_Release(surface
);
8153 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8154 memset(&surface_desc
, 0, sizeof(surface_desc
));
8155 surface_desc
.dwSize
= sizeof(surface_desc
);
8156 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8157 surface_desc
.dwWidth
= 128;
8158 surface_desc
.dwHeight
= 128;
8159 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8160 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8161 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8162 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
8163 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8164 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8165 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8166 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8167 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8168 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
8169 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
8170 IDirectDrawSurface7_Release(surface
);
8172 /* The Windows 8 testbot keeps extra references to the primary
8173 * while in 8 bpp mode. */
8174 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
8175 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8177 refcount
= IDirectDrawPalette_Release(palette
);
8178 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8179 refcount
= IDirectDraw7_Release(ddraw
);
8180 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8181 DestroyWindow(window
);
8184 static void test_vb_writeonly(void)
8186 IDirect3DDevice7
*device
;
8188 IDirect3DVertexBuffer7
*buffer
;
8191 D3DVERTEXBUFFERDESC desc
;
8193 static const struct vec4 quad
[] =
8195 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
8196 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
8197 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
8198 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
8201 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8202 0, 0, 640, 480, 0, 0, 0, 0);
8204 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8206 skip("Failed to create a 3D device, skipping test.\n");
8207 DestroyWindow(window
);
8211 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
8212 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
8214 memset(&desc
, 0, sizeof(desc
));
8215 desc
.dwSize
= sizeof(desc
);
8216 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
8217 desc
.dwFVF
= D3DFVF_XYZRHW
;
8218 desc
.dwNumVertices
= sizeof(quad
) / sizeof(*quad
);
8219 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0);
8220 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
8222 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, &ptr
, NULL
);
8223 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8224 memcpy(ptr
, quad
, sizeof(quad
));
8225 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
8226 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8228 hr
= IDirect3DDevice7_BeginScene(device
);
8229 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8230 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
8231 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8232 hr
= IDirect3DDevice7_EndScene(device
);
8233 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8235 hr
= IDirect3DVertexBuffer7_Lock(buffer
, 0, &ptr
, NULL
);
8236 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8237 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8238 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
8239 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8241 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_READONLY
, &ptr
, NULL
);
8242 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8243 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8244 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
8245 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8247 IDirect3DVertexBuffer7_Release(buffer
);
8248 IDirect3D7_Release(d3d
);
8249 IDirect3DDevice7_Release(device
);
8250 DestroyWindow(window
);
8253 static void test_lost_device(void)
8255 IDirectDrawSurface7
*surface
;
8256 DDSURFACEDESC2 surface_desc
;
8257 HWND window1
, window2
;
8258 IDirectDraw7
*ddraw
;
8263 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8264 0, 0, 640, 480, 0, 0, 0, 0);
8265 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8266 0, 0, 640, 480, 0, 0, 0, 0);
8267 ddraw
= create_ddraw();
8268 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8269 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8270 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8272 memset(&surface_desc
, 0, sizeof(surface_desc
));
8273 surface_desc
.dwSize
= sizeof(surface_desc
);
8274 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8275 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8276 U5(surface_desc
).dwBackBufferCount
= 1;
8277 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8278 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8280 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8281 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8282 hr
= IDirectDrawSurface7_IsLost(surface
);
8283 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8284 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8285 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8287 ret
= SetForegroundWindow(GetDesktopWindow());
8288 ok(ret
, "Failed to set foreground window.\n");
8289 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8290 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8291 hr
= IDirectDrawSurface7_IsLost(surface
);
8292 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8293 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8294 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8296 ret
= SetForegroundWindow(window1
);
8297 ok(ret
, "Failed to set foreground window.\n");
8298 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8299 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8300 hr
= IDirectDrawSurface7_IsLost(surface
);
8301 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8302 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8303 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8305 hr
= IDirectDraw7_RestoreAllSurfaces(ddraw
);
8306 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
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
);
8311 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8312 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8314 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8315 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8316 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8317 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8318 hr
= IDirectDrawSurface7_IsLost(surface
);
8319 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8320 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8321 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8323 /* Trying to restore the primary will crash, probably because flippable
8324 * surfaces can't exist in DDSCL_NORMAL. */
8325 IDirectDrawSurface7_Release(surface
);
8326 memset(&surface_desc
, 0, sizeof(surface_desc
));
8327 surface_desc
.dwSize
= sizeof(surface_desc
);
8328 surface_desc
.dwFlags
= DDSD_CAPS
;
8329 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8330 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8331 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8333 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8334 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8335 hr
= IDirectDrawSurface7_IsLost(surface
);
8336 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8338 ret
= SetForegroundWindow(GetDesktopWindow());
8339 ok(ret
, "Failed to set foreground window.\n");
8340 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8341 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8342 hr
= IDirectDrawSurface7_IsLost(surface
);
8343 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8345 ret
= SetForegroundWindow(window1
);
8346 ok(ret
, "Failed to set foreground window.\n");
8347 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8348 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8349 hr
= IDirectDrawSurface7_IsLost(surface
);
8350 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8352 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8353 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8354 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8355 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8356 hr
= IDirectDrawSurface7_IsLost(surface
);
8357 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8359 hr
= IDirectDraw7_RestoreAllSurfaces(ddraw
);
8360 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8361 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8362 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8363 hr
= IDirectDrawSurface7_IsLost(surface
);
8364 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8366 IDirectDrawSurface7_Release(surface
);
8367 memset(&surface_desc
, 0, sizeof(surface_desc
));
8368 surface_desc
.dwSize
= sizeof(surface_desc
);
8369 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8370 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8371 U5(surface_desc
).dwBackBufferCount
= 1;
8372 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8373 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8375 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8376 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8377 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8378 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8379 hr
= IDirectDrawSurface7_IsLost(surface
);
8380 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8381 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8382 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8384 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8385 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8386 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8387 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8388 hr
= IDirectDrawSurface7_IsLost(surface
);
8389 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8390 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8391 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8393 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8394 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8395 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8396 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8397 hr
= IDirectDrawSurface7_IsLost(surface
);
8398 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8399 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8400 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8402 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
8403 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8404 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8405 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8406 hr
= IDirectDrawSurface7_IsLost(surface
);
8407 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8408 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8409 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8411 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8412 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8413 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8414 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8415 hr
= IDirectDrawSurface7_IsLost(surface
);
8416 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8417 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8418 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8420 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8421 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8422 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8423 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8424 hr
= IDirectDrawSurface7_IsLost(surface
);
8425 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8426 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8427 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8429 IDirectDrawSurface7_Release(surface
);
8430 refcount
= IDirectDraw7_Release(ddraw
);
8431 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8432 DestroyWindow(window2
);
8433 DestroyWindow(window1
);
8436 static void test_resource_priority(void)
8438 IDirectDrawSurface7
*surface
, *mipmap
;
8439 DDSURFACEDESC2 surface_desc
;
8440 IDirectDraw7
*ddraw
;
8444 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
8446 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_MIPMAP
;
8454 /* SetPriority on offscreenplain surfaces crashes on AMD GPUs on Win7. */
8459 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem texture", DDERR_INVALIDPARAMS
, FALSE
},
8460 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem texture", DDERR_INVALIDPARAMS
, FALSE
},
8461 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, "managed texture", DD_OK
, FALSE
},
8462 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, "managed texture", DD_OK
, FALSE
},
8463 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem offscreenplain", DDERR_INVALIDOBJECT
, TRUE
},
8464 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem offscreenplain", DDERR_INVALIDOBJECT
, TRUE
},
8467 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8468 0, 0, 640, 480, 0, 0, 0, 0);
8469 ddraw
= create_ddraw();
8470 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8471 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8472 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8474 memset(&hal_caps
, 0, sizeof(hal_caps
));
8475 hal_caps
.dwSize
= sizeof(hal_caps
);
8476 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
8477 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
8478 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
8479 || !(hal_caps
.ddsCaps
.dwCaps
& DDSCAPS2_TEXTUREMANAGE
))
8481 skip("Required surface types not supported, skipping test.\n");
8485 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
8487 memset(&surface_desc
, 0, sizeof(surface_desc
));
8488 surface_desc
.dwSize
= sizeof(surface_desc
);
8489 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
8490 surface_desc
.dwWidth
= 32;
8491 surface_desc
.dwHeight
= 32;
8492 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
8493 surface_desc
.ddsCaps
.dwCaps2
= test_data
[i
].caps2
;
8494 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8495 if (is_ddraw64
&& (test_data
[i
].caps
& DDSCAPS_TEXTURE
))
8497 todo_wine
ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8499 IDirectDrawSurface7_Release(surface
);
8502 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8504 /* Priority == NULL segfaults. */
8505 priority
= 0xdeadbeef;
8506 hr
= IDirectDrawSurface7_GetPriority(surface
, &priority
);
8507 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8508 if (SUCCEEDED(test_data
[i
].hr
))
8509 ok(priority
== 0, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8511 ok(priority
== 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8513 if (!test_data
[i
].crash
)
8515 hr
= IDirectDrawSurface7_SetPriority(surface
, 1);
8516 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8517 hr
= IDirectDrawSurface7_GetPriority(surface
, &priority
);
8518 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8519 if (SUCCEEDED(test_data
[i
].hr
))
8521 ok(priority
== 1, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8522 hr
= IDirectDrawSurface7_SetPriority(surface
, 2);
8523 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8526 ok(priority
== 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8529 IDirectDrawSurface7_Release(surface
);
8535 memset(&surface_desc
, 0, sizeof(surface_desc
));
8536 surface_desc
.dwSize
= sizeof(surface_desc
);
8537 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_MIPMAPCOUNT
;
8538 surface_desc
.dwWidth
= 32;
8539 surface_desc
.dwHeight
= 32;
8540 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
8541 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
8542 U2(surface_desc
).dwMipMapCount
= 2;
8543 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8544 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8545 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &mipmap
);
8546 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
8548 priority
= 0xdeadbeef;
8549 hr
= IDirectDrawSurface7_GetPriority(mipmap
, &priority
);
8550 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type managed mipmap.\n", hr
);
8551 ok(priority
== 0xdeadbeef, "Got unexpected priority %u, type managed mipmap.\n", priority
);
8552 /* SetPriority on the mipmap surface crashes. */
8553 hr
= IDirectDrawSurface7_GetPriority(surface
, &priority
);
8554 ok(SUCCEEDED(hr
), "Failed to get priority, hr %#x.\n", hr
);
8555 ok(priority
== 0, "Got unexpected priority %u, type managed mipmap.\n", priority
);
8557 IDirectDrawSurface7_Release(mipmap
);
8558 refcount
= IDirectDrawSurface7_Release(surface
);
8559 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8562 refcount
= IDirectDraw7_Release(ddraw
);
8563 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8564 DestroyWindow(window
);
8567 static void test_surface_desc_lock(void)
8569 IDirectDrawSurface7
*surface
;
8570 DDSURFACEDESC2 surface_desc
;
8571 IDirectDraw7
*ddraw
;
8576 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8577 0, 0, 640, 480, 0, 0, 0, 0);
8578 ddraw
= create_ddraw();
8579 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8580 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8581 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8583 memset(&surface_desc
, 0, sizeof(surface_desc
));
8584 surface_desc
.dwSize
= sizeof(surface_desc
);
8585 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8586 surface_desc
.dwWidth
= 16;
8587 surface_desc
.dwHeight
= 16;
8588 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8589 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8590 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8592 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8593 surface_desc
.dwSize
= sizeof(surface_desc
);
8594 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
8595 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8596 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8598 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8599 surface_desc
.dwSize
= sizeof(surface_desc
);
8600 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
8601 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8602 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8603 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8604 surface_desc
.dwSize
= sizeof(surface_desc
);
8605 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
8606 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8607 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8608 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
8609 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8611 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8612 surface_desc
.dwSize
= sizeof(surface_desc
);
8613 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
8614 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8615 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8617 IDirectDrawSurface7_Release(surface
);
8618 refcount
= IDirectDraw7_Release(ddraw
);
8619 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8620 DestroyWindow(window
);
8623 static void test_fog_interpolation(void)
8626 IDirect3DDevice7
*device
;
8627 IDirectDrawSurface7
*rt
;
8633 struct vec3 position
;
8639 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff000000},
8640 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff000000},
8641 {{ 1.0f
, -1.0f
, 1.0f
}, 0xffff0000, 0x00000000},
8642 {{ 1.0f
, 1.0f
, 1.0f
}, 0xffff0000, 0x00000000},
8652 D3DFOGMODE vfog
, tfog
;
8654 D3DCOLOR middle_color
;
8659 {D3DFOG_NONE
, D3DFOG_NONE
, D3DSHADE_FLAT
, 0x00007f80, FALSE
},
8660 {D3DFOG_NONE
, D3DFOG_NONE
, D3DSHADE_GOURAUD
, 0x00007f80, FALSE
},
8661 {D3DFOG_EXP
, D3DFOG_NONE
, D3DSHADE_FLAT
, 0x00007f80, TRUE
},
8662 {D3DFOG_EXP
, D3DFOG_NONE
, D3DSHADE_GOURAUD
, 0x00007f80, TRUE
},
8663 {D3DFOG_NONE
, D3DFOG_EXP
, D3DSHADE_FLAT
, 0x0000ea15, FALSE
},
8664 {D3DFOG_NONE
, D3DFOG_EXP
, D3DSHADE_GOURAUD
, 0x0000ea15, FALSE
},
8665 {D3DFOG_EXP
, D3DFOG_EXP
, D3DSHADE_FLAT
, 0x0000ea15, FALSE
},
8666 {D3DFOG_EXP
, D3DFOG_EXP
, D3DSHADE_GOURAUD
, 0x0000ea15, FALSE
},
8668 D3DDEVICEDESC7 caps
;
8670 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8671 0, 0, 640, 480, 0, 0, 0, 0);
8673 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8675 skip("Failed to create a 3D device, skipping test.\n");
8676 DestroyWindow(window
);
8680 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
8681 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8682 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
8683 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8684 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
8685 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
8687 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
8688 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8689 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
8690 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8691 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
8692 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8693 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0x0000ff00);
8694 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8696 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGDENSITY
, conv
.d
);
8697 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8699 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
8700 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
8701 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
8702 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
8703 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x000000ff);
8704 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8706 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
8708 if(!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
) && tests
[i
].tfog
)
8711 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00808080, 0.0f
, 0);
8712 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
8714 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shade
);
8715 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8716 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, tests
[i
].vfog
);
8717 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8718 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, tests
[i
].tfog
);
8719 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8720 hr
= IDirect3DDevice7_BeginScene(device
);
8721 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8722 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
8723 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, quad
, 4, 0);
8724 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8725 hr
= IDirect3DDevice7_EndScene(device
);
8726 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8728 color
= get_surface_color(rt
, 0, 240);
8729 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color
, i
);
8730 color
= get_surface_color(rt
, 320, 240);
8732 todo_wine
ok(compare_color(color
, tests
[i
].middle_color
, 2),
8733 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
8735 ok(compare_color(color
, tests
[i
].middle_color
, 2),
8736 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
8737 color
= get_surface_color(rt
, 639, 240);
8738 ok(compare_color(color
, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color
, i
);
8741 IDirectDrawSurface7_Release(rt
);
8742 refcount
= IDirect3DDevice7_Release(device
);
8743 ok(!refcount
, "Device has %u references left.\n", refcount
);
8744 DestroyWindow(window
);
8747 static void test_negative_fixedfunction_fog(void)
8750 IDirect3DDevice7
*device
;
8751 IDirectDrawSurface7
*rt
;
8757 struct vec3 position
;
8762 {{-1.0f
, -1.0f
, -0.5f
}, 0xffff0000},
8763 {{-1.0f
, 1.0f
, -0.5f
}, 0xffff0000},
8764 {{ 1.0f
, -1.0f
, -0.5f
}, 0xffff0000},
8765 {{ 1.0f
, 1.0f
, -0.5f
}, 0xffff0000},
8769 struct vec4 position
;
8774 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xffff0000},
8775 {{640.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xffff0000},
8776 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xffff0000},
8777 {{640.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xffff0000},
8780 static D3DMATRIX zero
=
8782 1.0f
, 0.0f
, 0.0f
, 0.0f
,
8783 0.0f
, 1.0f
, 0.0f
, 0.0f
,
8784 0.0f
, 0.0f
, 0.0f
, 0.0f
,
8785 0.0f
, 0.0f
, 0.0f
, 1.0f
8787 static D3DMATRIX identity
=
8789 1.0f
, 0.0f
, 0.0f
, 0.0f
,
8790 0.0f
, 1.0f
, 0.0f
, 0.0f
,
8791 0.0f
, 0.0f
, 1.0f
, 0.0f
,
8792 0.0f
, 0.0f
, 0.0f
, 1.0f
8804 D3DFOGMODE vfog
, tfog
;
8805 DWORD color
, color_broken
, color_broken2
;
8809 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot.
8811 * Geforce8+ GPUs on Windows abs() table fog, everything else does not. */
8812 {D3DFVF_XYZRHW
, tquad
, &identity
, { 0.0f
}, {1.0f
}, D3DFOG_NONE
, D3DFOG_LINEAR
,
8813 0x00ff0000, 0x00808000, 0x00808000},
8814 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
8815 * parameters to 0.0 and 1.0 in the table fog case. */
8816 {D3DFVF_XYZRHW
, tquad
, &identity
, {-1.0f
}, {0.0f
}, D3DFOG_NONE
, D3DFOG_LINEAR
,
8817 0x00808000, 0x00ff0000, 0x0000ff00},
8818 /* test_fog_interpolation shows that vertex fog evaluates the fog
8819 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
8820 * that the abs happens before the fog equation is evaluated.
8822 * Vertex fog abs() behavior is the same on all GPUs. */
8823 {D3DFVF_XYZ
, quad
, &zero
, { 0.0f
}, {1.0f
}, D3DFOG_LINEAR
, D3DFOG_NONE
,
8824 0x00808000, 0x00808000, 0x00808000},
8825 {D3DFVF_XYZ
, quad
, &zero
, {-1.0f
}, {0.0f
}, D3DFOG_LINEAR
, D3DFOG_NONE
,
8826 0x0000ff00, 0x0000ff00, 0x0000ff00},
8827 {D3DFVF_XYZ
, quad
, &zero
, { 0.0f
}, {1.0f
}, D3DFOG_EXP
, D3DFOG_NONE
,
8828 0x009b6400, 0x009b6400, 0x009b6400},
8830 D3DDEVICEDESC7 caps
;
8832 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8833 0, 0, 640, 480, 0, 0, 0, 0);
8835 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8837 skip("Failed to create a 3D device, skipping test.\n");
8838 DestroyWindow(window
);
8842 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
8843 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8844 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
8845 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8846 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
8847 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
8849 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
8850 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8851 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8852 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8853 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
8854 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8855 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0x0000ff00);
8856 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8857 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
8858 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
8860 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
8862 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
) && tests
[i
].tfog
)
8865 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 0.0f
, 0);
8866 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
8868 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, tests
[i
].matrix
);
8869 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
8870 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, tests
[i
].start
.d
);
8871 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8872 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, tests
[i
].end
.d
);
8873 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8874 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, tests
[i
].vfog
);
8875 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8876 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, tests
[i
].tfog
);
8877 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8879 hr
= IDirect3DDevice7_BeginScene(device
);
8880 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8881 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
8882 tests
[i
].pos_type
| D3DFVF_DIFFUSE
, tests
[i
].quad
, 4, 0);
8883 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8884 hr
= IDirect3DDevice7_EndScene(device
);
8885 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8887 color
= get_surface_color(rt
, 0, 240);
8888 ok(compare_color(color
, tests
[i
].color
, 2) || broken(compare_color(color
, tests
[i
].color_broken
, 2))
8889 || broken(compare_color(color
, tests
[i
].color_broken2
, 2)),
8890 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
8893 IDirectDrawSurface7_Release(rt
);
8894 refcount
= IDirect3DDevice7_Release(device
);
8895 ok(!refcount
, "Device has %u references left.\n", refcount
);
8896 DestroyWindow(window
);
8899 static void test_table_fog_zw(void)
8902 IDirect3DDevice7
*device
;
8903 IDirectDrawSurface7
*rt
;
8909 struct vec4 position
;
8914 {{ 0.0f
, 0.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8915 {{640.0f
, 0.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8916 {{ 0.0f
, 480.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8917 {{640.0f
, 480.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8919 static D3DMATRIX identity
=
8921 1.0f
, 0.0f
, 0.0f
, 0.0f
,
8922 0.0f
, 1.0f
, 0.0f
, 0.0f
,
8923 0.0f
, 0.0f
, 1.0f
, 0.0f
,
8924 0.0f
, 0.0f
, 0.0f
, 1.0f
8926 D3DDEVICEDESC7 caps
;
8930 D3DZBUFFERTYPE z_test
;
8935 {0.7f
, 0.0f
, D3DZB_TRUE
, 0x004cb200},
8936 {0.7f
, 0.0f
, D3DZB_FALSE
, 0x004cb200},
8937 {0.7f
, 0.3f
, D3DZB_TRUE
, 0x004cb200},
8938 {0.7f
, 0.3f
, D3DZB_FALSE
, 0x004cb200},
8939 {0.7f
, 3.0f
, D3DZB_TRUE
, 0x004cb200},
8940 {0.7f
, 3.0f
, D3DZB_FALSE
, 0x004cb200},
8941 {0.3f
, 0.0f
, D3DZB_TRUE
, 0x00b24c00},
8942 {0.3f
, 0.0f
, D3DZB_FALSE
, 0x00b24c00},
8946 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8947 0, 0, 640, 480, 0, 0, 0, 0);
8949 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8951 skip("Failed to create a 3D device, skipping test.\n");
8952 DestroyWindow(window
);
8956 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
8957 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8958 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
8960 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping POSITIONT table fog test.\n");
8963 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
8964 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8966 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
8967 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8968 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
8969 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8970 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0x0000ff00);
8971 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8972 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
8973 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
8974 /* Work around an AMD Windows driver bug. Needs a proj matrix applied redundantly. */
8975 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &identity
);
8976 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
8977 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_LINEAR
);
8978 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8980 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
8982 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x000000ff, 1.0f
, 0);
8983 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
8985 quad
[0].position
.z
= tests
[i
].z
;
8986 quad
[1].position
.z
= tests
[i
].z
;
8987 quad
[2].position
.z
= tests
[i
].z
;
8988 quad
[3].position
.z
= tests
[i
].z
;
8989 quad
[0].position
.w
= tests
[i
].w
;
8990 quad
[1].position
.w
= tests
[i
].w
;
8991 quad
[2].position
.w
= tests
[i
].w
;
8992 quad
[3].position
.w
= tests
[i
].w
;
8993 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, tests
[i
].z_test
);
8994 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8996 hr
= IDirect3DDevice7_BeginScene(device
);
8997 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8998 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
8999 D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad
, 4, 0);
9000 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9001 hr
= IDirect3DDevice7_EndScene(device
);
9002 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9004 color
= get_surface_color(rt
, 0, 240);
9005 ok(compare_color(color
, tests
[i
].color
, 2),
9006 "Got unexpected color 0x%08x, expected 0x%8x, case %u.\n", color
, tests
[i
].color
, i
);
9009 IDirectDrawSurface7_Release(rt
);
9011 refcount
= IDirect3DDevice7_Release(device
);
9012 ok(!refcount
, "Device has %u references left.\n", refcount
);
9013 DestroyWindow(window
);
9016 static void test_signed_formats(void)
9019 IDirect3DDevice7
*device
;
9021 IDirectDraw7
*ddraw
;
9022 IDirectDrawSurface7
*surface
, *rt
;
9023 DDSURFACEDESC2 surface_desc
;
9026 D3DCOLOR color
, expected_color
;
9029 struct vec3 position
;
9030 struct vec2 texcoord
;
9034 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9035 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
9036 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9037 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
9039 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
9040 * of these values. */
9041 static const USHORT content_v8u8
[4][4] =
9043 {0x0000, 0x7f7f, 0x8880, 0x0000},
9044 {0x0080, 0x8000, 0x7f00, 0x007f},
9045 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
9046 {0x4444, 0xc0c0, 0xa066, 0x22e0},
9048 static const DWORD content_x8l8v8u8
[4][4] =
9050 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
9051 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
9052 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
9053 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
9055 static const USHORT content_l6v5u5
[4][4] =
9057 {0x0000, 0xfdef, 0x0230, 0xfc00},
9058 {0x0010, 0x0200, 0x01e0, 0x000f},
9059 {0x4067, 0x53b9, 0x0421, 0xffff},
9060 {0x8108, 0x0318, 0xc28c, 0x909c},
9065 const void *content
;
9068 unsigned int slop
, slop_broken
;
9069 DDPIXELFORMAT format
;
9074 "D3DFMT_V8U8", content_v8u8
, sizeof(WORD
), FALSE
, 1, 0,
9076 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
, 0,
9077 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
9081 "D3DFMT_X8L8V8U8", content_x8l8v8u8
, sizeof(DWORD
), TRUE
, 1, 0,
9083 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
9084 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
9088 "D3DFMT_L6V5U5", content_l6v5u5
, sizeof(WORD
), TRUE
, 4, 7,
9090 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
9091 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
9095 /* No V16U16 or Q8W8V8U8 support in ddraw. */
9097 static const D3DCOLOR expected_colors
[4][4] =
9099 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
9100 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
9101 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
9102 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
9104 unsigned int i
, width
, x
, y
;
9105 D3DDEVICEDESC7 device_desc
;
9107 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9108 0, 0, 640, 480, 0, 0, 0, 0);
9110 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9112 skip("Failed to create a 3D device, skipping test.\n");
9113 DestroyWindow(window
);
9117 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
9118 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9119 if (!(device_desc
.dwTextureOpCaps
& D3DTEXOPCAPS_BLENDFACTORALPHA
))
9121 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
9125 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
9126 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9127 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
9128 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9129 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
9130 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9132 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9133 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9135 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
9136 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x80ffffff);
9137 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9138 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BLENDFACTORALPHA
);
9139 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9140 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9141 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9142 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
9143 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9145 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
9147 for (width
= 1; width
< 5; width
+= 3)
9149 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
9150 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
9152 memset(&surface_desc
, 0, sizeof(surface_desc
));
9153 surface_desc
.dwSize
= sizeof(surface_desc
);
9154 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
9155 surface_desc
.dwWidth
= width
;
9156 surface_desc
.dwHeight
= 4;
9157 U4(surface_desc
).ddpfPixelFormat
= formats
[i
].format
;
9158 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
9159 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9162 skip("%s textures not supported, skipping.\n", formats
[i
].name
);
9165 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9166 hr
= IDirect3DDevice7_SetTexture(device
, 0, surface
);
9167 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9169 memset(&surface_desc
, 0, sizeof(surface_desc
));
9170 surface_desc
.dwSize
= sizeof(surface_desc
);
9171 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
9172 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9173 for (y
= 0; y
< 4; y
++)
9175 memcpy((char *)surface_desc
.lpSurface
+ y
* U1(surface_desc
).lPitch
,
9176 (char *)formats
[i
].content
+ y
* 4 * formats
[i
].pixel_size
,
9177 width
* formats
[i
].pixel_size
);
9179 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9180 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9182 hr
= IDirect3DDevice7_BeginScene(device
);
9183 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9184 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
9185 D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
9186 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9187 hr
= IDirect3DDevice7_EndScene(device
);
9188 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9190 for (y
= 0; y
< 4; y
++)
9192 for (x
= 0; x
< width
; x
++)
9194 expected_color
= expected_colors
[y
][x
];
9195 if (!formats
[i
].blue
)
9196 expected_color
|= 0x000000ff;
9198 color
= get_surface_color(rt
, 80 + 160 * x
, 60 + 120 * y
);
9199 ok(compare_color(color
, expected_color
, formats
[i
].slop
)
9200 || broken(compare_color(color
, expected_color
, formats
[i
].slop_broken
)),
9201 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9202 expected_color
, color
, formats
[i
].name
, x
, y
);
9206 IDirectDrawSurface7_Release(surface
);
9211 IDirectDrawSurface7_Release(rt
);
9212 IDirectDraw7_Release(ddraw
);
9213 IDirect3D7_Release(d3d
);
9216 refcount
= IDirect3DDevice7_Release(device
);
9217 ok(!refcount
, "Device has %u references left.\n", refcount
);
9218 DestroyWindow(window
);
9221 static void test_color_fill(void)
9224 IDirect3DDevice7
*device
;
9226 IDirectDraw7
*ddraw
;
9227 IDirectDrawSurface7
*surface
, *surface2
;
9228 DDSURFACEDESC2 surface_desc
;
9229 DDPIXELFORMAT z_fmt
;
9234 RECT rect
= {5, 5, 7, 7};
9236 DWORD supported_fmts
= 0, num_fourcc_codes
, *fourcc_codes
;
9241 HRESULT colorfill_hr
, depthfill_hr
;
9246 DDPIXELFORMAT format
;
9251 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9252 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9254 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9255 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9259 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9260 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9262 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9263 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9267 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9268 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
9270 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9271 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9275 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9276 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
9278 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9279 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9283 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
9284 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "managed texture RGB", 0xdeadbeef, TRUE
,
9286 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9287 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9291 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
, 0,
9292 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
9293 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9296 DDSCAPS_ZBUFFER
| DDSCAPS_SYSTEMMEMORY
, 0,
9297 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "sysmem zbuffer", 0, FALSE
,
9298 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9301 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9302 * different afterwards. DX9+ GPUs set one of the two luminance values
9303 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9304 * value they set. r200 (dx8) just sets the entire block to the clear
9306 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9307 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
9309 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9310 {0}, {0}, {0}, {0}, {0}
9314 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9315 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
9317 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9318 {0}, {0}, {0}, {0}, {0}
9322 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9323 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
9325 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9326 {0}, {0}, {0}, {0}, {0}
9330 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9331 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
9333 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9334 {0}, {0}, {0}, {0}, {0}
9338 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9339 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
9341 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9342 {0}, {0}, {0}, {0}, {0}
9346 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9347 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
9349 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9350 {0}, {0}, {0}, {0}, {0}
9354 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9355 * surface works, presumably because it is handled by the runtime instead of
9357 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9358 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
9360 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9361 {8}, {0}, {0}, {0}, {0}
9365 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9366 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
9368 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9369 {8}, {0}, {0}, {0}, {0}
9381 {SRCCOPY
, "SRCCOPY", DD_OK
},
9382 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
9383 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
9384 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
9385 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
9386 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
9387 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
9388 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
9389 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
9390 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
9391 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
9392 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
9393 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
9394 {BLACKNESS
, "BLACKNESS", DD_OK
},
9395 {WHITENESS
, "WHITENESS", DD_OK
},
9396 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
9399 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9400 0, 0, 640, 480, 0, 0, 0, 0);
9402 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9404 skip("Failed to create a 3D device, skipping test.\n");
9405 DestroyWindow(window
);
9409 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
9410 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9411 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
9412 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9414 memset(&z_fmt
, 0, sizeof(z_fmt
));
9415 IDirect3D7_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
9417 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9419 IDirect3DDevice7_EnumTextureFormats(device
, test_block_formats_creation_cb
, &supported_fmts
);
9420 if (!(supported_fmts
& SUPPORT_DXT1
))
9421 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9423 IDirect3D7_Release(d3d
);
9425 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
9426 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9427 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
9428 num_fourcc_codes
* sizeof(*fourcc_codes
));
9431 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
9432 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9433 for (i
= 0; i
< num_fourcc_codes
; i
++)
9435 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9436 supported_fmts
|= SUPPORT_YUY2
;
9437 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9438 supported_fmts
|= SUPPORT_UYVY
;
9440 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
9442 memset(&hal_caps
, 0, sizeof(hal_caps
));
9443 hal_caps
.dwSize
= sizeof(hal_caps
);
9444 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
9445 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9447 if (!(supported_fmts
& (SUPPORT_YUY2
| SUPPORT_UYVY
)) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9448 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9450 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
9452 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9453 memset(&fx
, 0, sizeof(fx
));
9454 fx
.dwSize
= sizeof(fx
);
9455 U5(fx
).dwFillColor
= 0xdeadbeef;
9457 memset(&surface_desc
, 0, sizeof(surface_desc
));
9458 surface_desc
.dwSize
= sizeof(surface_desc
);
9459 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9460 surface_desc
.dwWidth
= 64;
9461 surface_desc
.dwHeight
= 64;
9462 U4(surface_desc
).ddpfPixelFormat
= tests
[i
].format
;
9463 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
9464 surface_desc
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
9466 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('D','X','T','1') && !(supported_fmts
& SUPPORT_DXT1
))
9468 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !(supported_fmts
& SUPPORT_YUY2
))
9470 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !(supported_fmts
& SUPPORT_UYVY
))
9472 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9475 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
9480 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9483 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9484 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9486 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9487 if (tests
[i
].format
.dwFourCC
)
9488 todo_wine
ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9489 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9491 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9492 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9494 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9495 if (tests
[i
].format
.dwFourCC
)
9496 todo_wine
ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9497 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9499 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9500 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9502 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9504 memset(&surface_desc
, 0, sizeof(surface_desc
));
9505 surface_desc
.dwSize
= sizeof(surface_desc
);
9506 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9507 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9508 color
= surface_desc
.lpSurface
;
9509 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9510 *color
, tests
[i
].result
, tests
[i
].name
);
9511 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9512 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9515 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9516 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9517 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9518 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9519 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9520 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9522 U5(fx
).dwFillColor
= 0xdeadbeef;
9523 fx
.dwROP
= BLACKNESS
;
9524 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9525 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9526 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9527 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9528 U5(fx
).dwFillColor
, tests
[i
].name
);
9530 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9532 memset(&surface_desc
, 0, sizeof(surface_desc
));
9533 surface_desc
.dwSize
= sizeof(surface_desc
);
9534 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9535 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9536 color
= surface_desc
.lpSurface
;
9537 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9538 *color
, tests
[i
].name
);
9539 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9540 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9543 fx
.dwROP
= WHITENESS
;
9544 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9545 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9546 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9547 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9548 U5(fx
).dwFillColor
, tests
[i
].name
);
9550 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9552 memset(&surface_desc
, 0, sizeof(surface_desc
));
9553 surface_desc
.dwSize
= sizeof(surface_desc
);
9554 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9555 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9556 color
= surface_desc
.lpSurface
;
9557 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9558 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9559 *color
, tests
[i
].name
);
9560 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9561 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9564 IDirectDrawSurface7_Release(surface
);
9567 memset(&fx
, 0, sizeof(fx
));
9568 fx
.dwSize
= sizeof(fx
);
9569 U5(fx
).dwFillColor
= 0xdeadbeef;
9570 fx
.dwROP
= WHITENESS
;
9572 memset(&surface_desc
, 0, sizeof(surface_desc
));
9573 surface_desc
.dwSize
= sizeof(surface_desc
);
9574 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9575 surface_desc
.dwWidth
= 64;
9576 surface_desc
.dwHeight
= 64;
9577 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9578 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9579 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9580 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9581 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9582 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9583 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
9584 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9585 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9586 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9587 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9590 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
9591 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9592 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
9593 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9595 /* Unused source rectangle. */
9596 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9597 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9598 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9599 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9601 /* Unused source surface. */
9602 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9603 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9604 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9605 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9606 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9607 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9608 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9609 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9611 /* Inverted destination or source rectangle. */
9612 SetRect(&rect
, 5, 7, 7, 5);
9613 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9614 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9615 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9616 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9617 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9618 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9619 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9620 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9621 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9622 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9624 /* Negative rectangle. */
9625 SetRect(&rect
, -1, -1, 5, 5);
9626 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9627 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9628 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9629 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9630 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9631 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9632 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9633 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9634 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9635 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9637 /* Out of bounds rectangle. */
9638 SetRect(&rect
, 0, 0, 65, 65);
9639 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9640 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9641 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9642 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9644 /* Combine multiple flags. */
9645 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9646 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9647 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9648 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9649 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9650 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9652 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
9654 fx
.dwROP
= rops
[i
].rop
;
9655 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9656 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
9659 IDirectDrawSurface7_Release(surface2
);
9660 IDirectDrawSurface7_Release(surface
);
9665 memset(&surface_desc
, 0, sizeof(surface_desc
));
9666 surface_desc
.dwSize
= sizeof(surface_desc
);
9667 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9668 surface_desc
.dwWidth
= 64;
9669 surface_desc
.dwHeight
= 64;
9670 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9671 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
9672 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9673 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9674 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9675 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9678 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
9679 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9681 /* Unused source rectangle. */
9682 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9683 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9685 /* Unused source surface. */
9686 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9687 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9688 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9689 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9691 /* Inverted destination or source rectangle. */
9692 SetRect(&rect
, 5, 7, 7, 5);
9693 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9694 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9695 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9696 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9697 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9698 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9699 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9700 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9702 /* Negative rectangle. */
9703 SetRect(&rect
, -1, -1, 5, 5);
9704 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9705 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9706 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9707 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9708 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9709 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9710 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9711 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9713 /* Out of bounds rectangle. */
9714 SetRect(&rect
, 0, 0, 65, 65);
9715 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9716 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9718 /* Combine multiple flags. */
9719 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9720 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9722 IDirectDrawSurface7_Release(surface2
);
9723 IDirectDrawSurface7_Release(surface
);
9726 IDirectDraw7_Release(ddraw
);
9727 refcount
= IDirect3DDevice7_Release(device
);
9728 ok(!refcount
, "Device has %u references left.\n", refcount
);
9729 DestroyWindow(window
);
9732 static void test_texcoordindex(void)
9734 static D3DMATRIX mat
=
9736 1.0f
, 0.0f
, 0.0f
, 0.0f
,
9737 0.0f
, 0.0f
, 0.0f
, 0.0f
,
9738 0.0f
, 0.0f
, 0.0f
, 0.0f
,
9739 0.0f
, 0.0f
, 0.0f
, 0.0f
,
9744 struct vec2 texcoord1
;
9745 struct vec2 texcoord2
;
9746 struct vec2 texcoord3
;
9750 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}, {0.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9751 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}, {0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
9752 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9753 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 0.0f
}},
9755 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_TEX3
;
9756 IDirect3DDevice7
*device
;
9758 IDirectDraw7
*ddraw
;
9759 IDirectDrawSurface7
*rt
;
9762 IDirectDrawSurface7
*texture1
, *texture2
;
9763 DDSURFACEDESC2 surface_desc
;
9768 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9769 0, 0, 640, 480, 0, 0, 0, 0);
9770 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9772 skip("Failed to create a 3D device, skipping test.\n");
9773 DestroyWindow(window
);
9777 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
9778 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
9779 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
9780 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
9781 IDirect3D7_Release(d3d
);
9783 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
9784 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9786 memset(&surface_desc
, 0, sizeof(surface_desc
));
9787 surface_desc
.dwSize
= sizeof(surface_desc
);
9788 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9789 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9790 surface_desc
.dwWidth
= 2;
9791 surface_desc
.dwHeight
= 2;
9792 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9793 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
9794 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9795 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9796 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9797 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9798 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
9799 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture1
, NULL
);
9800 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9801 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture2
, NULL
);
9802 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9804 memset(&surface_desc
, 0, sizeof(surface_desc
));
9805 surface_desc
.dwSize
= sizeof(surface_desc
);
9806 hr
= IDirectDrawSurface7_Lock(texture1
, 0, &surface_desc
, 0, NULL
);
9807 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9808 ptr
= surface_desc
.lpSurface
;
9809 ptr
[0] = 0xff000000;
9810 ptr
[1] = 0xff00ff00;
9811 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9812 ptr
[0] = 0xff0000ff;
9813 ptr
[1] = 0xff00ffff;
9814 hr
= IDirectDrawSurface7_Unlock(texture1
, NULL
);
9815 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9817 memset(&surface_desc
, 0, sizeof(surface_desc
));
9818 surface_desc
.dwSize
= sizeof(surface_desc
);
9819 hr
= IDirectDrawSurface7_Lock(texture2
, 0, &surface_desc
, 0, NULL
);
9820 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9821 ptr
= surface_desc
.lpSurface
;
9822 ptr
[0] = 0xff000000;
9823 ptr
[1] = 0xff0000ff;
9824 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9825 ptr
[0] = 0xffff0000;
9826 ptr
[1] = 0xffff00ff;
9827 hr
= IDirectDrawSurface7_Unlock(texture2
, 0);
9828 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9830 hr
= IDirect3DDevice7_SetTexture(device
, 0, texture1
);
9831 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9832 hr
= IDirect3DDevice7_SetTexture(device
, 1, texture2
);
9833 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9834 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9835 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
9836 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
9837 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9838 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9839 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9840 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_ADD
);
9841 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9842 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9843 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9844 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
9845 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9846 hr
= IDirect3DDevice7_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
9847 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9849 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_TEXCOORDINDEX
, 1);
9850 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9851 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 0);
9852 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9854 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
9855 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9857 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9858 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9860 hr
= IDirect3DDevice7_BeginScene(device
);
9861 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9862 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9863 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9864 hr
= IDirect3DDevice7_EndScene(device
);
9865 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9867 color
= get_surface_color(rt
, 160, 120);
9868 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9869 color
= get_surface_color(rt
, 480, 120);
9870 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9871 color
= get_surface_color(rt
, 160, 360);
9872 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
9873 color
= get_surface_color(rt
, 480, 360);
9874 ok(compare_color(color
, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color
);
9876 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
9877 ok(SUCCEEDED(hr
), "Failed to set texture transform flags, hr %#x.\n", hr
);
9878 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_TEXTURE1
, &mat
);
9879 ok(SUCCEEDED(hr
), "Failed to set transformation matrix, hr %#x.\n", hr
);
9881 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9882 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9884 hr
= IDirect3DDevice7_BeginScene(device
);
9885 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9886 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9887 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9888 hr
= IDirect3DDevice7_EndScene(device
);
9889 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9891 color
= get_surface_color(rt
, 160, 120);
9892 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9893 color
= get_surface_color(rt
, 480, 120);
9894 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9895 color
= get_surface_color(rt
, 160, 360);
9896 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
9897 color
= get_surface_color(rt
, 480, 360);
9898 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9900 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_DISABLE
);
9901 ok(SUCCEEDED(hr
), "Failed to set texture transform flags, hr %#x.\n", hr
);
9902 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 2);
9903 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9905 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9906 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9908 hr
= IDirect3DDevice7_BeginScene(device
);
9909 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9910 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9911 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9912 hr
= IDirect3DDevice7_EndScene(device
);
9913 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9915 color
= get_surface_color(rt
, 160, 120);
9916 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9917 color
= get_surface_color(rt
, 480, 120);
9918 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9919 color
= get_surface_color(rt
, 160, 360);
9920 ok(compare_color(color
, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color
);
9921 color
= get_surface_color(rt
, 480, 360);
9922 ok(compare_color(color
, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color
);
9924 IDirectDrawSurface7_Release(texture1
);
9925 IDirectDrawSurface7_Release(texture2
);
9927 IDirectDrawSurface7_Release(rt
);
9928 IDirectDraw_Release(ddraw
);
9929 refcount
= IDirect3DDevice7_Release(device
);
9930 ok(!refcount
, "Device has %u references left.\n", refcount
);
9931 DestroyWindow(window
);
9934 static void test_colorkey_precision(void)
9939 struct vec2 texcoord
;
9943 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9944 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
9945 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9946 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
9948 IDirect3DDevice7
*device
;
9950 IDirectDraw7
*ddraw
;
9951 IDirectDrawSurface7
*rt
;
9954 IDirectDrawSurface7
*src
, *dst
, *texture
;
9955 DDSURFACEDESC2 surface_desc
, lock_desc
;
9961 DWORD data
[4] = {0}, color_mask
;
9962 D3DDEVICEDESC7 device_desc
;
9966 unsigned int max
, shift
, bpp
, clear
;
9973 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8",
9975 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9976 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
9981 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel",
9983 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9984 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9989 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel",
9991 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9992 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9997 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4",
9999 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
10000 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
10006 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10007 0, 0, 640, 480, 0, 0, 0, 0);
10008 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10010 skip("Failed to create a 3D device, skipping test.\n");
10011 DestroyWindow(window
);
10015 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
10016 * (color key doesn't match although the values are equal), and a false
10017 * positive when the color key is 0 and the texture contains the value 1.
10018 * I don't want to mark this broken unconditionally since this would
10019 * essentially disable the test on Windows. Try to detect WARP (and I
10020 * guess mismatch other SW renderers) by its ability to texture from
10021 * system memory. Also on random occasions 254 == 255 and 255 != 255.*/
10022 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
10023 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
10024 warp
= !!(device_desc
.dwDevCaps
& D3DDEVCAPS_TEXTURESYSTEMMEMORY
);
10026 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
10027 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
10028 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
10029 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
10030 IDirect3D7_Release(d3d
);
10031 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
10032 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10034 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10035 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
10036 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
10037 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
10038 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
10039 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
10040 /* Multiply the texture read result with 0, that way the result color if the key doesn't
10041 * match is constant. In theory color keying works without reading the texture result
10042 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
10044 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
10045 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
10046 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
10047 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10048 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
10049 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10050 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x00000000);
10051 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
10053 memset(&fx
, 0, sizeof(fx
));
10054 fx
.dwSize
= sizeof(fx
);
10055 memset(&lock_desc
, 0, sizeof(lock_desc
));
10056 lock_desc
.dwSize
= sizeof(lock_desc
);
10058 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
10060 memset(&surface_desc
, 0, sizeof(surface_desc
));
10061 surface_desc
.dwSize
= sizeof(surface_desc
);
10062 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10063 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10064 surface_desc
.dwWidth
= 4;
10065 surface_desc
.dwHeight
= 1;
10066 U4(surface_desc
).ddpfPixelFormat
= tests
[t
].fmt
;
10067 /* Windows XP (at least with the r200 driver, other drivers untested) produces
10068 * garbage when doing color keyed texture->texture blits. */
10069 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
10070 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10071 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
10072 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10074 fx
.dwFillColor
= tests
[t
].clear
;
10075 /* On the w8 testbot (WARP driver) the blit result has different values in the
10077 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
10078 | U3(tests
[t
].fmt
).dwGBitMask
10079 | U4(tests
[t
].fmt
).dwBBitMask
;
10081 for (c
= 0; c
<= tests
[t
].max
; ++c
)
10083 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
10084 * texture after it has been set once... */
10085 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
10086 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10087 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
10088 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
10089 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
10090 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10091 hr
= IDirect3DDevice7_SetTexture(device
, 0, texture
);
10092 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
10094 hr
= IDirectDrawSurface7_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
10095 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
10097 hr
= IDirectDrawSurface7_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
10098 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10099 switch (tests
[t
].bpp
)
10102 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
10103 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
10104 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
10105 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
10109 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
10110 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
10111 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
10112 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
10115 hr
= IDirectDrawSurface7_Unlock(src
, 0);
10116 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10117 hr
= IDirectDrawSurface7_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
10118 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10120 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
10121 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
10122 hr
= IDirectDrawSurface7_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
10123 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10125 hr
= IDirectDrawSurface7_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
10126 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10128 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
10129 hr
= IDirectDrawSurface7_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
10130 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10131 switch (tests
[t
].bpp
)
10134 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
10135 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
10136 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
10137 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
10141 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
10142 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
10143 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
10144 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
10147 hr
= IDirectDrawSurface7_Unlock(dst
, 0);
10148 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10152 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10153 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
10155 if (data
[3] == tests
[t
].clear
)
10157 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10158 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10159 * even when a different surface is used. The blit itself doesn't draw anything,
10160 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10161 * never be masked out by the key.
10163 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10164 * terrible on WARP. */
10165 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10166 IDirectDrawSurface7_Release(texture
);
10167 IDirectDrawSurface7_Release(src
);
10168 IDirectDrawSurface7_Release(dst
);
10173 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10174 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
10176 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10177 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
10179 if (c
== tests
[t
].max
)
10180 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10181 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
10183 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10184 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
10186 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 1.0f
, 0);
10187 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10189 hr
= IDirect3DDevice7_BeginScene(device
);
10190 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10191 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
10192 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10193 hr
= IDirect3DDevice7_EndScene(device
);
10194 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10196 color
= get_surface_color(rt
, 80, 240);
10198 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10199 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10200 color
, tests
[t
].name
, c
);
10202 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
10203 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10204 color
, tests
[t
].name
, c
);
10206 color
= get_surface_color(rt
, 240, 240);
10207 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10208 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10209 color
, tests
[t
].name
, c
);
10211 color
= get_surface_color(rt
, 400, 240);
10212 if (c
== tests
[t
].max
)
10213 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10214 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10215 color
, tests
[t
].name
, c
);
10217 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
10218 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10219 color
, tests
[t
].name
, c
);
10221 IDirectDrawSurface7_Release(texture
);
10223 IDirectDrawSurface7_Release(src
);
10224 IDirectDrawSurface7_Release(dst
);
10228 IDirectDrawSurface7_Release(rt
);
10229 IDirectDraw7_Release(ddraw
);
10230 refcount
= IDirect3DDevice7_Release(device
);
10231 ok(!refcount
, "Device has %u references left.\n", refcount
);
10232 DestroyWindow(window
);
10235 static void test_range_colorkey(void)
10237 IDirectDraw7
*ddraw
;
10240 IDirectDrawSurface7
*surface
;
10241 DDSURFACEDESC2 surface_desc
;
10245 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10246 0, 0, 640, 480, 0, 0, 0, 0);
10247 ddraw
= create_ddraw();
10248 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10249 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10250 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10252 memset(&surface_desc
, 0, sizeof(surface_desc
));
10253 surface_desc
.dwSize
= sizeof(surface_desc
);
10254 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
10255 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10256 surface_desc
.dwWidth
= 1;
10257 surface_desc
.dwHeight
= 1;
10258 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10259 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10260 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10261 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10262 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10263 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
10265 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10266 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10267 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10268 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10269 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10271 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10272 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10273 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10274 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10276 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10277 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10278 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10279 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10280 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10281 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10283 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10284 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10285 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10286 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10288 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10289 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10290 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10291 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10293 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10294 ckey
.dwColorSpaceLowValue
= 0x00000000;
10295 ckey
.dwColorSpaceHighValue
= 0x00000001;
10296 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10297 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10299 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10300 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10301 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10302 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10304 ckey
.dwColorSpaceLowValue
= 0x00000001;
10305 ckey
.dwColorSpaceHighValue
= 0x00000000;
10306 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10307 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10309 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10310 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10311 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10312 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10314 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10315 ckey
.dwColorSpaceLowValue
= 0x00000000;
10316 ckey
.dwColorSpaceHighValue
= 0x00000000;
10317 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10318 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10320 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10321 ckey
.dwColorSpaceLowValue
= 0x00000001;
10322 ckey
.dwColorSpaceHighValue
= 0x00000000;
10323 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10324 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10325 ckey
.dwColorSpaceLowValue
= 0x00000000;
10326 ckey
.dwColorSpaceHighValue
= 0x00000001;
10327 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10328 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10329 /* Range destination keys don't work either. */
10330 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
10331 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10333 /* Just to show it's not because of A, R, and G having equal values. */
10334 ckey
.dwColorSpaceLowValue
= 0x00000000;
10335 ckey
.dwColorSpaceHighValue
= 0x01010101;
10336 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10337 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10339 /* None of these operations modified the key. */
10340 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10341 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10342 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10343 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10345 IDirectDrawSurface7_Release(surface
),
10346 refcount
= IDirectDraw7_Release(ddraw
);
10347 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
10348 DestroyWindow(window
);
10351 static void test_shademode(void)
10353 IDirect3DVertexBuffer7
*vb_strip
, *vb_list
, *buffer
;
10354 IDirect3DDevice7
*device
;
10355 D3DVERTEXBUFFERDESC desc
;
10356 IDirectDrawSurface7
*rt
;
10357 DWORD color0
, color1
;
10364 static const struct
10366 struct vec3 position
;
10371 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10372 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10373 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10374 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10378 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10379 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10380 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10382 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10383 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10384 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10386 static const struct
10390 DWORD color0
, color1
;
10394 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
10395 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10396 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10397 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10398 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
10399 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10402 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10403 0, 0, 640, 480, 0, 0, 0, 0);
10405 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10407 skip("Failed to create a 3D device, skipping test.\n");
10408 DestroyWindow(window
);
10412 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
10413 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
10414 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
10415 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10417 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10418 ok(hr
== D3D_OK
, "Failed to disable lighting, hr %#x.\n", hr
);
10419 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10420 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10422 memset(&desc
, 0, sizeof(desc
));
10423 desc
.dwSize
= sizeof(desc
);
10424 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
10425 desc
.dwFVF
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
10426 desc
.dwNumVertices
= sizeof(quad_strip
) / sizeof(*quad_strip
);
10427 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &vb_strip
, 0);
10428 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10429 hr
= IDirect3DVertexBuffer7_Lock(vb_strip
, 0, &data
, NULL
);
10430 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10431 memcpy(data
, quad_strip
, sizeof(quad_strip
));
10432 hr
= IDirect3DVertexBuffer7_Unlock(vb_strip
);
10433 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10435 desc
.dwNumVertices
= sizeof(quad_list
) / sizeof(*quad_list
);
10436 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &vb_list
, 0);
10437 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10438 hr
= IDirect3DVertexBuffer7_Lock(vb_list
, 0, &data
, NULL
);
10439 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10440 memcpy(data
, quad_list
, sizeof(quad_list
));
10441 hr
= IDirect3DVertexBuffer7_Unlock(vb_list
);
10442 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10444 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10445 * the color fixups we have to do for FLAT shading will be dependent on that. */
10447 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
10449 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
10450 ok(hr
== D3D_OK
, "Failed to clear, hr %#x.\n", hr
);
10452 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
10453 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
10455 hr
= IDirect3DDevice7_BeginScene(device
);
10456 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10457 buffer
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? vb_strip
: vb_list
;
10458 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
10459 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, tests
[i
].primtype
, buffer
, 0, count
, 0);
10460 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10461 hr
= IDirect3DDevice7_EndScene(device
);
10462 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10464 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
10465 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
10467 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10468 * each triangle. This requires EXT_provoking_vertex or similar
10469 * functionality being available. */
10470 /* PHONG should be the same as GOURAUD, since no hardware implements
10472 ok(color0
== tests
[i
].color0
, "Test %u shading has color0 %08x, expected %08x.\n",
10473 i
, color0
, tests
[i
].color0
);
10474 ok(color1
== tests
[i
].color1
, "Test %u shading has color1 %08x, expected %08x.\n",
10475 i
, color1
, tests
[i
].color1
);
10478 IDirect3DVertexBuffer7_Release(vb_strip
);
10479 IDirect3DVertexBuffer7_Release(vb_list
);
10480 IDirectDrawSurface7_Release(rt
);
10481 IDirect3D7_Release(d3d
);
10482 refcount
= IDirect3DDevice7_Release(device
);
10483 ok(!refcount
, "Device has %u references left.\n", refcount
);
10484 DestroyWindow(window
);
10489 HMODULE module
= GetModuleHandleA("ddraw.dll");
10490 IDirectDraw7
*ddraw
;
10491 DEVMODEW current_mode
;
10493 if (!(pDirectDrawCreateEx
= (void *)GetProcAddress(module
, "DirectDrawCreateEx")))
10495 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
10499 if (!(ddraw
= create_ddraw()))
10501 skip("Failed to create a ddraw object, skipping tests.\n");
10504 IDirectDraw7_Release(ddraw
);
10506 memset(¤t_mode
, 0, sizeof(current_mode
));
10507 current_mode
.dmSize
= sizeof(current_mode
);
10508 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
10509 registry_mode
.dmSize
= sizeof(registry_mode
);
10510 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
10511 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
10512 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
10514 skip("Current mode does not match registry mode, skipping test.\n");
10518 test_process_vertices();
10519 test_coop_level_create_device_window();
10520 test_clipper_blt();
10521 test_coop_level_d3d_state();
10522 test_surface_interface_mismatch();
10523 test_coop_level_threaded();
10525 test_texture_load_ckey();
10533 test_window_style();
10534 test_redundant_mode_set();
10535 test_coop_level_mode_set();
10536 test_coop_level_mode_set_multi();
10538 test_coop_level_surf_create();
10540 test_coop_level_multi_window();
10541 test_draw_strided();
10543 test_specular_lighting();
10544 test_clear_rect_count();
10545 test_coop_level_versions();
10546 test_fog_special();
10547 test_lighting_interface_versions();
10548 test_coop_level_activateapp();
10549 test_texturemanage();
10550 test_block_formats_creation();
10551 test_unsupported_formats();
10553 test_primary_caps();
10554 test_surface_lock();
10555 test_surface_discard();
10557 test_set_surface_desc();
10558 test_user_memory_getdc();
10559 test_sysmem_overlay();
10560 test_primary_palette();
10561 test_surface_attachment();
10562 test_private_data();
10563 test_pixel_format();
10564 test_create_surface_pitch();
10565 test_mipmap_lock();
10566 test_palette_complex();
10567 test_p8_rgb_blit();
10569 test_palette_gdi();
10570 test_palette_alpha();
10571 test_vb_writeonly();
10572 test_lost_device();
10573 test_resource_priority();
10574 test_surface_desc_lock();
10575 test_fog_interpolation();
10576 test_negative_fixedfunction_fog();
10577 test_table_fog_zw();
10578 test_signed_formats();
10580 test_texcoordindex();
10581 test_colorkey_precision();
10582 test_range_colorkey();