2 * Copyright 2005 Antoine Chavasse (a.chavasse@gmail.com)
3 * Copyright 2006, 2008, 2011, 2012-2014 Stefan Dösinger for CodeWeavers
4 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
27 static HRESULT (WINAPI
*pDirectDrawCreateEx
)(GUID
*guid
, void **ddraw
, REFIID iid
, IUnknown
*outer_unknown
);
28 static BOOL is_ddraw64
= sizeof(DWORD
) != sizeof(DWORD
*);
29 static DEVMODEW registry_mode
;
31 static HRESULT (WINAPI
*pDwmIsCompositionEnabled
)(BOOL
*);
48 struct create_window_thread_param
51 HANDLE window_created
;
52 HANDLE destroy_window
;
56 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
66 if (abs(x
- y
) > ulps
)
72 static BOOL
compare_vec3(struct vec3
*vec
, float x
, float y
, float z
, unsigned int ulps
)
74 return compare_float(vec
->x
, x
, ulps
)
75 && compare_float(vec
->y
, y
, ulps
)
76 && compare_float(vec
->z
, z
, ulps
);
79 static BOOL
compare_vec4(const struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
81 return compare_float(vec
->x
, x
, ulps
)
82 && compare_float(vec
->y
, y
, ulps
)
83 && compare_float(vec
->z
, z
, ulps
)
84 && compare_float(vec
->w
, w
, ulps
);
87 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
89 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
91 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
93 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
95 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
99 static ULONG
get_refcount(IUnknown
*iface
)
101 IUnknown_AddRef(iface
);
102 return IUnknown_Release(iface
);
105 static IDirectDrawSurface7
*create_overlay(IDirectDraw7
*ddraw
,
106 unsigned int width
, unsigned int height
, DWORD format
)
108 IDirectDrawSurface7
*surface
;
111 memset(&desc
, 0, sizeof(desc
));
112 desc
.dwSize
= sizeof(desc
);
113 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
114 desc
.dwWidth
= width
;
115 desc
.dwHeight
= height
;
116 desc
.ddsCaps
.dwCaps
= DDSCAPS_OVERLAY
;
117 U4(desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(desc
).ddpfPixelFormat
);
118 U4(desc
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
119 U4(desc
).ddpfPixelFormat
.dwFourCC
= format
;
121 if (FAILED(IDirectDraw7_CreateSurface(ddraw
, &desc
, &surface
, NULL
)))
126 static DWORD WINAPI
create_window_thread_proc(void *param
)
128 struct create_window_thread_param
*p
= param
;
132 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
133 0, 0, 640, 480, 0, 0, 0, 0);
134 ret
= SetEvent(p
->window_created
);
135 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
141 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
142 DispatchMessageA(&msg
);
143 res
= WaitForSingleObject(p
->destroy_window
, 100);
144 if (res
== WAIT_OBJECT_0
)
146 if (res
!= WAIT_TIMEOUT
)
148 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
153 DestroyWindow(p
->window
);
158 static void create_window_thread(struct create_window_thread_param
*p
)
162 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
163 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
164 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
165 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
166 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
167 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
168 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
169 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
172 static void destroy_window_thread(struct create_window_thread_param
*p
)
174 SetEvent(p
->destroy_window
);
175 WaitForSingleObject(p
->thread
, INFINITE
);
176 CloseHandle(p
->destroy_window
);
177 CloseHandle(p
->window_created
);
178 CloseHandle(p
->thread
);
181 static IDirectDrawSurface7
*get_depth_stencil(IDirect3DDevice7
*device
)
183 IDirectDrawSurface7
*rt
, *ret
;
184 DDSCAPS2 caps
= {DDSCAPS_ZBUFFER
, 0, 0, {0}};
187 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
188 ok(SUCCEEDED(hr
), "Failed to get the render target, hr %#x.\n", hr
);
189 hr
= IDirectDrawSurface7_GetAttachedSurface(rt
, &caps
, &ret
);
190 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
191 IDirectDrawSurface7_Release(rt
);
195 static HRESULT
set_display_mode(IDirectDraw7
*ddraw
, DWORD width
, DWORD height
)
197 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
199 return IDirectDraw7_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
202 static D3DCOLOR
get_surface_color(IDirectDrawSurface7
*surface
, UINT x
, UINT y
)
204 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
205 DDSURFACEDESC2 surface_desc
;
209 memset(&surface_desc
, 0, sizeof(surface_desc
));
210 surface_desc
.dwSize
= sizeof(surface_desc
);
212 hr
= IDirectDrawSurface7_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
, NULL
);
213 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
217 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
219 hr
= IDirectDrawSurface7_Unlock(surface
, &rect
);
220 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
225 static HRESULT CALLBACK
enum_z_fmt(DDPIXELFORMAT
*format
, void *ctx
)
227 DDPIXELFORMAT
*z_fmt
= ctx
;
229 if (U1(*format
).dwZBufferBitDepth
> U1(*z_fmt
).dwZBufferBitDepth
)
235 static IDirectDraw7
*create_ddraw(void)
239 if (FAILED(pDirectDrawCreateEx(NULL
, (void **)&ddraw
, &IID_IDirectDraw7
, NULL
)))
245 static HRESULT WINAPI
enum_devtype_cb(char *desc_str
, char *name
, D3DDEVICEDESC7
*desc
, void *ctx
)
248 if (IsEqualGUID(&desc
->deviceGUID
, &IID_IDirect3DTnLHalDevice
))
251 return DDENUMRET_CANCEL
;
256 static IDirect3DDevice7
*create_device(HWND window
, DWORD coop_level
)
258 IDirectDrawSurface7
*surface
, *ds
;
259 IDirect3DDevice7
*device
= NULL
;
260 DDSURFACEDESC2 surface_desc
;
266 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
268 if (!(ddraw
= create_ddraw()))
271 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, coop_level
);
272 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
274 memset(&surface_desc
, 0, sizeof(surface_desc
));
275 surface_desc
.dwSize
= sizeof(surface_desc
);
276 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
277 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
278 surface_desc
.dwWidth
= 640;
279 surface_desc
.dwHeight
= 480;
281 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
282 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
284 if (coop_level
& DDSCL_NORMAL
)
286 IDirectDrawClipper
*clipper
;
288 hr
= IDirectDraw7_CreateClipper(ddraw
, 0, &clipper
, NULL
);
289 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
290 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
291 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
292 hr
= IDirectDrawSurface7_SetClipper(surface
, clipper
);
293 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
294 IDirectDrawClipper_Release(clipper
);
297 hr
= IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d7
);
298 IDirectDraw7_Release(ddraw
);
301 IDirectDrawSurface7_Release(surface
);
305 hr
= IDirect3D7_EnumDevices(d3d7
, enum_devtype_cb
, &hal_ok
);
306 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
307 if (hal_ok
) devtype
= &IID_IDirect3DTnLHalDevice
;
309 memset(&z_fmt
, 0, sizeof(z_fmt
));
310 hr
= IDirect3D7_EnumZBufferFormats(d3d7
, devtype
, enum_z_fmt
, &z_fmt
);
311 if (FAILED(hr
) || !z_fmt
.dwSize
)
313 IDirect3D7_Release(d3d7
);
314 IDirectDrawSurface7_Release(surface
);
318 memset(&surface_desc
, 0, sizeof(surface_desc
));
319 surface_desc
.dwSize
= sizeof(surface_desc
);
320 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
321 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
322 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
323 surface_desc
.dwWidth
= 640;
324 surface_desc
.dwHeight
= 480;
325 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
326 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
329 IDirect3D7_Release(d3d7
);
330 IDirectDrawSurface7_Release(surface
);
334 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
335 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
336 IDirectDrawSurface7_Release(ds
);
339 IDirect3D7_Release(d3d7
);
340 IDirectDrawSurface7_Release(surface
);
344 hr
= IDirect3D7_CreateDevice(d3d7
, devtype
, surface
, &device
);
345 IDirect3D7_Release(d3d7
);
346 IDirectDrawSurface7_Release(surface
);
357 WPARAM expect_wparam
;
360 static const struct message
*expect_messages
;
362 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
364 if (expect_messages
&& message
== expect_messages
->message
)
366 if (expect_messages
->check_wparam
)
367 ok (wparam
== expect_messages
->expect_wparam
,
368 "Got unexpected wparam %lx for message %x, expected %lx.\n",
369 wparam
, message
, expect_messages
->expect_wparam
);
374 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
377 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
378 * interface. This prevents subsequent SetCooperativeLevel() calls on a
379 * different window from failing with DDERR_HWNDALREADYSET. */
380 static void fix_wndproc(HWND window
, LONG_PTR proc
)
385 if (!(ddraw
= create_ddraw()))
388 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
389 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
390 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
391 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
392 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
394 IDirectDraw7_Release(ddraw
);
397 static void test_process_vertices(void)
399 IDirect3DVertexBuffer7
*src_vb
, *dst_vb1
, *dst_vb2
;
400 D3DVERTEXBUFFERDESC vb_desc
;
401 IDirect3DDevice7
*device
;
402 struct vec4
*dst_data
;
403 struct vec3
*dst_data2
;
404 struct vec3
*src_data
;
410 static D3DMATRIX world
=
412 0.0f
, 1.0f
, 0.0f
, 0.0f
,
413 1.0f
, 0.0f
, 0.0f
, 0.0f
,
414 0.0f
, 0.0f
, 0.0f
, 1.0f
,
415 0.0f
, 1.0f
, 1.0f
, 1.0f
,
417 static D3DMATRIX view
=
419 2.0f
, 0.0f
, 0.0f
, 0.0f
,
420 0.0f
, -1.0f
, 0.0f
, 0.0f
,
421 0.0f
, 0.0f
, 1.0f
, 0.0f
,
422 0.0f
, 0.0f
, 0.0f
, 3.0f
,
424 static D3DMATRIX proj
=
426 1.0f
, 0.0f
, 0.0f
, 1.0f
,
427 0.0f
, 1.0f
, 1.0f
, 0.0f
,
428 0.0f
, 1.0f
, 1.0f
, 0.0f
,
429 1.0f
, 0.0f
, 0.0f
, 1.0f
,
432 window
= CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW
,
433 0, 0, 640, 480, 0, 0, 0, 0);
434 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
436 skip("Failed to create a 3D device, skipping test.\n");
437 DestroyWindow(window
);
441 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d7
);
442 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
444 memset(&vb_desc
, 0, sizeof(vb_desc
));
445 vb_desc
.dwSize
= sizeof(vb_desc
);
446 vb_desc
.dwFVF
= D3DFVF_XYZ
;
447 vb_desc
.dwNumVertices
= 4;
448 hr
= IDirect3D7_CreateVertexBuffer(d3d7
, &vb_desc
, &src_vb
, 0);
449 ok(SUCCEEDED(hr
), "Failed to create source vertex buffer, hr %#x.\n", hr
);
451 hr
= IDirect3DVertexBuffer7_Lock(src_vb
, 0, (void **)&src_data
, NULL
);
452 ok(SUCCEEDED(hr
), "Failed to lock source vertex buffer, hr %#x.\n", hr
);
453 src_data
[0].x
= 0.0f
;
454 src_data
[0].y
= 0.0f
;
455 src_data
[0].z
= 0.0f
;
456 src_data
[1].x
= 1.0f
;
457 src_data
[1].y
= 1.0f
;
458 src_data
[1].z
= 1.0f
;
459 src_data
[2].x
= -1.0f
;
460 src_data
[2].y
= -1.0f
;
461 src_data
[2].z
= 0.5f
;
462 src_data
[3].x
= 0.5f
;
463 src_data
[3].y
= -0.5f
;
464 src_data
[3].z
= 0.25f
;
465 hr
= IDirect3DVertexBuffer7_Unlock(src_vb
);
466 ok(SUCCEEDED(hr
), "Failed to unlock source vertex buffer, hr %#x.\n", hr
);
468 memset(&vb_desc
, 0, sizeof(vb_desc
));
469 vb_desc
.dwSize
= sizeof(vb_desc
);
470 vb_desc
.dwFVF
= D3DFVF_XYZRHW
;
471 vb_desc
.dwNumVertices
= 4;
472 /* MSDN says that the last parameter must be 0 - check that. */
473 hr
= IDirect3D7_CreateVertexBuffer(d3d7
, &vb_desc
, &dst_vb1
, 4);
474 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
476 memset(&vb_desc
, 0, sizeof(vb_desc
));
477 vb_desc
.dwSize
= sizeof(vb_desc
);
478 vb_desc
.dwFVF
= D3DFVF_XYZ
;
479 vb_desc
.dwNumVertices
= 5;
480 /* MSDN says that the last parameter must be 0 - check that. */
481 hr
= IDirect3D7_CreateVertexBuffer(d3d7
, &vb_desc
, &dst_vb2
, 12345678);
482 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
484 memset(&vp
, 0, sizeof(vp
));
491 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
492 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
494 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb1
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
495 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
496 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb2
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
497 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
499 hr
= IDirect3DVertexBuffer7_Lock(dst_vb1
, 0, (void **)&dst_data
, NULL
);
500 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
501 ok(compare_vec4(&dst_data
[0], +1.280e+2f
, +1.280e+2f
, +0.000e+0f
, +1.000e+0f
, 4096),
502 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
503 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
504 ok(compare_vec4(&dst_data
[1], +1.920e+2f
, +6.400e+1f
, +1.000e+0f
, +1.000e+0f
, 4096),
505 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
506 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
507 ok(compare_vec4(&dst_data
[2], +6.400e+1f
, +1.920e+2f
, +5.000e-1f
, +1.000e+0f
, 4096),
508 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
509 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
510 ok(compare_vec4(&dst_data
[3], +1.600e+2f
, +1.600e+2f
, +2.500e-1f
, +1.000e+0f
, 4096),
511 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
512 dst_data
[3].x
, dst_data
[3].y
, dst_data
[3].z
, dst_data
[3].w
);
513 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb1
);
514 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
516 hr
= IDirect3DVertexBuffer7_Lock(dst_vb2
, 0, (void **)&dst_data2
, NULL
);
517 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
518 /* Small thing without much practical meaning, but I stumbled upon it,
519 * so let's check for it: If the output vertex buffer has no RHW value,
520 * the RHW value of the last vertex is written into the next vertex. */
521 ok(compare_vec3(&dst_data2
[4], +1.000e+0f
, +0.000e+0f
, +0.000e+0f
, 4096),
522 "Got unexpected vertex 4 {%.8e, %.8e, %.8e}.\n",
523 dst_data2
[4].x
, dst_data2
[4].y
, dst_data2
[4].z
);
524 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb2
);
525 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
527 /* Try a more complicated viewport, same vertices. */
528 memset(&vp
, 0, sizeof(vp
));
535 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
536 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
538 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb1
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
539 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
541 hr
= IDirect3DVertexBuffer7_Lock(dst_vb1
, 0, (void **)&dst_data
, NULL
);
542 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
543 ok(compare_vec4(&dst_data
[0], +1.330e+2f
, +7.000e+1f
, -2.000e+0f
, +1.000e+0f
, 4096),
544 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
545 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
546 ok(compare_vec4(&dst_data
[1], +2.560e+2f
, +5.000e+0f
, +4.000e+0f
, +1.000e+0f
, 4096),
547 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
548 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
549 ok(compare_vec4(&dst_data
[2], +1.000e+1f
, +1.350e+2f
, +1.000e+0f
, +1.000e+0f
, 4096),
550 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
551 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
552 ok(compare_vec4(&dst_data
[3], +1.945e+2f
, +1.025e+2f
, -5.000e-1f
, +1.000e+0f
, 4096),
553 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
554 dst_data
[3].x
, dst_data
[3].y
, dst_data
[3].z
, dst_data
[3].w
);
555 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb1
);
556 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
558 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &world
);
559 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
560 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &view
);
561 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
562 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &proj
);
563 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
565 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb1
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
566 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
568 hr
= IDirect3DVertexBuffer7_Lock(dst_vb1
, 0, (void **)&dst_data
, NULL
);
569 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
570 ok(compare_vec4(&dst_data
[0], +2.560e+2f
, +7.000e+1f
, -2.000e+0f
, +3.333e-1f
, 4096),
571 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
572 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
573 ok(compare_vec4(&dst_data
[1], +2.560e+2f
, +7.813e+1f
, -2.750e+0f
, +1.250e-1f
, 4096),
574 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
575 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
576 ok(compare_vec4(&dst_data
[2], +2.560e+2f
, +4.400e+1f
, +4.000e-1f
, +4.000e-1f
, 4096),
577 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
578 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
579 ok(compare_vec4(&dst_data
[3], +2.560e+2f
, +8.182e+1f
, -3.091e+0f
, +3.636e-1f
, 4096),
580 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
581 dst_data
[3].x
, dst_data
[3].y
, dst_data
[3].z
, dst_data
[3].w
);
582 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb1
);
583 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
585 IDirect3DVertexBuffer7_Release(dst_vb2
);
586 IDirect3DVertexBuffer7_Release(dst_vb1
);
587 IDirect3DVertexBuffer7_Release(src_vb
);
588 IDirect3D7_Release(d3d7
);
589 IDirect3DDevice7_Release(device
);
590 DestroyWindow(window
);
593 static void test_coop_level_create_device_window(void)
595 HWND focus_window
, device_window
;
599 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
600 0, 0, 640, 480, 0, 0, 0, 0);
601 ddraw
= create_ddraw();
602 ok(!!ddraw
, "Failed to create a ddraw object.\n");
604 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
605 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
606 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
607 ok(!device_window
, "Unexpected device window found.\n");
608 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
609 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
610 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
611 ok(!device_window
, "Unexpected device window found.\n");
612 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
613 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
614 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
615 ok(!device_window
, "Unexpected device window found.\n");
616 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
617 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
618 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
619 ok(!device_window
, "Unexpected device window found.\n");
620 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
621 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
622 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
623 ok(!device_window
, "Unexpected device window found.\n");
625 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
626 if (broken(hr
== DDERR_INVALIDPARAMS
))
628 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
629 IDirectDraw7_Release(ddraw
);
630 DestroyWindow(focus_window
);
634 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
635 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
636 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
637 ok(!device_window
, "Unexpected device window found.\n");
638 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
639 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
640 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
641 ok(!device_window
, "Unexpected device window found.\n");
643 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
644 ok(hr
== DD_OK
, "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
, NULL
, DDSCL_SETFOCUSWINDOW
648 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
649 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
650 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
651 ok(!!device_window
, "Device window not found.\n");
653 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
654 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
655 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
656 ok(!device_window
, "Unexpected device window found.\n");
657 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
658 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
659 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
660 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
661 ok(!!device_window
, "Device window not found.\n");
663 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
664 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
665 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
666 ok(!device_window
, "Unexpected device window found.\n");
667 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
668 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
669 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
670 ok(!device_window
, "Unexpected device window found.\n");
671 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
672 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
673 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
674 ok(!device_window
, "Unexpected device window found.\n");
675 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
676 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
677 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
678 ok(!!device_window
, "Device window not found.\n");
680 IDirectDraw7_Release(ddraw
);
681 DestroyWindow(focus_window
);
684 static void test_clipper_blt(void)
686 IDirectDrawSurface7
*src_surface
, *dst_surface
;
687 RECT client_rect
, src_rect
;
688 IDirectDrawClipper
*clipper
;
689 DDSURFACEDESC2 surface_desc
;
690 unsigned int i
, j
, x
, y
;
702 static const DWORD src_data
[] =
704 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
705 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
706 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
708 static const D3DCOLOR expected1
[] =
710 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
711 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
712 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
713 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
715 /* Nvidia on Windows seems to have an off-by-one error
716 * when processing source rectangles. Our left = 1 and
717 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
718 * read as well, but only for the edge pixels on the
719 * output image. The bug happens on the y axis as well,
720 * but we only read one row there, and all source rows
721 * contain the same data. This bug is not dependent on
722 * the presence of a clipper. */
723 static const D3DCOLOR expected1_broken
[] =
725 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
726 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
727 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
728 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
730 static const D3DCOLOR expected2
[] =
732 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
733 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
734 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
735 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
738 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
739 10, 10, 640, 480, 0, 0, 0, 0);
740 ShowWindow(window
, SW_SHOW
);
741 ddraw
= create_ddraw();
742 ok(!!ddraw
, "Failed to create a ddraw object.\n");
744 ret
= GetClientRect(window
, &client_rect
);
745 ok(ret
, "Failed to get client rect.\n");
746 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
747 ok(ret
, "Failed to map client rect.\n");
749 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
750 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
752 hr
= IDirectDraw7_CreateClipper(ddraw
, 0, &clipper
, NULL
);
753 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
754 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
755 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
756 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
757 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
758 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
759 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
760 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
761 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
762 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
763 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
764 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
765 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
766 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
767 "Got unexpected bounding rect %s, expected %s.\n",
768 wine_dbgstr_rect(&rgn_data
->rdh
.rcBound
), wine_dbgstr_rect(&client_rect
));
769 HeapFree(GetProcessHeap(), 0, rgn_data
);
771 r1
= CreateRectRgn(0, 0, 320, 240);
772 ok(!!r1
, "Failed to create region.\n");
773 r2
= CreateRectRgn(320, 240, 640, 480);
774 ok(!!r2
, "Failed to create region.\n");
775 CombineRgn(r1
, r1
, r2
, RGN_OR
);
776 ret
= GetRegionData(r1
, 0, NULL
);
777 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
778 ret
= GetRegionData(r1
, ret
, rgn_data
);
779 ok(!!ret
, "Failed to get region data.\n");
784 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
785 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
786 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
787 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
788 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
789 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
791 HeapFree(GetProcessHeap(), 0, rgn_data
);
793 memset(&surface_desc
, 0, sizeof(surface_desc
));
794 surface_desc
.dwSize
= sizeof(surface_desc
);
795 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
796 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
797 surface_desc
.dwWidth
= 640;
798 surface_desc
.dwHeight
= 480;
799 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
800 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
801 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
802 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
803 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
804 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
806 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
807 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
808 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
809 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
811 memset(&fx
, 0, sizeof(fx
));
812 fx
.dwSize
= sizeof(fx
);
813 hr
= IDirectDrawSurface7_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
814 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
815 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
816 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
818 hr
= IDirectDrawSurface7_Lock(src_surface
, NULL
, &surface_desc
, 0, NULL
);
819 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
820 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
821 ptr
= surface_desc
.lpSurface
;
822 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
823 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
824 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
825 hr
= IDirectDrawSurface7_Unlock(src_surface
, NULL
);
826 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
828 hr
= IDirectDrawSurface7_SetClipper(dst_surface
, clipper
);
829 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
831 SetRect(&src_rect
, 1, 1, 5, 2);
832 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
833 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
834 for (i
= 0; i
< 4; ++i
)
836 for (j
= 0; j
< 4; ++j
)
838 x
= 80 * ((2 * j
) + 1);
839 y
= 60 * ((2 * i
) + 1);
840 color
= get_surface_color(dst_surface
, x
, y
);
841 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
842 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
843 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
847 U5(fx
).dwFillColor
= 0xff0000ff;
848 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
849 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
850 for (i
= 0; i
< 4; ++i
)
852 for (j
= 0; j
< 4; ++j
)
854 x
= 80 * ((2 * j
) + 1);
855 y
= 60 * ((2 * i
) + 1);
856 color
= get_surface_color(dst_surface
, x
, y
);
857 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
858 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
862 hr
= IDirectDrawSurface7_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
863 ok(hr
== DDERR_BLTFASTCANTCLIP
, "Got unexpected hr %#x.\n", hr
);
865 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
866 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
867 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
868 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
869 DestroyWindow(window
);
870 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
871 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
872 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
873 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
874 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
875 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
876 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
877 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
878 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
879 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
880 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
881 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
883 IDirectDrawSurface7_Release(dst_surface
);
884 IDirectDrawSurface7_Release(src_surface
);
885 refcount
= IDirectDrawClipper_Release(clipper
);
886 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
887 IDirectDraw7_Release(ddraw
);
890 static void test_coop_level_d3d_state(void)
892 IDirectDrawSurface7
*rt
, *surface
;
893 IDirect3DDevice7
*device
;
901 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
902 0, 0, 640, 480, 0, 0, 0, 0);
903 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
905 skip("Failed to create a 3D device, skipping test.\n");
906 DestroyWindow(window
);
910 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
911 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
912 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
913 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
914 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
915 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
916 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
917 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
918 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
919 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
920 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
921 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
922 color
= get_surface_color(rt
, 320, 240);
923 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
925 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
926 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
927 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
928 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
929 IDirect3D7_Release(d3d
);
930 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
931 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
932 hr
= IDirectDrawSurface7_IsLost(rt
);
933 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
934 hr
= IDirectDraw7_RestoreAllSurfaces(ddraw
);
935 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
936 IDirectDraw7_Release(ddraw
);
938 hr
= IDirect3DDevice7_GetRenderTarget(device
, &surface
);
939 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
940 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
941 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
942 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
943 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
944 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
945 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
946 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
947 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
948 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
949 color
= get_surface_color(rt
, 320, 240);
950 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
952 IDirectDrawSurface7_Release(surface
);
953 IDirectDrawSurface7_Release(rt
);
954 IDirect3DDevice7_Release(device
);
955 DestroyWindow(window
);
958 static void test_surface_interface_mismatch(void)
960 IDirectDraw7
*ddraw
= NULL
;
961 IDirect3D7
*d3d
= NULL
;
962 IDirectDrawSurface7
*surface
= NULL
, *ds
;
963 IDirectDrawSurface3
*surface3
= NULL
;
964 IDirect3DDevice7
*device
= NULL
;
965 DDSURFACEDESC2 surface_desc
;
972 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
973 0, 0, 640, 480, 0, 0, 0, 0);
974 ddraw
= create_ddraw();
975 ok(!!ddraw
, "Failed to create a ddraw object.\n");
976 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
977 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
979 memset(&surface_desc
, 0, sizeof(surface_desc
));
980 surface_desc
.dwSize
= sizeof(surface_desc
);
981 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
982 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
983 surface_desc
.dwWidth
= 640;
984 surface_desc
.dwHeight
= 480;
986 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
987 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
989 hr
= IDirectDrawSurface7_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
990 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr
);
992 if (FAILED(IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
994 skip("D3D interface is not available, skipping test.\n");
998 memset(&z_fmt
, 0, sizeof(z_fmt
));
999 hr
= IDirect3D7_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
1000 if (FAILED(hr
) || !z_fmt
.dwSize
)
1002 skip("No depth buffer formats available, skipping test.\n");
1006 memset(&surface_desc
, 0, sizeof(surface_desc
));
1007 surface_desc
.dwSize
= sizeof(surface_desc
);
1008 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
1009 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1010 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
1011 surface_desc
.dwWidth
= 640;
1012 surface_desc
.dwHeight
= 480;
1013 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
1014 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
1018 /* Using a different surface interface version still works */
1019 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
1020 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
1021 refcount
= IDirectDrawSurface7_Release(ds
);
1022 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1027 hr
= IDirect3D7_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface7
*)surface3
, &device
);
1028 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
1032 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
1033 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1034 color
= get_surface_color(surface
, 320, 240);
1035 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
1038 if (surface3
) IDirectDrawSurface3_Release(surface3
);
1039 if (surface
) IDirectDrawSurface7_Release(surface
);
1040 if (device
) IDirect3DDevice7_Release(device
);
1041 if (d3d
) IDirect3D7_Release(d3d
);
1042 if (ddraw
) IDirectDraw7_Release(ddraw
);
1043 DestroyWindow(window
);
1046 static void test_coop_level_threaded(void)
1048 struct create_window_thread_param p
;
1049 IDirectDraw7
*ddraw
;
1052 ddraw
= create_ddraw();
1053 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1054 create_window_thread(&p
);
1056 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1057 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1059 IDirectDraw7_Release(ddraw
);
1060 destroy_window_thread(&p
);
1063 static void test_depth_blit(void)
1065 IDirect3DDevice7
*device
;
1073 { -1.0, 1.0, 0.50f
, 0xff00ff00},
1074 { 1.0, 1.0, 0.50f
, 0xff00ff00},
1075 { -1.0, -1.0, 0.50f
, 0xff00ff00},
1076 { 1.0, -1.0, 0.50f
, 0xff00ff00},
1078 static const D3DCOLOR expected_colors
[4][4] =
1080 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1081 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1082 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1083 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1085 DDSURFACEDESC2 ddsd_new
, ddsd_existing
;
1087 IDirectDrawSurface7
*ds1
, *ds2
, *ds3
, *rt
;
1088 RECT src_rect
, dst_rect
;
1093 IDirectDraw7
*ddraw
;
1097 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1098 0, 0, 640, 480, 0, 0, 0, 0);
1099 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1101 skip("Failed to create a 3D device, skipping test.\n");
1102 DestroyWindow(window
);
1106 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1107 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
1108 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1109 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
1110 IDirect3D7_Release(d3d
);
1112 ds1
= get_depth_stencil(device
);
1114 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1115 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1116 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1117 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1118 hr
= IDirectDrawSurface7_GetSurfaceDesc(ds1
, &ddsd_existing
);
1119 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
1120 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1121 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1122 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1123 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1124 U4(ddsd_new
).ddpfPixelFormat
= U4(ddsd_existing
).ddpfPixelFormat
;
1125 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1126 ok(SUCCEEDED(hr
), "Failed to create a z buffer, hr %#x.\n", hr
);
1127 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1128 ok(SUCCEEDED(hr
), "Failed to create a z buffer, hr %#x.\n", hr
);
1129 IDirectDraw7_Release(ddraw
);
1131 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1132 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1133 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1134 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1135 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
1136 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
1138 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
1139 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1142 SetRect(&src_rect
, 0, 0, 320, 240);
1143 SetRect(&dst_rect
, 0, 0, 320, 240);
1144 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1145 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1146 /* Different locations. */
1147 SetRect(&src_rect
, 0, 0, 320, 240);
1148 SetRect(&dst_rect
, 320, 240, 640, 480);
1149 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1150 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1152 SetRect(&src_rect
, 0, 0, 320, 240);
1153 SetRect(&dst_rect
, 0, 0, 640, 480);
1154 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1155 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1157 SetRect(&src_rect
, 0, 480, 640, 0);
1158 SetRect(&dst_rect
, 0, 0, 640, 480);
1159 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1160 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1161 SetRect(&src_rect
, 0, 0, 640, 480);
1162 SetRect(&dst_rect
, 0, 480, 640, 0);
1163 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1164 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1165 /* Full, explicit. */
1166 SetRect(&src_rect
, 0, 0, 640, 480);
1167 SetRect(&dst_rect
, 0, 0, 640, 480);
1168 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1169 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1170 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1172 /* Depth blit inside a BeginScene / EndScene pair */
1173 hr
= IDirect3DDevice7_BeginScene(device
);
1174 ok(SUCCEEDED(hr
), "Failed to start scene, hr %#x.\n", hr
);
1175 /* From the current depth stencil */
1176 hr
= IDirectDrawSurface7_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1177 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1178 /* To the current depth stencil */
1179 hr
= IDirectDrawSurface7_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1180 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1181 /* Between unbound surfaces */
1182 hr
= IDirectDrawSurface7_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1183 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1184 hr
= IDirect3DDevice7_EndScene(device
);
1185 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1187 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1188 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1189 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1190 * a reliable result(z = 0.0) */
1191 memset(&fx
, 0, sizeof(fx
));
1192 fx
.dwSize
= sizeof(fx
);
1193 hr
= IDirectDrawSurface7_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1194 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1196 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
, 0xffff0000, 1.0f
, 0);
1197 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1198 SetRect(&dst_rect
, 0, 0, 320, 240);
1199 hr
= IDirectDrawSurface7_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1200 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1201 IDirectDrawSurface7_Release(ds3
);
1202 IDirectDrawSurface7_Release(ds2
);
1203 IDirectDrawSurface7_Release(ds1
);
1205 hr
= IDirect3DDevice7_BeginScene(device
);
1206 ok(SUCCEEDED(hr
), "Failed to start scene, hr %#x.\n", hr
);
1207 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
1209 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1210 hr
= IDirect3DDevice7_EndScene(device
);
1211 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1213 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1214 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1215 for (i
= 0; i
< 4; ++i
)
1217 for (j
= 0; j
< 4; ++j
)
1219 unsigned int x
= 80 * ((2 * j
) + 1);
1220 unsigned int y
= 60 * ((2 * i
) + 1);
1221 color
= get_surface_color(rt
, x
, y
);
1222 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1223 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1227 IDirectDrawSurface7_Release(rt
);
1228 IDirect3DDevice7_Release(device
);
1229 DestroyWindow(window
);
1232 static void test_texture_load_ckey(void)
1235 IDirect3DDevice7
*device
;
1236 IDirectDraw7
*ddraw
;
1237 IDirectDrawSurface7
*src
;
1238 IDirectDrawSurface7
*dst
;
1239 DDSURFACEDESC2 ddsd
;
1244 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1245 0, 0, 640, 480, 0, 0, 0, 0);
1246 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1248 skip("Failed to create a 3D device, skipping test.\n");
1249 DestroyWindow(window
);
1253 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1254 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
1255 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1256 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
1257 IDirect3D7_Release(d3d
);
1259 memset(&ddsd
, 0, sizeof(ddsd
));
1260 ddsd
.dwSize
= sizeof(ddsd
);
1261 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1262 ddsd
.dwHeight
= 128;
1264 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1265 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1266 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1267 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1268 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1269 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1271 /* No surface has a color key */
1272 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1273 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1274 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1275 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1276 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1277 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1278 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1280 /* Source surface has a color key */
1281 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1282 hr
= IDirectDrawSurface7_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1283 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1284 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1285 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1286 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1287 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1288 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1289 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1291 /* Both surfaces have a color key: Dest ckey is overwritten */
1292 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1293 hr
= IDirectDrawSurface7_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1294 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1295 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1296 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1297 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1298 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1299 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1300 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1302 /* Only the destination has a color key: It is deleted. This behavior differs from
1303 * IDirect3DTexture(2)::Load */
1304 hr
= IDirectDrawSurface7_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1305 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1306 hr
= IDirectDrawSurface7_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1307 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1308 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1309 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1310 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1311 todo_wine
ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1313 IDirectDrawSurface7_Release(dst
);
1314 IDirectDrawSurface7_Release(src
);
1315 IDirectDraw7_Release(ddraw
);
1316 IDirect3DDevice7_Release(device
);
1317 DestroyWindow(window
);
1320 static void test_zenable(void)
1324 struct vec4 position
;
1329 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1330 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1331 {{640.0f
, 480.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1332 {{640.0f
, 0.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1334 IDirect3DDevice7
*device
;
1335 IDirectDrawSurface7
*rt
;
1342 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1343 0, 0, 640, 480, 0, 0, 0, 0);
1344 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1346 skip("Failed to create a 3D device, skipping test.\n");
1347 DestroyWindow(window
);
1351 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1352 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1354 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 0.0f
, 0);
1355 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1356 hr
= IDirect3DDevice7_BeginScene(device
);
1357 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1358 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, tquad
, 4, 0);
1359 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1360 hr
= IDirect3DDevice7_EndScene(device
);
1361 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1363 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1364 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1365 for (i
= 0; i
< 4; ++i
)
1367 for (j
= 0; j
< 4; ++j
)
1369 x
= 80 * ((2 * j
) + 1);
1370 y
= 60 * ((2 * i
) + 1);
1371 color
= get_surface_color(rt
, x
, y
);
1372 ok(compare_color(color
, 0x0000ff00, 1),
1373 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1376 IDirectDrawSurface7_Release(rt
);
1378 IDirect3DDevice7_Release(device
);
1379 DestroyWindow(window
);
1382 static void test_ck_rgba(void)
1386 struct vec4 position
;
1387 struct vec2 texcoord
;
1391 {{ 0.0f
, 480.0f
, 0.25f
, 1.0f
}, {0.0f
, 0.0f
}},
1392 {{ 0.0f
, 0.0f
, 0.25f
, 1.0f
}, {0.0f
, 1.0f
}},
1393 {{640.0f
, 480.0f
, 0.25f
, 1.0f
}, {1.0f
, 0.0f
}},
1394 {{640.0f
, 0.0f
, 0.25f
, 1.0f
}, {1.0f
, 1.0f
}},
1395 {{ 0.0f
, 480.0f
, 0.75f
, 1.0f
}, {0.0f
, 0.0f
}},
1396 {{ 0.0f
, 0.0f
, 0.75f
, 1.0f
}, {0.0f
, 1.0f
}},
1397 {{640.0f
, 480.0f
, 0.75f
, 1.0f
}, {1.0f
, 0.0f
}},
1398 {{640.0f
, 0.0f
, 0.75f
, 1.0f
}, {1.0f
, 1.0f
}},
1402 D3DCOLOR fill_color
;
1405 D3DCOLOR result1
, result1_broken
;
1406 D3DCOLOR result2
, result2_broken
;
1410 /* r200 on Windows doesn't check the alpha component when applying the color
1411 * key, so the key matches on every texel. */
1412 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1413 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1414 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1415 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1416 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1417 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1418 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1419 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1422 IDirectDrawSurface7
*texture
;
1423 DDSURFACEDESC2 surface_desc
;
1424 IDirect3DDevice7
*device
;
1425 IDirectDrawSurface7
*rt
;
1426 IDirectDraw7
*ddraw
;
1434 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1435 0, 0, 640, 480, 0, 0, 0, 0);
1436 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1438 skip("Failed to create a 3D device, skipping test.\n");
1439 DestroyWindow(window
);
1443 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1444 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1445 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1446 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1447 IDirect3D7_Release(d3d
);
1449 memset(&surface_desc
, 0, sizeof(surface_desc
));
1450 surface_desc
.dwSize
= sizeof(surface_desc
);
1451 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1452 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1453 surface_desc
.dwWidth
= 256;
1454 surface_desc
.dwHeight
= 256;
1455 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1456 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1457 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1458 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1459 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1460 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1461 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1462 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1463 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1464 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
1465 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1467 hr
= IDirect3DDevice7_SetTexture(device
, 0, texture
);
1468 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1469 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1470 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1471 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1472 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1474 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1475 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1477 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1479 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1480 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1481 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1482 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1484 memset(&fx
, 0, sizeof(fx
));
1485 fx
.dwSize
= sizeof(fx
);
1486 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1487 hr
= IDirectDrawSurface7_Blt(texture
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1488 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1490 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 1.0f
, 0);
1491 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1492 hr
= IDirect3DDevice7_BeginScene(device
);
1493 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1494 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1495 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1496 hr
= IDirect3DDevice7_EndScene(device
);
1497 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1499 color
= get_surface_color(rt
, 320, 240);
1500 ok(compare_color(color
, tests
[i
].result1
, 1) || compare_color(color
, tests
[i
].result1_broken
, 1),
1501 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1502 tests
[i
].result1
, i
, color
);
1504 U5(fx
).dwFillColor
= 0xff0000ff;
1505 hr
= IDirectDrawSurface7_Blt(texture
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1506 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1508 hr
= IDirect3DDevice7_BeginScene(device
);
1509 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1510 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[4], 4, 0);
1511 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1512 hr
= IDirect3DDevice7_EndScene(device
);
1513 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1515 /* This tests that fragments that are masked out by the color key are
1516 * discarded, instead of just fully transparent. */
1517 color
= get_surface_color(rt
, 320, 240);
1518 ok(compare_color(color
, tests
[i
].result2
, 1) || compare_color(color
, tests
[i
].result2_broken
, 1),
1519 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1520 tests
[i
].result2
, i
, color
);
1523 IDirectDrawSurface7_Release(rt
);
1524 IDirectDrawSurface7_Release(texture
);
1525 IDirectDraw7_Release(ddraw
);
1526 IDirect3DDevice7_Release(device
);
1527 DestroyWindow(window
);
1530 static void test_ck_default(void)
1534 struct vec4 position
;
1535 struct vec2 texcoord
;
1539 {{ 0.0f
, 480.0f
, 0.0f
, 1.0f
}, {0.0f
, 0.0f
}},
1540 {{ 0.0f
, 0.0f
, 0.0f
, 1.0f
}, {0.0f
, 1.0f
}},
1541 {{640.0f
, 480.0f
, 0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
1542 {{640.0f
, 0.0f
, 0.0f
, 1.0f
}, {1.0f
, 1.0f
}},
1544 IDirectDrawSurface7
*surface
, *rt
;
1545 DDSURFACEDESC2 surface_desc
;
1546 IDirect3DDevice7
*device
;
1547 IDirectDraw7
*ddraw
;
1555 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1556 0, 0, 640, 480, 0, 0, 0, 0);
1558 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1560 skip("Failed to create a 3D device, skipping test.\n");
1561 DestroyWindow(window
);
1565 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1566 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1567 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1568 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1569 IDirect3D7_Release(d3d
);
1571 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1572 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1574 memset(&surface_desc
, 0, sizeof(surface_desc
));
1575 surface_desc
.dwSize
= sizeof(surface_desc
);
1576 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1577 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1578 surface_desc
.dwWidth
= 256;
1579 surface_desc
.dwHeight
= 256;
1580 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1581 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1582 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1583 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1584 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1585 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1586 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1587 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1588 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1589 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1590 hr
= IDirect3DDevice7_SetTexture(device
, 0, surface
);
1591 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1593 memset(&fx
, 0, sizeof(fx
));
1594 fx
.dwSize
= sizeof(fx
);
1595 U5(fx
).dwFillColor
= 0x000000ff;
1596 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1597 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1599 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1600 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1601 hr
= IDirect3DDevice7_BeginScene(device
);
1602 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1603 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1604 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1605 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1606 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1607 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1608 hr
= IDirect3DDevice7_EndScene(device
);
1609 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1610 color
= get_surface_color(rt
, 320, 240);
1611 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1613 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1614 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1615 hr
= IDirect3DDevice7_BeginScene(device
);
1616 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1617 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1618 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1619 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1620 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1621 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1622 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1623 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1624 hr
= IDirect3DDevice7_EndScene(device
);
1625 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1626 color
= get_surface_color(rt
, 320, 240);
1627 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1629 IDirectDrawSurface7_Release(surface
);
1630 IDirectDrawSurface7_Release(rt
);
1631 IDirect3DDevice7_Release(device
);
1632 IDirectDraw7_Release(ddraw
);
1633 DestroyWindow(window
);
1636 static void test_ck_complex(void)
1638 IDirectDrawSurface7
*surface
, *mipmap
, *tmp
;
1639 D3DDEVICEDESC7 device_desc
;
1640 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
1641 DDSURFACEDESC2 surface_desc
;
1642 IDirect3DDevice7
*device
;
1643 DDCOLORKEY color_key
;
1644 IDirectDraw7
*ddraw
;
1651 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1652 0, 0, 640, 480, 0, 0, 0, 0);
1653 if (!(device
= create_device(window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1655 skip("Failed to create a 3D device, skipping test.\n");
1656 DestroyWindow(window
);
1659 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
1660 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
1661 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1662 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1663 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1664 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1665 IDirect3D7_Release(d3d
);
1667 memset(&surface_desc
, 0, sizeof(surface_desc
));
1668 surface_desc
.dwSize
= sizeof(surface_desc
);
1669 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1670 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1671 surface_desc
.dwWidth
= 128;
1672 surface_desc
.dwHeight
= 128;
1673 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1674 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1676 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1677 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1678 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1679 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1680 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1681 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1682 memset(&color_key
, 0, sizeof(color_key
));
1683 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1684 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1685 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1686 color_key
.dwColorSpaceLowValue
);
1687 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1688 color_key
.dwColorSpaceHighValue
);
1691 IDirectDrawSurface_AddRef(mipmap
);
1692 for (i
= 0; i
< 7; ++i
)
1694 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1695 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1696 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1697 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1699 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1700 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1701 hr
= IDirectDrawSurface7_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1702 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1704 IDirectDrawSurface_Release(mipmap
);
1708 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1709 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1710 IDirectDrawSurface_Release(mipmap
);
1711 refcount
= IDirectDrawSurface7_Release(surface
);
1712 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1714 memset(&surface_desc
, 0, sizeof(surface_desc
));
1715 surface_desc
.dwSize
= sizeof(surface_desc
);
1716 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1717 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1718 U5(surface_desc
).dwBackBufferCount
= 1;
1719 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1720 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1722 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1723 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1724 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1725 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1726 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1727 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1728 memset(&color_key
, 0, sizeof(color_key
));
1729 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1730 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1731 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1732 color_key
.dwColorSpaceLowValue
);
1733 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1734 color_key
.dwColorSpaceHighValue
);
1736 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &tmp
);
1737 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
1739 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1740 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1741 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1742 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1743 hr
= IDirectDrawSurface7_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1744 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1745 memset(&color_key
, 0, sizeof(color_key
));
1746 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1747 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1748 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1749 color_key
.dwColorSpaceLowValue
);
1750 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1751 color_key
.dwColorSpaceHighValue
);
1753 IDirectDrawSurface_Release(tmp
);
1755 refcount
= IDirectDrawSurface7_Release(surface
);
1756 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1758 if (!(device_desc
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
1760 skip("Device does not support cubemaps.\n");
1763 memset(&surface_desc
, 0, sizeof(surface_desc
));
1764 surface_desc
.dwSize
= sizeof(surface_desc
);
1765 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1766 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1767 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
;
1768 surface_desc
.dwWidth
= 128;
1769 surface_desc
.dwHeight
= 128;
1770 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1771 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1773 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1774 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1775 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1776 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1777 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1778 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1780 caps
.dwCaps2
= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
1781 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &mipmap
);
1782 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1784 hr
= IDirectDrawSurface7_GetColorKey(mipmap
, DDCKEY_SRCBLT
, &color_key
);
1785 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1786 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1787 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1788 hr
= IDirectDrawSurface7_SetColorKey(mipmap
, DDCKEY_SRCBLT
, &color_key
);
1789 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1791 color_key
.dwColorSpaceLowValue
= 0;
1792 color_key
.dwColorSpaceHighValue
= 0;
1793 hr
= IDirectDrawSurface7_GetColorKey(mipmap
, DDCKEY_SRCBLT
, &color_key
);
1794 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1795 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x.\n",
1796 color_key
.dwColorSpaceLowValue
);
1797 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x.\n",
1798 color_key
.dwColorSpaceHighValue
);
1800 IDirectDrawSurface_AddRef(mipmap
);
1801 for (i
= 0; i
< 7; ++i
)
1803 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1804 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1805 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1806 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1808 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1809 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1810 hr
= IDirectDrawSurface7_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1811 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1813 IDirectDrawSurface_Release(mipmap
);
1817 IDirectDrawSurface7_Release(mipmap
);
1819 refcount
= IDirectDrawSurface7_Release(surface
);
1820 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1823 IDirectDraw7_Release(ddraw
);
1824 refcount
= IDirect3DDevice7_Release(device
);
1825 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1826 DestroyWindow(window
);
1832 REFIID refcount_iid
;
1836 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
1837 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
1839 ULONG refcount
, expected_refcount
;
1840 IUnknown
*iface1
, *iface2
;
1844 for (i
= 0; i
< entry_count
; ++i
)
1846 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
1847 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
1850 for (j
= 0; j
< entry_count
; ++j
)
1852 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
1853 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
1856 expected_refcount
= 0;
1857 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
1858 ++expected_refcount
;
1859 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
1860 ++expected_refcount
;
1861 refcount
= IUnknown_Release(iface2
);
1862 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1863 refcount
, test_name
, i
, j
, expected_refcount
);
1867 expected_refcount
= 0;
1868 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
1869 ++expected_refcount
;
1870 refcount
= IUnknown_Release(iface1
);
1871 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1872 refcount
, test_name
, i
, expected_refcount
);
1877 static void test_surface_qi(void)
1879 static const struct qi_test tests
[] =
1881 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
1882 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
1883 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1884 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1885 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1886 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1887 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1888 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1889 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1890 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
1891 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
1892 {&IID_IDirect3DDevice2
, NULL
, E_NOINTERFACE
},
1893 {&IID_IDirect3DDevice
, NULL
, E_NOINTERFACE
},
1894 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
1895 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
1896 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
1897 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
1898 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
1899 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
1900 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
1901 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
1902 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
1903 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
1904 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
1905 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
1906 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
1907 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
1908 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
1909 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
1910 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
1911 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
1912 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
1913 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
1914 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
1915 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
1916 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
1917 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
1918 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
1919 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
1920 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
1921 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
1922 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1925 IDirectDrawSurface7
*surface
;
1926 DDSURFACEDESC2 surface_desc
;
1927 IDirect3DDevice7
*device
;
1928 IDirectDraw7
*ddraw
;
1932 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1933 0, 0, 640, 480, 0, 0, 0, 0);
1934 /* Try to create a D3D device to see if the ddraw implementation supports
1935 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1936 * doesn't support e.g. the IDirect3DTexture interfaces. */
1937 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1939 skip("Failed to create a 3D device, skipping test.\n");
1940 DestroyWindow(window
);
1943 IDirect3DDevice_Release(device
);
1944 ddraw
= create_ddraw();
1945 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1946 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
1947 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1949 memset(&surface_desc
, 0, sizeof(surface_desc
));
1950 surface_desc
.dwSize
= sizeof(surface_desc
);
1951 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1952 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1953 surface_desc
.dwWidth
= 512;
1954 surface_desc
.dwHeight
= 512;
1955 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1956 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1958 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface7
, tests
, sizeof(tests
) / sizeof(*tests
));
1960 IDirectDrawSurface7_Release(surface
);
1961 IDirectDraw7_Release(ddraw
);
1962 DestroyWindow(window
);
1965 static void test_device_qi(void)
1967 static const struct qi_test tests
[] =
1969 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
1970 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
1971 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
1972 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1973 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
1974 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
1975 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
1976 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
1977 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
1978 {&IID_IDirect3DDevice7
, &IID_IDirect3DDevice7
, S_OK
},
1979 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
1980 {&IID_IDirect3DDevice2
, NULL
, E_NOINTERFACE
},
1981 {&IID_IDirect3DDevice
, NULL
, E_NOINTERFACE
},
1982 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
1983 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
1984 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
1985 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
1986 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
1987 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
1988 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
1989 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
1990 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
1991 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
1992 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
1993 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
1994 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
1995 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
1996 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
1997 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
1998 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
1999 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
2000 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
2001 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
2002 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
2003 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
2004 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
2005 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
2006 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
2007 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
2008 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
2009 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
2010 {&IID_IUnknown
, &IID_IDirect3DDevice7
, S_OK
},
2013 IDirect3DDevice7
*device
;
2016 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2017 0, 0, 640, 480, 0, 0, 0, 0);
2018 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
2020 skip("Failed to create a 3D device, skipping test.\n");
2021 DestroyWindow(window
);
2025 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice7
, tests
, sizeof(tests
) / sizeof(*tests
));
2027 IDirect3DDevice7_Release(device
);
2028 DestroyWindow(window
);
2031 static void test_wndproc(void)
2033 LONG_PTR proc
, ddraw_proc
;
2034 IDirectDraw7
*ddraw
;
2040 static struct message messages
[] =
2042 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2043 {WM_MOVE
, FALSE
, 0},
2044 {WM_SIZE
, FALSE
, 0},
2045 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2046 {WM_ACTIVATE
, FALSE
, 0},
2047 {WM_SETFOCUS
, FALSE
, 0},
2051 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2052 ddraw
= create_ddraw();
2053 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2055 wc
.lpfnWndProc
= test_proc
;
2056 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2057 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2059 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2060 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2062 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2063 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2064 (LONG_PTR
)test_proc
, proc
);
2065 expect_messages
= messages
;
2066 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2067 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2068 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2069 expect_messages
= NULL
;
2070 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2071 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2072 (LONG_PTR
)test_proc
, proc
);
2073 ref
= IDirectDraw7_Release(ddraw
);
2074 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2075 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2076 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2077 (LONG_PTR
)test_proc
, proc
);
2079 /* DDSCL_NORMAL doesn't. */
2080 ddraw
= create_ddraw();
2081 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2082 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2083 (LONG_PTR
)test_proc
, proc
);
2084 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2085 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2086 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2087 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2088 (LONG_PTR
)test_proc
, proc
);
2089 ref
= IDirectDraw7_Release(ddraw
);
2090 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2091 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2092 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2093 (LONG_PTR
)test_proc
, proc
);
2095 /* The original window proc is only restored by ddraw if the current
2096 * window proc matches the one ddraw set. This also affects switching
2097 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2098 ddraw
= create_ddraw();
2099 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2100 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2101 (LONG_PTR
)test_proc
, proc
);
2102 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2103 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2104 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2105 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2106 (LONG_PTR
)test_proc
, proc
);
2108 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2109 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2110 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2111 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2112 (LONG_PTR
)test_proc
, proc
);
2113 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2114 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2115 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2116 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2117 (LONG_PTR
)test_proc
, proc
);
2118 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2119 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2120 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2121 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2122 (LONG_PTR
)DefWindowProcA
, proc
);
2123 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2124 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2125 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2126 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2127 (LONG_PTR
)DefWindowProcA
, proc
);
2128 ref
= IDirectDraw7_Release(ddraw
);
2129 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2130 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2131 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2132 (LONG_PTR
)test_proc
, proc
);
2134 ddraw
= create_ddraw();
2135 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2136 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2137 (LONG_PTR
)test_proc
, proc
);
2138 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2139 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2140 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2141 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2142 (LONG_PTR
)test_proc
, proc
);
2143 ref
= IDirectDraw7_Release(ddraw
);
2144 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2145 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2146 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2147 (LONG_PTR
)DefWindowProcA
, proc
);
2149 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2150 expect_messages
= NULL
;
2151 DestroyWindow(window
);
2152 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2155 static void test_window_style(void)
2157 LONG style
, exstyle
, tmp
, expected_style
;
2158 RECT fullscreen_rect
, r
;
2159 IDirectDraw7
*ddraw
;
2165 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2166 0, 0, 100, 100, 0, 0, 0, 0);
2167 ddraw
= create_ddraw();
2168 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2170 style
= GetWindowLongA(window
, GWL_STYLE
);
2171 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2172 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2174 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2175 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2177 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2178 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2179 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2180 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2182 GetWindowRect(window
, &r
);
2183 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
2184 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
2185 GetClientRect(window
, &r
);
2186 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2188 ret
= SetForegroundWindow(GetDesktopWindow());
2189 ok(ret
, "Failed to set foreground window.\n");
2191 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2192 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2193 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2194 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2196 ret
= SetForegroundWindow(window
);
2197 ok(ret
, "Failed to set foreground window.\n");
2198 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2199 * the next tests expect this. */
2200 ShowWindow(window
, SW_HIDE
);
2202 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2203 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2205 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2206 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2207 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2208 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2210 ShowWindow(window
, SW_SHOW
);
2211 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2212 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2214 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2215 expected_style
= style
| WS_VISIBLE
;
2216 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2217 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2218 expected_style
= exstyle
| WS_EX_TOPMOST
;
2219 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2221 ret
= SetForegroundWindow(GetDesktopWindow());
2222 ok(ret
, "Failed to set foreground window.\n");
2223 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2224 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2225 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2226 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2227 expected_style
= exstyle
| WS_EX_TOPMOST
;
2228 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2230 ref
= IDirectDraw7_Release(ddraw
);
2231 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2233 DestroyWindow(window
);
2236 static void test_redundant_mode_set(void)
2238 DDSURFACEDESC2 surface_desc
= {0};
2239 IDirectDraw7
*ddraw
;
2245 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2246 0, 0, 100, 100, 0, 0, 0, 0);
2247 ddraw
= create_ddraw();
2248 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2249 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2250 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2252 surface_desc
.dwSize
= sizeof(surface_desc
);
2253 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &surface_desc
);
2254 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
2256 hr
= IDirectDraw7_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2257 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2258 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2260 GetWindowRect(window
, &r
);
2263 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2264 GetWindowRect(window
, &s
);
2265 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2267 hr
= IDirectDraw7_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2268 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2269 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2271 GetWindowRect(window
, &s
);
2272 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2274 ref
= IDirectDraw7_Release(ddraw
);
2275 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2277 DestroyWindow(window
);
2280 static SIZE screen_size
, screen_size2
;
2282 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2284 if (message
== WM_SIZE
)
2286 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2287 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2290 return test_proc(hwnd
, message
, wparam
, lparam
);
2293 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2295 if (message
== WM_SIZE
)
2297 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2298 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2301 return test_proc(hwnd
, message
, wparam
, lparam
);
2304 struct test_coop_level_mode_set_enum_param
2306 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2309 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC2
*surface_desc
, void *context
)
2311 struct test_coop_level_mode_set_enum_param
*param
= context
;
2313 if (U1(U4(*surface_desc
).ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2314 return DDENUMRET_OK
;
2315 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2316 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2317 return DDENUMRET_OK
;
2319 if (!param
->ddraw_width
)
2321 param
->ddraw_width
= surface_desc
->dwWidth
;
2322 param
->ddraw_height
= surface_desc
->dwHeight
;
2323 return DDENUMRET_OK
;
2325 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2326 return DDENUMRET_OK
;
2328 param
->user32_width
= surface_desc
->dwWidth
;
2329 param
->user32_height
= surface_desc
->dwHeight
;
2330 return DDENUMRET_CANCEL
;
2333 static void test_coop_level_mode_set(void)
2335 IDirectDrawSurface7
*primary
;
2336 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2337 IDirectDraw7
*ddraw
;
2338 DDSURFACEDESC2 ddsd
;
2340 HWND window
, window2
;
2344 struct test_coop_level_mode_set_enum_param param
;
2349 static const struct message exclusive_messages
[] =
2351 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2352 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2353 {WM_SIZE
, FALSE
, 0},
2354 {WM_DISPLAYCHANGE
, FALSE
, 0},
2357 static const struct message exclusive_focus_loss_messages
[] =
2359 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2360 {WM_DISPLAYCHANGE
, FALSE
, 0},
2361 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2362 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2363 * SW_MINIMIZED, causing a recursive window activation that does not
2364 * produce the same result in Wine yet. Ignore the difference for now.
2365 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2366 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2367 {WM_MOVE
, FALSE
, 0},
2368 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2369 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2372 static const struct message exclusive_focus_restore_messages
[] =
2374 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2375 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2376 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2377 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2378 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2379 /* Native redundantly sets the window size here. */
2380 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2381 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2382 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2383 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2386 static const struct message sc_restore_messages
[] =
2388 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2389 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2390 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2391 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2394 static const struct message sc_minimize_messages
[] =
2396 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2397 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2398 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2399 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2402 static const struct message sc_maximize_messages
[] =
2404 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2405 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2406 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2407 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2411 static const struct message normal_messages
[] =
2413 {WM_DISPLAYCHANGE
, FALSE
, 0},
2417 ddraw
= create_ddraw();
2418 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2420 memset(¶m
, 0, sizeof(param
));
2421 hr
= IDirectDraw7_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2422 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2423 ref
= IDirectDraw7_Release(ddraw
);
2424 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2426 if (!param
.user32_height
)
2428 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2432 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2433 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2434 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2436 memset(&devmode
, 0, sizeof(devmode
));
2437 devmode
.dmSize
= sizeof(devmode
);
2438 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2439 devmode
.dmPelsWidth
= param
.user32_width
;
2440 devmode
.dmPelsHeight
= param
.user32_height
;
2441 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2442 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2444 ddraw
= create_ddraw();
2445 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2447 wc
.lpfnWndProc
= mode_set_proc
;
2448 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2449 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2450 wc
.lpfnWndProc
= mode_set_proc2
;
2451 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2452 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2454 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2455 0, 0, 100, 100, 0, 0, 0, 0);
2456 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2457 0, 0, 100, 100, 0, 0, 0, 0);
2459 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2460 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2462 GetWindowRect(window
, &r
);
2463 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2464 wine_dbgstr_rect(&r
));
2466 memset(&ddsd
, 0, sizeof(ddsd
));
2467 ddsd
.dwSize
= sizeof(ddsd
);
2468 ddsd
.dwFlags
= DDSD_CAPS
;
2469 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2471 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2472 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2473 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2474 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2475 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2476 param
.user32_width
, ddsd
.dwWidth
);
2477 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2478 param
.user32_height
, ddsd
.dwHeight
);
2480 GetWindowRect(window
, &r
);
2481 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2482 wine_dbgstr_rect(&r
));
2484 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2485 expect_messages
= exclusive_messages
;
2489 hr
= IDirectDrawSurface7_IsLost(primary
);
2490 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2491 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2492 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2493 hr
= IDirectDrawSurface7_IsLost(primary
);
2494 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2496 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2497 expect_messages
= NULL
;
2498 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2499 "Expected screen size %ux%u, got %ux%u.\n",
2500 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2502 GetWindowRect(window
, &r
);
2503 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2504 wine_dbgstr_rect(&r
));
2506 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2507 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2508 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2509 param
.user32_width
, ddsd
.dwWidth
);
2510 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2511 param
.user32_height
, ddsd
.dwHeight
);
2512 IDirectDrawSurface7_Release(primary
);
2514 memset(&ddsd
, 0, sizeof(ddsd
));
2515 ddsd
.dwSize
= sizeof(ddsd
);
2516 ddsd
.dwFlags
= DDSD_CAPS
;
2517 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2519 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2520 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2521 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2522 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2523 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2524 param
.ddraw_width
, ddsd
.dwWidth
);
2525 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2526 param
.ddraw_height
, ddsd
.dwHeight
);
2528 GetWindowRect(window
, &r
);
2529 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2530 wine_dbgstr_rect(&r
));
2532 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2533 expect_messages
= exclusive_messages
;
2537 hr
= IDirectDrawSurface7_IsLost(primary
);
2538 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2539 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2540 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2541 hr
= IDirectDrawSurface7_IsLost(primary
);
2542 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2544 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2545 expect_messages
= NULL
;
2546 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2547 "Expected screen size %ux%u, got %ux%u.\n",
2548 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2550 GetWindowRect(window
, &r
);
2551 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2552 wine_dbgstr_rect(&r
));
2554 expect_messages
= exclusive_focus_loss_messages
;
2555 ret
= SetForegroundWindow(GetDesktopWindow());
2556 ok(ret
, "Failed to set foreground window.\n");
2557 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2558 memset(&devmode
, 0, sizeof(devmode
));
2559 devmode
.dmSize
= sizeof(devmode
);
2560 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2561 ok(ret
, "Failed to get display mode.\n");
2562 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2563 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2564 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2566 expect_messages
= exclusive_focus_restore_messages
;
2567 ShowWindow(window
, SW_RESTORE
);
2568 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2570 GetWindowRect(window
, &r
);
2571 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2572 wine_dbgstr_rect(&r
));
2573 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2574 ok(ret
, "Failed to get display mode.\n");
2575 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2576 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2577 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2579 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2580 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2581 /* Normally the primary should be restored here. Unfortunately this causes the
2582 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2583 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2584 * the point of the GetSurfaceDesc call. */
2586 expect_messages
= sc_minimize_messages
;
2587 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2588 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2589 expect_messages
= NULL
;
2591 expect_messages
= sc_restore_messages
;
2592 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2593 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2594 expect_messages
= NULL
;
2596 expect_messages
= sc_maximize_messages
;
2597 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2598 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2599 expect_messages
= NULL
;
2601 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2602 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2604 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2605 expect_messages
= exclusive_messages
;
2609 hr
= IDirectDrawSurface7_IsLost(primary
);
2610 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2611 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
2612 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2613 hr
= IDirectDrawSurface7_IsLost(primary
);
2614 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2616 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2617 expect_messages
= NULL
;
2618 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2619 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2620 "Expected screen size %ux%u, got %ux%u.\n",
2621 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2623 GetWindowRect(window
, &r
);
2624 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2625 wine_dbgstr_rect(&r
));
2627 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2628 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2629 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2630 param
.ddraw_width
, ddsd
.dwWidth
);
2631 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2632 param
.ddraw_height
, ddsd
.dwHeight
);
2633 IDirectDrawSurface7_Release(primary
);
2636 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2637 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2639 memset(&ddsd
, 0, sizeof(ddsd
));
2640 ddsd
.dwSize
= sizeof(ddsd
);
2641 ddsd
.dwFlags
= DDSD_CAPS
;
2642 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2644 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2645 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2646 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2647 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2648 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2649 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2650 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2651 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2653 GetWindowRect(window
, &r
);
2654 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2655 wine_dbgstr_rect(&r
));
2657 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2658 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2660 GetWindowRect(window
, &r
);
2661 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2662 wine_dbgstr_rect(&r
));
2664 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2665 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2666 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2667 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2668 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2669 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2670 IDirectDrawSurface7_Release(primary
);
2672 memset(&ddsd
, 0, sizeof(ddsd
));
2673 ddsd
.dwSize
= sizeof(ddsd
);
2674 ddsd
.dwFlags
= DDSD_CAPS
;
2675 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2677 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2678 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2679 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2680 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2681 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2682 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2683 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2684 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2686 GetWindowRect(window
, &r
);
2687 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2688 wine_dbgstr_rect(&r
));
2690 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2691 expect_messages
= normal_messages
;
2695 hr
= IDirectDrawSurface7_IsLost(primary
);
2696 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2697 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2698 devmode
.dmPelsWidth
= param
.user32_width
;
2699 devmode
.dmPelsHeight
= param
.user32_height
;
2700 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2701 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2702 hr
= IDirectDrawSurface7_IsLost(primary
);
2703 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2705 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2706 expect_messages
= NULL
;
2707 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2709 GetWindowRect(window
, &r
);
2710 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2711 wine_dbgstr_rect(&r
));
2713 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2714 expect_messages
= normal_messages
;
2718 hr
= IDirectDrawSurface7_Restore(primary
);
2719 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2720 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2721 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2722 hr
= IDirectDrawSurface7_Restore(primary
);
2723 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2724 hr
= IDirectDrawSurface7_IsLost(primary
);
2725 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2727 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2728 expect_messages
= NULL
;
2729 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2731 GetWindowRect(window
, &r
);
2732 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2733 wine_dbgstr_rect(&r
));
2735 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2736 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2737 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2738 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2739 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2740 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2741 IDirectDrawSurface7_Release(primary
);
2743 memset(&ddsd
, 0, sizeof(ddsd
));
2744 ddsd
.dwSize
= sizeof(ddsd
);
2745 ddsd
.dwFlags
= DDSD_CAPS
;
2746 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2748 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2749 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2750 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2751 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2752 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2753 param
.ddraw_width
, ddsd
.dwWidth
);
2754 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2755 param
.ddraw_height
, ddsd
.dwHeight
);
2757 GetWindowRect(window
, &r
);
2758 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2759 wine_dbgstr_rect(&r
));
2761 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2762 expect_messages
= normal_messages
;
2766 hr
= IDirectDrawSurface7_IsLost(primary
);
2767 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2768 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
2769 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2770 hr
= IDirectDrawSurface7_IsLost(primary
);
2771 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2773 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2774 expect_messages
= NULL
;
2775 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2777 GetWindowRect(window
, &r
);
2778 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2779 wine_dbgstr_rect(&r
));
2781 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2782 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2783 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2784 param
.ddraw_width
, ddsd
.dwWidth
);
2785 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2786 param
.ddraw_height
, ddsd
.dwHeight
);
2787 IDirectDrawSurface7_Release(primary
);
2789 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2790 ok(ret
, "Failed to get display mode.\n");
2791 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2792 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2793 "Expected resolution %ux%u, got %ux%u.\n",
2794 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2795 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2796 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2797 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2799 memset(&ddsd
, 0, sizeof(ddsd
));
2800 ddsd
.dwSize
= sizeof(ddsd
);
2801 ddsd
.dwFlags
= DDSD_CAPS
;
2802 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2804 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2805 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2806 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2807 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2808 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2809 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2810 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2811 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2813 GetWindowRect(window
, &r
);
2814 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2815 wine_dbgstr_rect(&r
));
2817 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2818 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2819 * not DDSCL_FULLSCREEN. */
2820 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2821 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2823 GetWindowRect(window
, &r
);
2824 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2825 wine_dbgstr_rect(&r
));
2827 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2828 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2829 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2830 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2831 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2832 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2833 IDirectDrawSurface7_Release(primary
);
2835 memset(&ddsd
, 0, sizeof(ddsd
));
2836 ddsd
.dwSize
= sizeof(ddsd
);
2837 ddsd
.dwFlags
= DDSD_CAPS
;
2838 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2840 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2841 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2842 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2843 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2844 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2845 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2846 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2847 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2849 GetWindowRect(window
, &r
);
2850 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2851 wine_dbgstr_rect(&r
));
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 %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2874 wine_dbgstr_rect(&r
));
2876 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2877 expect_messages
= normal_messages
;
2881 hr
= IDirectDrawSurface7_Restore(primary
);
2882 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2883 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2884 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2885 hr
= IDirectDrawSurface7_Restore(primary
);
2886 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2887 hr
= IDirectDrawSurface7_IsLost(primary
);
2888 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2890 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2891 expect_messages
= NULL
;
2892 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2894 GetWindowRect(window
, &r
);
2895 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2896 wine_dbgstr_rect(&r
));
2898 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2899 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2900 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2901 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2902 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2903 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2904 IDirectDrawSurface7_Release(primary
);
2906 memset(&ddsd
, 0, sizeof(ddsd
));
2907 ddsd
.dwSize
= sizeof(ddsd
);
2908 ddsd
.dwFlags
= DDSD_CAPS
;
2909 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2911 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2912 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2913 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2914 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2915 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2916 param
.ddraw_width
, ddsd
.dwWidth
);
2917 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2918 param
.ddraw_height
, ddsd
.dwHeight
);
2920 GetWindowRect(window
, &r
);
2921 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2922 wine_dbgstr_rect(&r
));
2924 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2925 expect_messages
= normal_messages
;
2929 hr
= IDirectDrawSurface7_IsLost(primary
);
2930 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2931 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
2932 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2933 hr
= IDirectDrawSurface7_IsLost(primary
);
2934 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2936 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2937 expect_messages
= NULL
;
2938 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2940 GetWindowRect(window
, &r
);
2941 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2942 wine_dbgstr_rect(&r
));
2944 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2945 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2946 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2947 param
.ddraw_width
, ddsd
.dwWidth
);
2948 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2949 param
.ddraw_height
, ddsd
.dwHeight
);
2950 IDirectDrawSurface7_Release(primary
);
2952 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2953 ok(ret
, "Failed to get display mode.\n");
2954 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2955 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2956 "Expected resolution %ux%u, got %ux%u.\n",
2957 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2958 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2959 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2960 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2962 memset(&ddsd
, 0, sizeof(ddsd
));
2963 ddsd
.dwSize
= sizeof(ddsd
);
2964 ddsd
.dwFlags
= DDSD_CAPS
;
2965 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2967 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2968 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2969 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2970 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2971 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2972 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2973 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2974 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2975 IDirectDrawSurface7_Release(primary
);
2977 GetWindowRect(window
, &r
);
2978 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2979 wine_dbgstr_rect(&r
));
2981 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2982 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2983 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2984 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2985 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2987 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2988 expect_messages
= exclusive_messages
;
2992 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2993 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2995 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2996 expect_messages
= NULL
;
2997 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2998 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2999 "Expected screen size %ux%u, got %ux%u.\n",
3000 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3001 screen_size
.cx
, screen_size
.cy
);
3003 GetWindowRect(window
, &r
);
3004 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3005 wine_dbgstr_rect(&r
));
3007 memset(&ddsd
, 0, sizeof(ddsd
));
3008 ddsd
.dwSize
= sizeof(ddsd
);
3009 ddsd
.dwFlags
= DDSD_CAPS
;
3010 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3012 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3013 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3014 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
3015 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3016 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3017 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3018 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3019 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3020 IDirectDrawSurface7_Release(primary
);
3022 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3023 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3024 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3025 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3026 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3028 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3029 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3031 memset(&ddsd
, 0, sizeof(ddsd
));
3032 ddsd
.dwSize
= sizeof(ddsd
);
3033 ddsd
.dwFlags
= DDSD_CAPS
;
3034 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3036 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3037 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3038 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
3039 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3040 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3041 param
.ddraw_width
, ddsd
.dwWidth
);
3042 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3043 param
.ddraw_height
, ddsd
.dwHeight
);
3044 IDirectDrawSurface7_Release(primary
);
3046 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
3047 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3049 /* If the window is changed at the same time, messages are sent to the new window. */
3050 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3051 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3052 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3053 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3055 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3056 expect_messages
= exclusive_messages
;
3059 screen_size2
.cx
= 0;
3060 screen_size2
.cy
= 0;
3062 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3063 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3065 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3066 expect_messages
= NULL
;
3067 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
3068 screen_size
.cx
, screen_size
.cy
);
3069 ok(screen_size2
.cx
== registry_mode
.dmPelsWidth
&& screen_size2
.cy
== registry_mode
.dmPelsHeight
,
3070 "Expected screen size 2 %ux%u, got %ux%u.\n",
3071 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size2
.cx
, screen_size2
.cy
);
3073 GetWindowRect(window
, &r
);
3074 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
3075 wine_dbgstr_rect(&r
));
3076 GetWindowRect(window2
, &r
);
3077 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3078 wine_dbgstr_rect(&r
));
3080 memset(&ddsd
, 0, sizeof(ddsd
));
3081 ddsd
.dwSize
= sizeof(ddsd
);
3082 ddsd
.dwFlags
= DDSD_CAPS
;
3083 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3085 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3086 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3087 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
3088 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3089 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3090 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3091 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3092 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3093 IDirectDrawSurface7_Release(primary
);
3095 ref
= IDirectDraw7_Release(ddraw
);
3096 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3098 GetWindowRect(window
, &r
);
3099 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
3100 wine_dbgstr_rect(&r
));
3102 expect_messages
= NULL
;
3103 DestroyWindow(window
);
3104 DestroyWindow(window2
);
3105 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3106 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3109 static void test_coop_level_mode_set_multi(void)
3111 IDirectDraw7
*ddraw1
, *ddraw2
;
3117 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3118 0, 0, 100, 100, 0, 0, 0, 0);
3119 ddraw1
= create_ddraw();
3120 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3122 /* With just a single ddraw object, the display mode is restored on
3124 hr
= set_display_mode(ddraw1
, 800, 600);
3125 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3126 w
= GetSystemMetrics(SM_CXSCREEN
);
3127 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3128 h
= GetSystemMetrics(SM_CYSCREEN
);
3129 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3131 ref
= IDirectDraw7_Release(ddraw1
);
3132 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3133 w
= GetSystemMetrics(SM_CXSCREEN
);
3134 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3135 h
= GetSystemMetrics(SM_CYSCREEN
);
3136 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3138 /* When there are multiple ddraw objects, the display mode is restored to
3139 * the initial mode, before the first SetDisplayMode() call. */
3140 ddraw1
= create_ddraw();
3141 hr
= set_display_mode(ddraw1
, 800, 600);
3142 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3143 w
= GetSystemMetrics(SM_CXSCREEN
);
3144 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3145 h
= GetSystemMetrics(SM_CYSCREEN
);
3146 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3148 ddraw2
= create_ddraw();
3149 hr
= set_display_mode(ddraw2
, 640, 480);
3150 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3151 w
= GetSystemMetrics(SM_CXSCREEN
);
3152 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3153 h
= GetSystemMetrics(SM_CYSCREEN
);
3154 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3156 ref
= IDirectDraw7_Release(ddraw2
);
3157 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3158 w
= GetSystemMetrics(SM_CXSCREEN
);
3159 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3160 h
= GetSystemMetrics(SM_CYSCREEN
);
3161 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3163 ref
= IDirectDraw7_Release(ddraw1
);
3164 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3165 w
= GetSystemMetrics(SM_CXSCREEN
);
3166 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3167 h
= GetSystemMetrics(SM_CYSCREEN
);
3168 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3170 /* Regardless of release ordering. */
3171 ddraw1
= create_ddraw();
3172 hr
= set_display_mode(ddraw1
, 800, 600);
3173 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3174 w
= GetSystemMetrics(SM_CXSCREEN
);
3175 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3176 h
= GetSystemMetrics(SM_CYSCREEN
);
3177 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3179 ddraw2
= create_ddraw();
3180 hr
= set_display_mode(ddraw2
, 640, 480);
3181 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3182 w
= GetSystemMetrics(SM_CXSCREEN
);
3183 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3184 h
= GetSystemMetrics(SM_CYSCREEN
);
3185 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3187 ref
= IDirectDraw7_Release(ddraw1
);
3188 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3189 w
= GetSystemMetrics(SM_CXSCREEN
);
3190 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3191 h
= GetSystemMetrics(SM_CYSCREEN
);
3192 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3194 ref
= IDirectDraw7_Release(ddraw2
);
3195 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3196 w
= GetSystemMetrics(SM_CXSCREEN
);
3197 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3198 h
= GetSystemMetrics(SM_CYSCREEN
);
3199 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3201 /* But only for ddraw objects that called SetDisplayMode(). */
3202 ddraw1
= create_ddraw();
3203 ddraw2
= create_ddraw();
3204 hr
= set_display_mode(ddraw2
, 640, 480);
3205 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3206 w
= GetSystemMetrics(SM_CXSCREEN
);
3207 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3208 h
= GetSystemMetrics(SM_CYSCREEN
);
3209 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3211 ref
= IDirectDraw7_Release(ddraw1
);
3212 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3213 w
= GetSystemMetrics(SM_CXSCREEN
);
3214 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3215 h
= GetSystemMetrics(SM_CYSCREEN
);
3216 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3218 ref
= IDirectDraw7_Release(ddraw2
);
3219 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3220 w
= GetSystemMetrics(SM_CXSCREEN
);
3221 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3222 h
= GetSystemMetrics(SM_CYSCREEN
);
3223 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3225 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3226 * restoring the display mode. */
3227 ddraw1
= create_ddraw();
3228 hr
= set_display_mode(ddraw1
, 800, 600);
3229 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3230 w
= GetSystemMetrics(SM_CXSCREEN
);
3231 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3232 h
= GetSystemMetrics(SM_CYSCREEN
);
3233 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3235 ddraw2
= create_ddraw();
3236 hr
= set_display_mode(ddraw2
, 640, 480);
3237 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3238 w
= GetSystemMetrics(SM_CXSCREEN
);
3239 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3240 h
= GetSystemMetrics(SM_CYSCREEN
);
3241 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3243 hr
= IDirectDraw7_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3244 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3246 ref
= IDirectDraw7_Release(ddraw1
);
3247 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3248 w
= GetSystemMetrics(SM_CXSCREEN
);
3249 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3250 h
= GetSystemMetrics(SM_CYSCREEN
);
3251 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3253 ref
= IDirectDraw7_Release(ddraw2
);
3254 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3255 w
= GetSystemMetrics(SM_CXSCREEN
);
3256 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3257 h
= GetSystemMetrics(SM_CYSCREEN
);
3258 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3260 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3261 ddraw1
= create_ddraw();
3262 hr
= set_display_mode(ddraw1
, 800, 600);
3263 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3264 w
= GetSystemMetrics(SM_CXSCREEN
);
3265 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3266 h
= GetSystemMetrics(SM_CYSCREEN
);
3267 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3269 hr
= IDirectDraw7_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3270 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3272 ddraw2
= create_ddraw();
3273 hr
= set_display_mode(ddraw2
, 640, 480);
3274 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3276 ref
= IDirectDraw7_Release(ddraw1
);
3277 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3278 w
= GetSystemMetrics(SM_CXSCREEN
);
3279 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3280 h
= GetSystemMetrics(SM_CYSCREEN
);
3281 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3283 ref
= IDirectDraw7_Release(ddraw2
);
3284 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3285 w
= GetSystemMetrics(SM_CXSCREEN
);
3286 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3287 h
= GetSystemMetrics(SM_CYSCREEN
);
3288 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3290 DestroyWindow(window
);
3293 static void test_initialize(void)
3295 IDirectDraw7
*ddraw
;
3298 ddraw
= create_ddraw();
3299 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3301 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
3302 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3303 IDirectDraw7_Release(ddraw
);
3306 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw7
, (void **)&ddraw
);
3307 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr
);
3308 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
3309 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3310 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
3311 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3312 IDirectDraw7_Release(ddraw
);
3316 static void test_coop_level_surf_create(void)
3318 IDirectDrawSurface7
*surface
;
3319 IDirectDraw7
*ddraw
;
3320 DDSURFACEDESC2 ddsd
;
3323 ddraw
= create_ddraw();
3324 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3326 memset(&ddsd
, 0, sizeof(ddsd
));
3327 ddsd
.dwSize
= sizeof(ddsd
);
3328 ddsd
.dwFlags
= DDSD_CAPS
;
3329 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3330 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3331 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3333 IDirectDraw7_Release(ddraw
);
3336 static void test_vb_discard(void)
3338 static const struct vec4 quad
[] =
3340 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
3341 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
3342 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
3343 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
3346 IDirect3DDevice7
*device
;
3348 IDirect3DVertexBuffer7
*buffer
;
3351 D3DVERTEXBUFFERDESC desc
;
3353 static const unsigned int vbsize
= 16;
3356 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3357 0, 0, 640, 480, 0, 0, 0, 0);
3359 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3361 skip("Failed to create a 3D device, skipping test.\n");
3362 DestroyWindow(window
);
3366 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
3367 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
3369 memset(&desc
, 0, sizeof(desc
));
3370 desc
.dwSize
= sizeof(desc
);
3371 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
3372 desc
.dwFVF
= D3DFVF_XYZRHW
;
3373 desc
.dwNumVertices
= vbsize
;
3374 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0);
3375 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3377 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3378 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3379 memcpy(data
, quad
, sizeof(quad
));
3380 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3381 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3383 hr
= IDirect3DDevice7_BeginScene(device
);
3384 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3385 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
3386 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3387 hr
= IDirect3DDevice7_EndScene(device
);
3388 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3390 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3391 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3392 memset(data
, 0xaa, sizeof(struct vec4
) * vbsize
);
3393 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3394 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3396 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3397 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3398 for (i
= 0; i
< sizeof(struct vec4
) * vbsize
; i
++)
3400 if (data
[i
] != 0xaa)
3402 ok(FALSE
, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i
, data
[i
]);
3406 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3407 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3409 IDirect3DVertexBuffer7_Release(buffer
);
3410 IDirect3D7_Release(d3d
);
3411 IDirect3DDevice7_Release(device
);
3412 DestroyWindow(window
);
3415 static void test_coop_level_multi_window(void)
3417 HWND window1
, window2
;
3418 IDirectDraw7
*ddraw
;
3421 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3422 0, 0, 640, 480, 0, 0, 0, 0);
3423 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3424 0, 0, 640, 480, 0, 0, 0, 0);
3425 ddraw
= create_ddraw();
3426 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3428 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3429 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3430 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3431 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3432 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3433 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3435 IDirectDraw7_Release(ddraw
);
3436 DestroyWindow(window2
);
3437 DestroyWindow(window1
);
3440 static void test_draw_strided(void)
3442 static struct vec3 position
[] =
3449 static DWORD diffuse
[] =
3451 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3453 static WORD indices
[] =
3458 IDirectDrawSurface7
*rt
;
3459 IDirect3DDevice7
*device
;
3463 D3DDRAWPRIMITIVESTRIDEDDATA strided
;
3465 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3466 0, 0, 640, 480, 0, 0, 0, 0);
3468 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3470 skip("Failed to create a 3D device, skipping test.\n");
3471 DestroyWindow(window
);
3475 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3476 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3478 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3479 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3480 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 1.0f
, 0);
3481 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3482 hr
= IDirect3DDevice7_BeginScene(device
);
3483 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3485 memset(&strided
, 0x55, sizeof(strided
));
3486 strided
.position
.lpvData
= position
;
3487 strided
.position
.dwStride
= sizeof(*position
);
3488 strided
.diffuse
.lpvData
= diffuse
;
3489 strided
.diffuse
.dwStride
= sizeof(*diffuse
);
3490 hr
= IDirect3DDevice7_DrawIndexedPrimitiveStrided(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
3491 &strided
, 4, indices
, 6, 0);
3492 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3494 hr
= IDirect3DDevice7_EndScene(device
);
3495 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3497 color
= get_surface_color(rt
, 320, 240);
3498 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3500 IDirectDrawSurface7_Release(rt
);
3501 IDirect3DDevice7_Release(device
);
3502 DestroyWindow(window
);
3505 static void test_lighting(void)
3507 static D3DMATRIX mat
=
3509 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3510 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3511 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3512 0.0f
, 0.0f
, 0.0f
, 1.0f
,
3516 1.0f
, 0.0f
, 1.0f
, 0.0f
,
3517 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3518 1.0f
, 0.0f
, 1.0f
, 0.0f
,
3519 0.0f
, 0.0f
, 0.5f
, 1.0f
,
3523 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3524 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3525 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
3526 10.f
, 10.0f
, 10.0f
, 1.0f
,
3530 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3531 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3532 0.0f
, 0.0f
, 1.0f
, -1.0f
,
3533 10.f
, 10.0f
, 10.0f
, 0.0f
,
3537 struct vec3 position
;
3542 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
3543 {{-1.0f
, 0.0f
, 0.1f
}, 0xffff0000},
3544 {{ 0.0f
, 0.0f
, 0.1f
}, 0xffff0000},
3545 {{ 0.0f
, -1.0f
, 0.1f
}, 0xffff0000},
3549 {{-1.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
3550 {{-1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
3551 {{ 0.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
3552 {{ 0.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
3556 struct vec3 position
;
3562 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3563 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3564 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3565 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3569 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3570 {{0.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3571 {{1.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3572 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3576 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3577 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3578 {{ 1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3579 {{ 1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3583 {{-10.0f
, -11.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3584 {{-10.0f
, -9.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3585 {{-10.0f
, -9.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3586 {{-10.0f
, -11.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3590 {{-11.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3591 {{-11.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3592 {{ -9.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3593 {{ -9.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3595 static WORD indices
[] = {0, 1, 2, 2, 3, 0};
3598 D3DMATRIX
*world_matrix
;
3601 const char *message
;
3605 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
3606 {&mat_singular
, nquad
, 0x000000ff, "Lit quad with singular world matrix"},
3607 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
3608 {&mat_nonaffine
, translatedquad
, 0x00000000, "Lit quad with non-affine matrix"},
3612 IDirect3DDevice7
*device
;
3613 IDirectDrawSurface7
*rt
;
3615 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
3616 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
3621 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3622 0, 0, 640, 480, 0, 0, 0, 0);
3623 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3625 skip("Failed to create a 3D device, skipping test.\n");
3626 DestroyWindow(window
);
3630 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3631 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3633 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
3634 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3636 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
3637 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
3638 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
3639 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
3640 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
3641 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
3642 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3643 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
3644 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
3645 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
3646 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
3647 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
3648 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
3649 ok(SUCCEEDED(hr
), "Failed to disable stencil buffering, hr %#x.\n", hr
);
3650 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
3651 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
3653 hr
= IDirect3DDevice7_BeginScene(device
);
3654 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3656 /* No lights are defined... That means, lit vertices should be entirely black. */
3657 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3658 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3659 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, unlitquad
, 4,
3661 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3663 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
3664 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
3665 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, litquad
, 4,
3667 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3669 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3670 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3671 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, unlitnquad
, 4,
3673 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3675 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
3676 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
3677 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, litnquad
, 4,
3679 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3681 hr
= IDirect3DDevice7_EndScene(device
);
3682 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3684 color
= get_surface_color(rt
, 160, 360);
3685 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color
);
3686 color
= get_surface_color(rt
, 160, 120);
3687 ok(color
== 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color
);
3688 color
= get_surface_color(rt
, 480, 360);
3689 ok(color
== 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color
);
3690 color
= get_surface_color(rt
, 480, 120);
3691 ok(color
== 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color
);
3693 hr
= IDirect3DDevice7_LightEnable(device
, 0, TRUE
);
3694 ok(SUCCEEDED(hr
), "Failed to enable light 0, hr %#x.\n", hr
);
3696 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
3698 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, tests
[i
].world_matrix
);
3699 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
3701 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
3702 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3704 hr
= IDirect3DDevice7_BeginScene(device
);
3705 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3707 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, tests
[i
].quad
,
3709 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3711 hr
= IDirect3DDevice7_EndScene(device
);
3712 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3714 color
= get_surface_color(rt
, 320, 240);
3715 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
3718 IDirectDrawSurface7_Release(rt
);
3720 refcount
= IDirect3DDevice7_Release(device
);
3721 ok(!refcount
, "Device has %u references left.\n", refcount
);
3722 DestroyWindow(window
);
3725 static void test_specular_lighting(void)
3727 static const unsigned int vertices_side
= 5;
3728 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
3729 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_NORMAL
;
3730 static D3DMATRIX mat
=
3732 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3733 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3734 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3735 0.0f
, 0.0f
, 0.0f
, 1.0f
,
3737 static D3DLIGHT7 directional
=
3739 D3DLIGHT_DIRECTIONAL
,
3740 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3741 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3742 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3743 {{0.0f
}, {0.0f
}, {0.0f
}},
3744 {{0.0f
}, {0.0f
}, {1.0f
}},
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
}, {0.0f
}},
3761 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3762 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3763 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3764 {{0.0f
}, {0.0f
}, {0.0f
}},
3765 {{0.0f
}, {0.0f
}, {1.0f
}},
3769 M_PI
/ 12.0f
, M_PI
/ 3.0f
3771 /* The chosen range value makes the test fail when using a manhattan
3772 * distance metric vs the correct euclidean distance. */
3776 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3777 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3778 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3779 {{0.0f
}, {0.0f
}, {0.0f
}},
3780 {{0.0f
}, {0.0f
}, {0.0f
}},
3785 static const struct expected_color
3790 expected_directional
[] =
3792 {160, 120, 0x00ffffff},
3793 {320, 120, 0x00ffffff},
3794 {480, 120, 0x00ffffff},
3795 {160, 240, 0x00ffffff},
3796 {320, 240, 0x00ffffff},
3797 {480, 240, 0x00ffffff},
3798 {160, 360, 0x00ffffff},
3799 {320, 360, 0x00ffffff},
3800 {480, 360, 0x00ffffff},
3802 expected_directional_local
[] =
3804 {160, 120, 0x003c3c3c},
3805 {320, 120, 0x00717171},
3806 {480, 120, 0x003c3c3c},
3807 {160, 240, 0x00717171},
3808 {320, 240, 0x00ffffff},
3809 {480, 240, 0x00717171},
3810 {160, 360, 0x003c3c3c},
3811 {320, 360, 0x00717171},
3812 {480, 360, 0x003c3c3c},
3816 {160, 120, 0x00282828},
3817 {320, 120, 0x005a5a5a},
3818 {480, 120, 0x00282828},
3819 {160, 240, 0x005a5a5a},
3820 {320, 240, 0x00ffffff},
3821 {480, 240, 0x005a5a5a},
3822 {160, 360, 0x00282828},
3823 {320, 360, 0x005a5a5a},
3824 {480, 360, 0x00282828},
3826 expected_point_local
[] =
3828 {160, 120, 0x00000000},
3829 {320, 120, 0x00070707},
3830 {480, 120, 0x00000000},
3831 {160, 240, 0x00070707},
3832 {320, 240, 0x00ffffff},
3833 {480, 240, 0x00070707},
3834 {160, 360, 0x00000000},
3835 {320, 360, 0x00070707},
3836 {480, 360, 0x00000000},
3840 {160, 120, 0x00000000},
3841 {320, 120, 0x00141414},
3842 {480, 120, 0x00000000},
3843 {160, 240, 0x00141414},
3844 {320, 240, 0x00ffffff},
3845 {480, 240, 0x00141414},
3846 {160, 360, 0x00000000},
3847 {320, 360, 0x00141414},
3848 {480, 360, 0x00000000},
3850 expected_spot_local
[] =
3852 {160, 120, 0x00000000},
3853 {320, 120, 0x00020202},
3854 {480, 120, 0x00000000},
3855 {160, 240, 0x00020202},
3856 {320, 240, 0x00ffffff},
3857 {480, 240, 0x00020202},
3858 {160, 360, 0x00000000},
3859 {320, 360, 0x00020202},
3860 {480, 360, 0x00000000},
3862 expected_point_range
[] =
3864 {160, 120, 0x00000000},
3865 {320, 120, 0x005a5a5a},
3866 {480, 120, 0x00000000},
3867 {160, 240, 0x005a5a5a},
3868 {320, 240, 0x00ffffff},
3869 {480, 240, 0x005a5a5a},
3870 {160, 360, 0x00000000},
3871 {320, 360, 0x005a5a5a},
3872 {480, 360, 0x00000000},
3878 const struct expected_color
*expected
;
3879 unsigned int expected_count
;
3883 {&directional
, FALSE
, expected_directional
,
3884 sizeof(expected_directional
) / sizeof(expected_directional
[0])},
3885 {&directional
, TRUE
, expected_directional_local
,
3886 sizeof(expected_directional_local
) / sizeof(expected_directional_local
[0])},
3887 {&point
, FALSE
, expected_point
,
3888 sizeof(expected_point
) / sizeof(expected_point
[0])},
3889 {&point
, TRUE
, expected_point_local
,
3890 sizeof(expected_point_local
) / sizeof(expected_point_local
[0])},
3891 {&spot
, FALSE
, expected_spot
,
3892 sizeof(expected_spot
) / sizeof(expected_spot
[0])},
3893 {&spot
, TRUE
, expected_spot_local
,
3894 sizeof(expected_spot_local
) / sizeof(expected_spot_local
[0])},
3895 {&point_range
, FALSE
, expected_point_range
,
3896 sizeof(expected_point_range
) / sizeof(expected_point_range
[0])},
3898 IDirect3DDevice7
*device
;
3899 IDirectDrawSurface7
*rt
;
3900 D3DMATERIAL7 material
;
3905 unsigned int i
, j
, x
, y
;
3908 struct vec3 position
;
3913 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3914 0, 0, 640, 480, 0, 0, 0, 0);
3915 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3917 skip("Failed to create a 3D device, skipping test.\n");
3918 DestroyWindow(window
);
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 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3950 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3952 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
3953 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
3954 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
3955 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
3956 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
3957 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
3958 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3959 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
3960 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
3961 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
3962 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
3963 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
3965 memset(&material
, 0, sizeof(material
));
3966 U1(U2(material
).specular
).r
= 1.0f
;
3967 U2(U2(material
).specular
).g
= 1.0f
;
3968 U3(U2(material
).specular
).b
= 1.0f
;
3969 U4(U2(material
).specular
).a
= 1.0f
;
3970 U4(material
).power
= 30.0f
;
3971 hr
= IDirect3DDevice7_SetMaterial(device
, &material
);
3972 ok(SUCCEEDED(hr
), "Failed to set material, hr %#x.\n", hr
);
3974 hr
= IDirect3DDevice7_LightEnable(device
, 0, TRUE
);
3975 ok(SUCCEEDED(hr
), "Failed to enable light 0, hr %#x.\n", hr
);
3976 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, TRUE
);
3977 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
3979 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
3981 hr
= IDirect3DDevice7_SetLight(device
, 0, tests
[i
].light
);
3982 ok(SUCCEEDED(hr
), "Failed to set light parameters, hr %#x.\n", hr
);
3984 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LOCALVIEWER
, tests
[i
].local_viewer
);
3985 ok(SUCCEEDED(hr
), "Failed to set local viewer state, hr %#x.\n", hr
);
3987 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
3988 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
3990 hr
= IDirect3DDevice7_BeginScene(device
);
3991 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3993 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, quad
,
3994 vertices_side
* vertices_side
, indices
, indices_count
, 0);
3995 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3997 hr
= IDirect3DDevice7_EndScene(device
);
3998 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4000 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
4002 color
= get_surface_color(rt
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
4003 ok(compare_color(color
, tests
[i
].expected
[j
].color
, 1),
4004 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
4005 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
4006 tests
[i
].expected
[j
].y
, color
, i
);
4010 IDirectDrawSurface7_Release(rt
);
4012 refcount
= IDirect3DDevice7_Release(device
);
4013 ok(!refcount
, "Device has %u references left.\n", refcount
);
4014 DestroyWindow(window
);
4015 HeapFree(GetProcessHeap(), 0, indices
);
4016 HeapFree(GetProcessHeap(), 0, quad
);
4019 static void test_clear_rect_count(void)
4021 IDirectDrawSurface7
*rt
;
4022 IDirect3DDevice7
*device
;
4026 D3DRECT rect
= {{0}, {0}, {640}, {480}};
4028 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4029 0, 0, 640, 480, 0, 0, 0, 0);
4030 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4032 skip("Failed to create a 3D device, skipping test.\n");
4033 DestroyWindow(window
);
4037 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
4038 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4040 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ffffff, 1.0f
, 0);
4041 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4042 hr
= IDirect3DDevice7_Clear(device
, 0, &rect
, D3DCLEAR_TARGET
, 0x00ff0000, 1.0f
, 0);
4043 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4045 color
= get_surface_color(rt
, 320, 240);
4046 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x00ff0000, 1)),
4047 "Clear with count = 0, rect != NULL has color %#08x.\n", color
);
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
, 1, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 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
, 0x0000ff00, 1),
4056 "Clear with count = 1, rect = NULL has color %#08x.\n", color
);
4058 IDirectDrawSurface7_Release(rt
);
4059 IDirect3DDevice7_Release(device
);
4060 DestroyWindow(window
);
4063 static BOOL
test_mode_restored(IDirectDraw7
*ddraw
, HWND window
)
4065 DDSURFACEDESC2 ddsd1
, ddsd2
;
4068 memset(&ddsd1
, 0, sizeof(ddsd1
));
4069 ddsd1
.dwSize
= sizeof(ddsd1
);
4070 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &ddsd1
);
4071 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
4073 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4074 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4075 hr
= set_display_mode(ddraw
, 640, 480);
4076 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
4077 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4078 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4080 memset(&ddsd2
, 0, sizeof(ddsd2
));
4081 ddsd2
.dwSize
= sizeof(ddsd2
);
4082 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &ddsd2
);
4083 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
4084 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
4085 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
4087 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
4090 static void test_coop_level_versions(void)
4096 IDirectDrawSurface
*surface
;
4097 IDirectDraw7
*ddraw7
;
4100 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
4101 0, 0, 640, 480, 0, 0, 0, 0);
4103 ddraw7
= create_ddraw();
4104 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4105 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
4106 restored
= test_mode_restored(ddraw7
, window
);
4107 ok(restored
, "Display mode not restored in new ddraw object\n");
4109 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
4110 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4111 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4113 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4114 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
4115 restored
= test_mode_restored(ddraw7
, window
);
4116 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
4118 /* A successful one does */
4119 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4120 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4121 restored
= test_mode_restored(ddraw7
, window
);
4122 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
4124 IDirectDraw_Release(ddraw
);
4125 IDirectDraw7_Release(ddraw7
);
4127 ddraw7
= create_ddraw();
4128 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4129 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4130 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4132 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
4133 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4134 restored
= test_mode_restored(ddraw7
, window
);
4135 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
4137 IDirectDraw_Release(ddraw
);
4138 IDirectDraw7_Release(ddraw7
);
4140 /* A failing call does not restore the ddraw2+ behavior */
4141 ddraw7
= create_ddraw();
4142 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4143 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4144 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4146 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4147 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4148 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4149 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
4150 restored
= test_mode_restored(ddraw7
, window
);
4151 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
4153 IDirectDraw_Release(ddraw
);
4154 IDirectDraw7_Release(ddraw7
);
4156 /* Neither does a sequence of successful calls with the new interface */
4157 ddraw7
= create_ddraw();
4158 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4159 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4160 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4162 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4163 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4164 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4165 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4166 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_NORMAL
);
4167 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4169 restored
= test_mode_restored(ddraw7
, window
);
4170 ok(!restored
, "Display mode restored after ddraw1-ddraw7 SetCooperativeLevel() call sequence\n");
4171 IDirectDraw_Release(ddraw
);
4172 IDirectDraw7_Release(ddraw7
);
4174 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
4175 ddraw7
= create_ddraw();
4176 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4177 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4178 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4180 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_NORMAL
);
4181 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4183 memset(&ddsd
, 0, sizeof(ddsd
));
4184 ddsd
.dwSize
= sizeof(ddsd
);
4185 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4186 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4187 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
4188 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4189 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
4190 IDirectDrawSurface_Release(surface
);
4191 restored
= test_mode_restored(ddraw7
, window
);
4192 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
4194 IDirectDraw_Release(ddraw
);
4195 IDirectDraw7_Release(ddraw7
);
4196 DestroyWindow(window
);
4199 static void test_fog_special(void)
4203 struct vec3 position
;
4208 {{ -1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
4209 {{ 1.0f
, 1.0f
, 1.0f
}, 0xff00ff00},
4210 {{ -1.0f
, -1.0f
, 0.0f
}, 0xff00ff00},
4211 {{ 1.0f
, -1.0f
, 1.0f
}, 0xff00ff00},
4215 DWORD vertexmode
, tablemode
;
4216 D3DCOLOR color_left
, color_right
;
4220 {D3DFOG_LINEAR
, D3DFOG_NONE
, 0x00ff0000, 0x00ff0000},
4221 {D3DFOG_NONE
, D3DFOG_LINEAR
, 0x0000ff00, 0x00ff0000},
4232 IDirect3DDevice7
*device
;
4233 IDirectDrawSurface7
*rt
;
4235 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4236 0, 0, 640, 480, 0, 0, 0, 0);
4238 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4240 skip("Failed to create a 3D device, skipping test.\n");
4241 DestroyWindow(window
);
4245 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
4246 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4248 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
4249 ok(SUCCEEDED(hr
), "Failed to enable fog, hr %#x.\n", hr
);
4250 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0xffff0000);
4251 ok(SUCCEEDED(hr
), "Failed to set fog color, hr %#x.\n", hr
);
4252 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
4253 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
4254 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
4255 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
4258 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, conv
.d
);
4259 ok(SUCCEEDED(hr
), "Failed to set fog start, hr %#x.\n", hr
);
4260 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, conv
.d
);
4261 ok(SUCCEEDED(hr
), "Failed to set fog end, hr %#x.\n", hr
);
4263 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4265 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 1.0f
, 0);
4266 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4268 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, tests
[i
].vertexmode
);
4269 ok(SUCCEEDED(hr
), "Failed to set fogvertexmode, hr %#x.\n", hr
);
4270 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, tests
[i
].tablemode
);
4271 ok(SUCCEEDED(hr
), "Failed to set fogtablemode, hr %#x.\n", hr
);
4273 hr
= IDirect3DDevice7_BeginScene(device
);
4274 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4275 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad
, 4, 0);
4276 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4277 hr
= IDirect3DDevice7_EndScene(device
);
4278 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4280 color
= get_surface_color(rt
, 310, 240);
4281 ok(compare_color(color
, tests
[i
].color_left
, 1),
4282 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests
[i
].color_left
, color
, i
);
4283 color
= get_surface_color(rt
, 330, 240);
4284 ok(compare_color(color
, tests
[i
].color_right
, 1),
4285 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests
[i
].color_right
, color
, i
);
4288 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
4289 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
4291 IDirectDrawSurface7_Release(rt
);
4292 IDirect3DDevice7_Release(device
);
4293 DestroyWindow(window
);
4296 static void test_lighting_interface_versions(void)
4298 IDirect3DDevice7
*device
;
4299 IDirectDrawSurface7
*rt
;
4306 D3DMATERIAL7 material
;
4307 static D3DVERTEX quad
[] =
4309 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4310 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4311 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4312 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4315 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
4318 struct vec3 position
;
4320 DWORD diffuse
, specular
;
4324 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4325 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4326 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4327 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4330 static D3DLVERTEX lquad
[] =
4332 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4333 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4334 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4335 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4338 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
4341 struct vec3 position
;
4342 DWORD diffuse
, specular
;
4343 struct vec2 texcoord
;
4347 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4348 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4349 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4350 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4353 static D3DTLVERTEX tlquad
[] =
4355 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4356 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4357 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4358 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4365 DWORD d3drs_lighting
, d3drs_specular
;
4371 /* Lighting is enabled when D3DFVF_XYZ is used and D3DRENDERSTATE_LIGHTING is
4372 * enabled. D3DDP_DONOTLIGHT is ignored. Lighting is also enabled when normals
4375 * Note that the specular result is 0x00000000 when lighting is on even if the
4376 * input vertex has specular color because D3DRENDERSTATE_COLORVERTEX is not
4380 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x00ffffff},
4381 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
4382 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4383 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4384 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x00ffffff},
4385 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
4386 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4387 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4390 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, 0, 0x00ff0000},
4391 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, 0, 0x0000ff00},
4392 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4393 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4394 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, 0, 0x00ff8080},
4395 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, 0, 0x0000ff00},
4396 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4397 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4400 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
4401 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x0000ff00},
4402 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4403 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4404 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
4405 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x0000ff00},
4406 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4407 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4410 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, 0, 0x00ff0000},
4411 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, 0, 0x0000ff00},
4412 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4413 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4414 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, 0, 0x00ff8080},
4415 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, 0, 0x0000ff00},
4416 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4417 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4420 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
4421 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
4422 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
4423 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
4424 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
4425 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
4426 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
4427 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
4430 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4431 0, 0, 640, 480, 0, 0, 0, 0);
4433 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4435 skip("Failed to create a 3D device, skipping test.\n");
4436 DestroyWindow(window
);
4440 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
4441 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4443 memset(&material
, 0, sizeof(material
));
4444 U2(U3(material
).emissive
).g
= 1.0f
;
4445 hr
= IDirect3DDevice7_SetMaterial(device
, &material
);
4446 ok(SUCCEEDED(hr
), "Failed set material, hr %#x.\n", hr
);
4447 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
4448 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
4450 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_LIGHTING
, &rs
);
4451 ok(SUCCEEDED(hr
), "Failed to get lighting render state, hr %#x.\n", hr
);
4452 ok(rs
== TRUE
, "Initial D3DRENDERSTATE_LIGHTING is %#x, expected TRUE.\n", rs
);
4453 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
4454 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
4455 ok(rs
== FALSE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs
);
4457 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4459 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff202020, 0.0f
, 0);
4460 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
4462 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
4463 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
4464 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
4465 tests
[i
].d3drs_specular
);
4466 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
4468 hr
= IDirect3DDevice7_BeginScene(device
);
4469 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4470 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
4471 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
4472 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4473 hr
= IDirect3DDevice7_EndScene(device
);
4474 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4476 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_LIGHTING
, &rs
);
4477 ok(SUCCEEDED(hr
), "Failed to get lighting render state, hr %#x.\n", hr
);
4478 ok(rs
== tests
[i
].d3drs_lighting
, "D3DRENDERSTATE_LIGHTING is %#x, expected %#x.\n",
4479 rs
, tests
[i
].d3drs_lighting
);
4481 color
= get_surface_color(rt
, 320, 240);
4482 ok(compare_color(color
, tests
[i
].color
, 1),
4483 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
4484 color
, tests
[i
].color
, i
);
4487 IDirectDrawSurface7_Release(rt
);
4488 ref
= IDirect3DDevice7_Release(device
);
4489 ok(ref
== 0, "Device not properly released, refcount %u.\n", ref
);
4490 DestroyWindow(window
);
4496 IDirectDraw7
*ddraw
;
4499 } activateapp_testdata
;
4501 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
4503 if (message
== WM_ACTIVATEAPP
)
4505 if (activateapp_testdata
.ddraw
)
4508 activateapp_testdata
.received
= FALSE
;
4509 hr
= IDirectDraw7_SetCooperativeLevel(activateapp_testdata
.ddraw
,
4510 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
4511 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
4512 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
4514 activateapp_testdata
.received
= TRUE
;
4517 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
4520 static void test_coop_level_activateapp(void)
4522 IDirectDraw7
*ddraw
;
4526 DDSURFACEDESC2 ddsd
;
4527 IDirectDrawSurface7
*surface
;
4529 ddraw
= create_ddraw();
4530 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4532 wc
.lpfnWndProc
= activateapp_test_proc
;
4533 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
4534 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
4536 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
4537 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
4539 /* Exclusive with window already active. */
4540 SetForegroundWindow(window
);
4541 activateapp_testdata
.received
= FALSE
;
4542 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4543 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4544 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
4545 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4546 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4548 /* Exclusive with window not active. */
4549 SetForegroundWindow(GetDesktopWindow());
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
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4554 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4555 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4557 /* Normal with window not active, then exclusive with the same window. */
4558 SetForegroundWindow(GetDesktopWindow());
4559 activateapp_testdata
.received
= FALSE
;
4560 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4561 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4562 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
4563 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4564 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4565 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4566 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4567 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4569 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
4570 SetForegroundWindow(GetDesktopWindow());
4571 activateapp_testdata
.received
= FALSE
;
4572 activateapp_testdata
.ddraw
= ddraw
;
4573 activateapp_testdata
.window
= window
;
4574 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
4575 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4576 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4577 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4578 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4579 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4581 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
4582 * succeeding. Another switch to exclusive and back to normal is needed to release the
4583 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
4584 * WM_ACTIVATEAPP messages. */
4585 activateapp_testdata
.ddraw
= NULL
;
4586 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4587 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4588 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4589 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4591 /* Setting DDSCL_NORMAL with recursive invocation. */
4592 SetForegroundWindow(GetDesktopWindow());
4593 activateapp_testdata
.received
= FALSE
;
4594 activateapp_testdata
.ddraw
= ddraw
;
4595 activateapp_testdata
.window
= window
;
4596 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
4597 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4598 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4599 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4601 /* DDraw is in exlusive mode now. */
4602 memset(&ddsd
, 0, sizeof(ddsd
));
4603 ddsd
.dwSize
= sizeof(ddsd
);
4604 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4605 U5(ddsd
).dwBackBufferCount
= 1;
4606 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4607 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4608 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4609 IDirectDrawSurface7_Release(surface
);
4611 /* Recover again, just to be sure. */
4612 activateapp_testdata
.ddraw
= NULL
;
4613 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4614 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4615 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4616 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4618 DestroyWindow(window
);
4619 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
4620 IDirectDraw7_Release(ddraw
);
4623 static void test_texturemanage(void)
4625 IDirectDraw7
*ddraw
;
4627 DDSURFACEDESC2 ddsd
;
4628 IDirectDrawSurface7
*surface
;
4630 DDCAPS hal_caps
, hel_caps
;
4631 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
4634 DWORD caps_in
, caps2_in
;
4636 DWORD caps_out
, caps2_out
;
4640 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4642 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4644 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4646 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4648 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DD_OK
,
4649 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
},
4650 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DD_OK
,
4651 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
},
4652 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
4653 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_LOCALVIDMEM
, 0},
4654 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
4655 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0},
4657 {0, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4659 {0, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4661 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4663 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4665 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4667 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4669 {DDSCAPS_VIDEOMEMORY
, 0, DD_OK
,
4670 DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
, 0},
4671 {DDSCAPS_SYSTEMMEMORY
, 0, DD_OK
,
4672 DDSCAPS_SYSTEMMEMORY
, 0},
4675 ddraw
= create_ddraw();
4676 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4677 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4678 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4680 memset(&hal_caps
, 0, sizeof(hal_caps
));
4681 hal_caps
.dwSize
= sizeof(hal_caps
);
4682 memset(&hel_caps
, 0, sizeof(hel_caps
));
4683 hel_caps
.dwSize
= sizeof(hel_caps
);
4684 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, &hel_caps
);
4685 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4686 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
4688 skip("Managed textures not supported, skipping managed texture test.\n");
4689 IDirectDraw7_Release(ddraw
);
4693 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4695 memset(&ddsd
, 0, sizeof(ddsd
));
4696 ddsd
.dwSize
= sizeof(ddsd
);
4697 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4698 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps_in
;
4699 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2_in
;
4703 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4704 if (tests
[i
].hr
== DD_OK
&& is_ddraw64
&& (tests
[i
].caps_in
& DDSCAPS_TEXTURE
))
4705 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4707 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, tests
[i
].hr
);
4711 memset(&ddsd
, 0, sizeof(ddsd
));
4712 ddsd
.dwSize
= sizeof(ddsd
);
4713 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
4714 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4716 ok(ddsd
.ddsCaps
.dwCaps
== tests
[i
].caps_out
,
4717 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4718 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps_out
, ddsd
.ddsCaps
.dwCaps
, i
);
4719 ok(ddsd
.ddsCaps
.dwCaps2
== tests
[i
].caps2_out
,
4720 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4721 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps2_out
, ddsd
.ddsCaps
.dwCaps2
, i
);
4723 IDirectDrawSurface7_Release(surface
);
4726 IDirectDraw7_Release(ddraw
);
4729 #define SUPPORT_DXT1 0x01
4730 #define SUPPORT_DXT2 0x02
4731 #define SUPPORT_DXT3 0x04
4732 #define SUPPORT_DXT4 0x08
4733 #define SUPPORT_DXT5 0x10
4734 #define SUPPORT_YUY2 0x20
4735 #define SUPPORT_UYVY 0x40
4737 static HRESULT WINAPI
test_block_formats_creation_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
4739 DWORD
*supported_fmts
= ctx
;
4741 if (!(fmt
->dwFlags
& DDPF_FOURCC
))
4742 return DDENUMRET_OK
;
4744 switch (fmt
->dwFourCC
)
4746 case MAKEFOURCC('D','X','T','1'):
4747 *supported_fmts
|= SUPPORT_DXT1
;
4749 case MAKEFOURCC('D','X','T','2'):
4750 *supported_fmts
|= SUPPORT_DXT2
;
4752 case MAKEFOURCC('D','X','T','3'):
4753 *supported_fmts
|= SUPPORT_DXT3
;
4755 case MAKEFOURCC('D','X','T','4'):
4756 *supported_fmts
|= SUPPORT_DXT4
;
4758 case MAKEFOURCC('D','X','T','5'):
4759 *supported_fmts
|= SUPPORT_DXT5
;
4761 case MAKEFOURCC('Y','U','Y','2'):
4762 *supported_fmts
|= SUPPORT_YUY2
;
4764 case MAKEFOURCC('U','Y','V','Y'):
4765 *supported_fmts
|= SUPPORT_UYVY
;
4771 return DDENUMRET_OK
;
4774 static void test_block_formats_creation(void)
4776 HRESULT hr
, expect_hr
;
4777 unsigned int i
, j
, w
, h
;
4779 IDirectDraw7
*ddraw
;
4781 IDirect3DDevice7
*device
;
4782 IDirectDrawSurface7
*surface
;
4783 DWORD supported_fmts
= 0, supported_overlay_fmts
= 0;
4784 DWORD num_fourcc_codes
= 0, *fourcc_codes
;
4785 DDSURFACEDESC2 ddsd
;
4794 unsigned int block_width
;
4795 unsigned int block_height
;
4796 unsigned int block_size
;
4797 BOOL create_size_checked
, overlay
;
4801 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1
, 4, 4, 8, TRUE
, FALSE
},
4802 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2
, 4, 4, 16, TRUE
, FALSE
},
4803 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3
, 4, 4, 16, TRUE
, FALSE
},
4804 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4
, 4, 4, 16, TRUE
, FALSE
},
4805 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5
, 4, 4, 16, TRUE
, FALSE
},
4806 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2
, 2, 1, 4, FALSE
, TRUE
},
4807 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY
, 2, 1, 4, FALSE
, TRUE
},
4817 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4818 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4820 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4821 * Other hw / drivers successfully create those surfaces. Ignore them, this
4822 * suggests that no game uses this, otherwise Nvidia would support it. */
4824 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0,
4825 "videomemory texture", FALSE
4828 DDSCAPS_VIDEOMEMORY
| DDSCAPS_OVERLAY
, 0,
4829 "videomemory overlay", TRUE
4832 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0,
4833 "systemmemory texture", FALSE
4836 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
4837 "managed texture", FALSE
4849 enum size_type size_type
;
4855 {DDSD_LINEARSIZE
, SIZE_TYPE_ZERO
, 0, DD_OK
},
4856 {DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
4857 {DDSD_PITCH
, SIZE_TYPE_ZERO
, 0, DD_OK
},
4858 {DDSD_PITCH
, SIZE_TYPE_PITCH
, 0, DD_OK
},
4859 {DDSD_LPSURFACE
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
4860 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
4861 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_PITCH
, 0, DDERR_INVALIDPARAMS
},
4862 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
4863 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 1, DD_OK
},
4864 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, -1, DDERR_INVALIDPARAMS
},
4865 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
4866 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_PITCH
, 0, DDERR_INVALIDPARAMS
},
4867 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_SIZE
, 0, DDERR_INVALIDPARAMS
},
4868 {DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DDERR_INVALIDPARAMS
},
4871 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4872 0, 0, 640, 480, 0, 0, 0, 0);
4874 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4876 skip("Failed to create a 3D device, skipping test.\n");
4877 DestroyWindow(window
);
4881 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
4882 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
4883 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
4884 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
4885 IDirect3D7_Release(d3d
);
4887 hr
= IDirect3DDevice7_EnumTextureFormats(device
, test_block_formats_creation_cb
,
4889 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4891 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
4892 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
4893 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
4894 num_fourcc_codes
* sizeof(*fourcc_codes
));
4897 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
4898 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
4899 for (i
= 0; i
< num_fourcc_codes
; i
++)
4901 for (j
= 0; j
< sizeof(formats
) / sizeof(*formats
); j
++)
4903 if (fourcc_codes
[i
] == formats
[j
].fourcc
)
4904 supported_overlay_fmts
|= formats
[j
].support_flag
;
4907 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
4909 memset(&hal_caps
, 0, sizeof(hal_caps
));
4910 hal_caps
.dwSize
= sizeof(hal_caps
);
4911 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
4912 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4914 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 2 * 2 * 16 + 1);
4916 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
4918 for (j
= 0; j
< sizeof(types
) / sizeof(*types
); j
++)
4922 if (formats
[i
].overlay
!= types
[j
].overlay
4923 || (types
[j
].overlay
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
)))
4926 if (formats
[i
].overlay
)
4927 support
= supported_overlay_fmts
& formats
[i
].support_flag
;
4929 support
= supported_fmts
& formats
[i
].support_flag
;
4931 for (w
= 1; w
<= 8; w
++)
4933 for (h
= 1; h
<= 8; h
++)
4935 BOOL block_aligned
= TRUE
;
4938 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
4939 block_aligned
= FALSE
;
4941 memset(&ddsd
, 0, sizeof(ddsd
));
4942 ddsd
.dwSize
= sizeof(ddsd
);
4943 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4944 ddsd
.ddsCaps
.dwCaps
= types
[j
].caps
;
4945 ddsd
.ddsCaps
.dwCaps2
= types
[j
].caps2
;
4946 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
4947 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
4948 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
4952 /* TODO: Handle power of two limitations. I cannot test the pow2
4953 * behavior on windows because I have no hardware that doesn't at
4954 * least support np2_conditional. There's probably no HW that
4955 * supports DXTN textures but no conditional np2 textures. */
4956 if (!support
&& !(types
[j
].caps
& DDSCAPS_SYSTEMMEMORY
))
4957 expect_hr
= DDERR_INVALIDPARAMS
;
4958 else if (formats
[i
].create_size_checked
&& !block_aligned
)
4960 expect_hr
= DDERR_INVALIDPARAMS
;
4961 if (!(types
[j
].caps
& DDSCAPS_TEXTURE
))
4967 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4970 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4971 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
4974 IDirectDrawSurface7_Release(surface
);
4979 if (formats
[i
].overlay
)
4982 for (j
= 0; j
< sizeof(user_mem_tests
) / sizeof(*user_mem_tests
); ++j
)
4984 memset(&ddsd
, 0, sizeof(ddsd
));
4985 ddsd
.dwSize
= sizeof(ddsd
);
4986 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| user_mem_tests
[j
].flags
;
4987 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
;
4989 switch (user_mem_tests
[j
].size_type
)
4991 case SIZE_TYPE_ZERO
:
4992 U1(ddsd
).dwLinearSize
= 0;
4995 case SIZE_TYPE_PITCH
:
4996 U1(ddsd
).dwLinearSize
= 2 * formats
[i
].block_size
;
4999 case SIZE_TYPE_SIZE
:
5000 U1(ddsd
).dwLinearSize
= 2 * 2 * formats
[i
].block_size
;
5003 U1(ddsd
).dwLinearSize
+= user_mem_tests
[j
].rel_size
;
5005 ddsd
.lpSurface
= mem
;
5006 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5007 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
5008 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
5012 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5013 ok(hr
== user_mem_tests
[j
].hr
, "Test %u: Got unexpected hr %#x, format %s.\n", j
, hr
, formats
[i
].name
);
5018 memset(&ddsd
, 0, sizeof(ddsd
));
5019 ddsd
.dwSize
= sizeof(ddsd
);
5020 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
5021 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", j
, hr
);
5022 ok(ddsd
.dwFlags
== (DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_LINEARSIZE
),
5023 "Test %u: Got unexpected flags %#x.\n", j
, ddsd
.dwFlags
);
5024 if (user_mem_tests
[j
].flags
& DDSD_LPSURFACE
)
5025 ok(U1(ddsd
).dwLinearSize
== ~0u, "Test %u: Got unexpected linear size %#x.\n",
5026 j
, U1(ddsd
).dwLinearSize
);
5028 ok(U1(ddsd
).dwLinearSize
== 2 * 2 * formats
[i
].block_size
,
5029 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
5030 j
, U1(ddsd
).dwLinearSize
, 2 * 2 * formats
[i
].block_size
);
5031 IDirectDrawSurface7_Release(surface
);
5035 HeapFree(GetProcessHeap(), 0, mem
);
5037 IDirectDraw7_Release(ddraw
);
5038 IDirect3DDevice7_Release(device
);
5039 DestroyWindow(window
);
5042 struct format_support_check
5044 const DDPIXELFORMAT
*format
;
5048 static HRESULT WINAPI
test_unsupported_formats_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
5050 struct format_support_check
*format
= ctx
;
5052 if (!memcmp(format
->format
, fmt
, sizeof(*fmt
)))
5054 format
->supported
= TRUE
;
5055 return DDENUMRET_CANCEL
;
5058 return DDENUMRET_OK
;
5061 static void test_unsupported_formats(void)
5064 BOOL expect_success
;
5066 IDirectDraw7
*ddraw
;
5068 IDirect3DDevice7
*device
;
5069 IDirectDrawSurface7
*surface
;
5070 DDSURFACEDESC2 ddsd
;
5072 DWORD expected_caps
;
5083 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
5084 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
5090 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
5091 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
5095 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
5097 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5098 0, 0, 640, 480, 0, 0, 0, 0);
5100 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5102 skip("Failed to create a 3D device, skipping test.\n");
5103 DestroyWindow(window
);
5107 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
5108 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5109 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
5110 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5111 IDirect3D7_Release(d3d
);
5113 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
5115 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
5116 hr
= IDirect3DDevice7_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
5117 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
5119 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
5121 memset(&ddsd
, 0, sizeof(ddsd
));
5122 ddsd
.dwSize
= sizeof(ddsd
);
5123 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5124 U4(ddsd
).ddpfPixelFormat
= formats
[i
].fmt
;
5127 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
5129 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
5130 expect_success
= FALSE
;
5132 expect_success
= TRUE
;
5134 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5135 ok(SUCCEEDED(hr
) == expect_success
,
5136 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
5137 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
5141 memset(&ddsd
, 0, sizeof(ddsd
));
5142 ddsd
.dwSize
= sizeof(ddsd
);
5143 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
5144 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5146 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
5147 expected_caps
= DDSCAPS_VIDEOMEMORY
;
5148 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
5149 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
5150 else if (check
.supported
)
5151 expected_caps
= DDSCAPS_VIDEOMEMORY
;
5153 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
5155 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
5156 "Expected capability %#x, format %s, input cap %#x.\n",
5157 expected_caps
, formats
[i
].name
, caps
[j
]);
5159 IDirectDrawSurface7_Release(surface
);
5163 IDirectDraw7_Release(ddraw
);
5164 IDirect3DDevice7_Release(device
);
5165 DestroyWindow(window
);
5168 static void test_rt_caps(void)
5170 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
5171 PALETTEENTRY palette_entries
[256];
5172 IDirectDrawPalette
*palette
;
5173 IDirectDraw7
*ddraw
;
5174 BOOL hal_ok
= FALSE
;
5175 DDPIXELFORMAT z_fmt
;
5182 static const DDPIXELFORMAT p8_fmt
=
5184 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
5185 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
5190 const DDPIXELFORMAT
*pf
;
5193 HRESULT create_device_hr
;
5194 HRESULT set_rt_hr
, alternative_set_rt_hr
;
5200 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
5201 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5208 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5209 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5216 DDSCAPS_OFFSCREENPLAIN
,
5217 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5224 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5225 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5226 D3DERR_SURFACENOTINVIDMEM
,
5227 DDERR_INVALIDPARAMS
,
5232 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5233 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5240 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
5241 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5249 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5257 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5264 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5265 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5266 D3DERR_SURFACENOTINVIDMEM
,
5267 DDERR_INVALIDPARAMS
,
5272 DDSCAPS_SYSTEMMEMORY
,
5273 DDSCAPS_SYSTEMMEMORY
,
5281 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5288 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5290 DDERR_NOPALETTEATTACHED
,
5296 DDSCAPS_OFFSCREENPLAIN
,
5297 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5304 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5305 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5306 DDERR_NOPALETTEATTACHED
,
5312 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5313 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5320 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
5321 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5323 DDERR_INVALIDPIXELFORMAT
,
5324 DDERR_INVALIDPIXELFORMAT
,
5328 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5329 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5331 DDERR_INVALIDPIXELFORMAT
,
5332 DDERR_INVALIDPIXELFORMAT
,
5337 DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5344 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5345 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5347 DDERR_INVALIDPARAMS
,
5348 DDERR_INVALIDPIXELFORMAT
,
5352 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
5353 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
5360 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5361 0, 0, 640, 480, 0, 0, 0, 0);
5362 ddraw
= create_ddraw();
5363 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5364 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5365 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5367 if (FAILED(IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
5369 skip("D3D interface is not available, skipping test.\n");
5373 hr
= IDirect3D7_EnumDevices(d3d
, enum_devtype_cb
, &hal_ok
);
5374 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
5376 devtype
= &IID_IDirect3DTnLHalDevice
;
5378 memset(&z_fmt
, 0, sizeof(z_fmt
));
5379 hr
= IDirect3D7_EnumZBufferFormats(d3d
, devtype
, enum_z_fmt
, &z_fmt
);
5380 if (FAILED(hr
) || !z_fmt
.dwSize
)
5382 skip("No depth buffer formats available, skipping test.\n");
5383 IDirect3D7_Release(d3d
);
5387 memset(palette_entries
, 0, sizeof(palette_entries
));
5388 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
5389 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5391 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5393 IDirectDrawSurface7
*surface
, *rt
, *expected_rt
, *tmp
;
5394 DDSURFACEDESC2 surface_desc
;
5395 IDirect3DDevice7
*device
;
5397 memset(&surface_desc
, 0, sizeof(surface_desc
));
5398 surface_desc
.dwSize
= sizeof(surface_desc
);
5399 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5400 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5401 if (test_data
[i
].pf
)
5403 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5404 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
5406 surface_desc
.dwWidth
= 640;
5407 surface_desc
.dwHeight
= 480;
5408 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5409 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5410 i
, test_data
[i
].caps_in
, hr
);
5412 memset(&surface_desc
, 0, sizeof(surface_desc
));
5413 surface_desc
.dwSize
= sizeof(surface_desc
);
5414 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
5415 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5416 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
5417 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5418 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
5420 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5421 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
5422 i
, hr
, test_data
[i
].create_device_hr
);
5425 if (hr
== DDERR_NOPALETTEATTACHED
)
5427 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
5428 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
5429 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5430 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5431 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5433 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5435 IDirectDrawSurface7_Release(surface
);
5437 memset(&surface_desc
, 0, sizeof(surface_desc
));
5438 surface_desc
.dwSize
= sizeof(surface_desc
);
5439 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5440 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5441 surface_desc
.dwWidth
= 640;
5442 surface_desc
.dwHeight
= 480;
5443 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5444 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
5446 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5447 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
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
= test_data
[i
].caps_in
;
5454 if (test_data
[i
].pf
)
5456 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5457 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
5459 surface_desc
.dwWidth
= 640;
5460 surface_desc
.dwHeight
= 480;
5461 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
5462 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5463 i
, test_data
[i
].caps_in
, hr
);
5465 hr
= IDirect3DDevice7_SetRenderTarget(device
, rt
, 0);
5466 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
5467 "Test %u: Got unexpected hr %#x, expected %#x.\n",
5468 i
, hr
, test_data
[i
].set_rt_hr
);
5469 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
5472 expected_rt
= surface
;
5474 hr
= IDirect3DDevice7_GetRenderTarget(device
, &tmp
);
5475 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
5476 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
5478 IDirectDrawSurface7_Release(tmp
);
5479 IDirectDrawSurface7_Release(rt
);
5480 refcount
= IDirect3DDevice7_Release(device
);
5481 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
5482 refcount
= IDirectDrawSurface7_Release(surface
);
5483 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
5486 IDirectDrawPalette_Release(palette
);
5487 IDirect3D7_Release(d3d
);
5490 refcount
= IDirectDraw7_Release(ddraw
);
5491 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5492 DestroyWindow(window
);
5495 static void test_primary_caps(void)
5497 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
5498 IDirectDrawSurface7
*surface
;
5499 DDSURFACEDESC2 surface_desc
;
5500 IDirectDraw7
*ddraw
;
5510 DWORD back_buffer_count
;
5518 DDSCAPS_PRIMARYSURFACE
,
5521 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
5525 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
5532 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
5539 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
5546 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
5553 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
5560 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5567 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5574 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5576 DDERR_NOEXCLUSIVEMODE
,
5580 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5581 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5587 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5588 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5591 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
5594 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5595 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
5601 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5602 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
5609 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5610 0, 0, 640, 480, 0, 0, 0, 0);
5611 ddraw
= create_ddraw();
5612 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5614 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5616 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
5617 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5619 memset(&surface_desc
, 0, sizeof(surface_desc
));
5620 surface_desc
.dwSize
= sizeof(surface_desc
);
5621 surface_desc
.dwFlags
= DDSD_CAPS
;
5622 if (test_data
[i
].back_buffer_count
!= ~0u)
5623 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
5624 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5625 U5(surface_desc
).dwBackBufferCount
= test_data
[i
].back_buffer_count
;
5626 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5627 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
5631 memset(&surface_desc
, 0, sizeof(surface_desc
));
5632 surface_desc
.dwSize
= sizeof(surface_desc
);
5633 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
5634 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5635 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
5636 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5637 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
5639 IDirectDrawSurface7_Release(surface
);
5642 refcount
= IDirectDraw7_Release(ddraw
);
5643 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5644 DestroyWindow(window
);
5647 static void test_surface_lock(void)
5649 IDirectDraw7
*ddraw
;
5650 IDirect3D7
*d3d
= NULL
;
5651 IDirectDrawSurface7
*surface
;
5652 IDirect3DDevice7
*device
;
5656 DDSURFACEDESC2 ddsd
;
5658 DDPIXELFORMAT z_fmt
;
5659 BOOL hal_ok
= FALSE
;
5660 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
5661 D3DDEVICEDESC7 device_desc
;
5662 BOOL cubemap_supported
;
5672 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
5674 "videomemory offscreenplain"
5677 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5679 "systemmemory offscreenplain"
5682 DDSCAPS_PRIMARYSURFACE
,
5687 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
5689 "videomemory texture"
5692 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
5694 "opaque videomemory texture"
5697 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
5699 "systemmemory texture"
5703 DDSCAPS2_TEXTUREMANAGE
,
5708 DDSCAPS2_D3DTEXTUREMANAGE
,
5713 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
5714 "opaque managed texture"
5718 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
5719 "opaque managed texture"
5722 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5732 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_VIDEOMEMORY
,
5733 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5737 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_VIDEOMEMORY
,
5738 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
5739 "opaque videomemory cube"
5742 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_SYSTEMMEMORY
,
5743 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5747 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5748 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5752 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5753 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5757 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5758 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
5759 "opaque managed cube"
5762 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5763 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
5764 "opaque managed cube"
5768 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5769 0, 0, 640, 480, 0, 0, 0, 0);
5770 ddraw
= create_ddraw();
5771 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5772 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5773 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5775 if (FAILED(IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
5777 skip("D3D interface is not available, skipping test.\n");
5781 hr
= IDirect3D7_EnumDevices(d3d
, enum_devtype_cb
, &hal_ok
);
5782 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
5784 devtype
= &IID_IDirect3DTnLHalDevice
;
5786 memset(&z_fmt
, 0, sizeof(z_fmt
));
5787 hr
= IDirect3D7_EnumZBufferFormats(d3d
, devtype
, enum_z_fmt
, &z_fmt
);
5788 if (FAILED(hr
) || !z_fmt
.dwSize
)
5790 skip("No depth buffer formats available, skipping test.\n");
5794 memset(&ddsd
, 0, sizeof(ddsd
));
5795 ddsd
.dwSize
= sizeof(ddsd
);
5796 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5799 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5800 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5801 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5803 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5804 ok(SUCCEEDED(hr
), "Failed to create device, hr %#x.\n", hr
);
5805 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
5806 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
5807 cubemap_supported
= !!(device_desc
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
);
5808 IDirect3DDevice7_Release(device
);
5810 IDirectDrawSurface7_Release(surface
);
5812 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5814 if (!cubemap_supported
&& tests
[i
].caps2
& DDSCAPS2_CUBEMAP
)
5817 memset(&ddsd
, 0, sizeof(ddsd
));
5818 ddsd
.dwSize
= sizeof(ddsd
);
5819 ddsd
.dwFlags
= DDSD_CAPS
;
5820 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5822 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5826 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
5828 ddsd
.dwFlags
|= DDSD_PIXELFORMAT
;
5829 U4(ddsd
).ddpfPixelFormat
= z_fmt
;
5831 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
5832 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
5834 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5835 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5837 memset(&ddsd
, 0, sizeof(ddsd
));
5838 ddsd
.dwSize
= sizeof(ddsd
);
5839 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
5840 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5843 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5844 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5847 IDirectDrawSurface7_Release(surface
);
5852 IDirect3D7_Release(d3d
);
5853 refcount
= IDirectDraw7_Release(ddraw
);
5854 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5855 DestroyWindow(window
);
5858 static void test_surface_discard(void)
5860 IDirect3DDevice7
*device
;
5862 IDirectDraw7
*ddraw
;
5865 DDSURFACEDESC2 ddsd
;
5866 IDirectDrawSurface7
*surface
, *target
;
5875 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
5876 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
5877 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
5878 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
5879 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
},
5880 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
5881 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
},
5882 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
5886 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5887 0, 0, 640, 480, 0, 0, 0, 0);
5889 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5891 skip("Failed to create a 3D device, skipping test.\n");
5892 DestroyWindow(window
);
5895 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
5896 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5897 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
5898 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5899 hr
= IDirect3DDevice7_GetRenderTarget(device
, &target
);
5900 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
5902 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5906 memset(&ddsd
, 0, sizeof(ddsd
));
5907 ddsd
.dwSize
= sizeof(ddsd
);
5908 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5909 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
5910 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
5913 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5914 ok(SUCCEEDED(hr
), "Failed to create offscreen surface, hr %#x, case %u.\n", hr
, i
);
5916 memset(&ddsd
, 0, sizeof(ddsd
));
5917 ddsd
.dwSize
= sizeof(ddsd
);
5918 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
5919 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5920 addr
= ddsd
.lpSurface
;
5921 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5922 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5924 memset(&ddsd
, 0, sizeof(ddsd
));
5925 ddsd
.dwSize
= sizeof(ddsd
);
5926 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
5927 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5928 discarded
= ddsd
.lpSurface
!= addr
;
5929 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5930 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5932 hr
= IDirectDrawSurface7_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
5933 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
5935 memset(&ddsd
, 0, sizeof(ddsd
));
5936 ddsd
.dwSize
= sizeof(ddsd
);
5937 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
5938 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5939 discarded
|= ddsd
.lpSurface
!= addr
;
5940 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5941 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5943 IDirectDrawSurface7_Release(surface
);
5945 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
5946 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
5947 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
5950 IDirectDrawSurface7_Release(target
);
5951 IDirectDraw7_Release(ddraw
);
5952 IDirect3D7_Release(d3d
);
5953 IDirect3DDevice7_Release(device
);
5954 DestroyWindow(window
);
5957 static void test_flip(void)
5959 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
5960 IDirectDrawSurface7
*frontbuffer
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
5961 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
5962 DDSURFACEDESC2 surface_desc
;
5963 D3DDEVICEDESC7 device_desc
;
5964 IDirect3DDevice7
*device
;
5965 BOOL sysmem_primary
;
5966 IDirectDraw7
*ddraw
;
5967 DWORD expected_caps
;
5982 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE
},
5983 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN
},
5984 {"TEXTURE", DDSCAPS_TEXTURE
},
5987 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5988 0, 0, 640, 480, 0, 0, 0, 0);
5989 ddraw
= create_ddraw();
5990 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5992 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5993 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5995 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5997 memset(&surface_desc
, 0, sizeof(surface_desc
));
5998 surface_desc
.dwSize
= sizeof(surface_desc
);
5999 surface_desc
.dwFlags
= DDSD_CAPS
;
6000 if (!(test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
6001 surface_desc
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
6002 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
6003 surface_desc
.dwWidth
= 512;
6004 surface_desc
.dwHeight
= 512;
6005 U5(surface_desc
).dwBackBufferCount
= 3;
6006 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6007 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6009 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_FLIP
;
6010 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
6011 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6012 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6014 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_COMPLEX
;
6015 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_FLIP
;
6016 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6017 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6019 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_COMPLEX
;
6020 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6021 if (is_ddraw64
&& test_data
[i
].caps
& DDSCAPS_TEXTURE
)
6022 todo_wine
ok(hr
== E_NOINTERFACE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6023 else todo_wine_if(test_data
[i
].caps
& DDSCAPS_TEXTURE
)
6024 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
6028 memset(&surface_desc
, 0, sizeof(surface_desc
));
6029 surface_desc
.dwSize
= sizeof(surface_desc
);
6030 hr
= IDirectDrawSurface7_GetSurfaceDesc(frontbuffer
, &surface_desc
);
6031 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
6032 expected_caps
= DDSCAPS_FRONTBUFFER
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
6033 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
6034 expected_caps
|= DDSCAPS_VISIBLE
;
6035 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
6036 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
6037 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
6039 hr
= IDirectDrawSurface7_GetAttachedSurface(frontbuffer
, &caps
, &backbuffer1
);
6040 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
6041 memset(&surface_desc
, 0, sizeof(surface_desc
));
6042 surface_desc
.dwSize
= sizeof(surface_desc
);
6043 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer1
, &surface_desc
);
6044 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
6045 ok(!U5(surface_desc
).dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
6046 test_data
[i
].name
, U5(surface_desc
).dwBackBufferCount
);
6047 expected_caps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
);
6048 expected_caps
|= DDSCAPS_BACKBUFFER
;
6049 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
6050 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
6052 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
6053 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
6054 memset(&surface_desc
, 0, sizeof(surface_desc
));
6055 surface_desc
.dwSize
= sizeof(surface_desc
);
6056 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer2
, &surface_desc
);
6057 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
6058 ok(!U5(surface_desc
).dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
6059 test_data
[i
].name
, U5(surface_desc
).dwBackBufferCount
);
6060 expected_caps
&= ~DDSCAPS_BACKBUFFER
;
6061 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
6062 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
6064 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
6065 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
6066 memset(&surface_desc
, 0, sizeof(surface_desc
));
6067 surface_desc
.dwSize
= sizeof(surface_desc
);
6068 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer3
, &surface_desc
);
6069 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
6070 ok(!U5(surface_desc
).dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
6071 test_data
[i
].name
, U5(surface_desc
).dwBackBufferCount
);
6072 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
6073 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
6075 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
6076 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
6077 ok(surface
== frontbuffer
, "%s: Got unexpected surface %p, expected %p.\n",
6078 test_data
[i
].name
, surface
, frontbuffer
);
6079 IDirectDrawSurface7_Release(surface
);
6081 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
6082 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
6083 hr
= IDirectDrawSurface7_IsLost(frontbuffer
);
6084 ok(hr
== DD_OK
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6085 hr
= IDirectDrawSurface7_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
6086 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
6087 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6089 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6090 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6091 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
6092 hr
= IDirectDrawSurface7_IsLost(frontbuffer
);
6093 todo_wine
ok(hr
== DDERR_SURFACELOST
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6094 hr
= IDirectDraw7_RestoreAllSurfaces(ddraw
);
6095 ok(SUCCEEDED(hr
), "%s: Failed to restore surfaces, hr %#x.\n", test_data
[i
].name
, hr
);
6097 memset(&surface_desc
, 0, sizeof(surface_desc
));
6098 surface_desc
.dwSize
= sizeof(surface_desc
);
6099 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6100 surface_desc
.ddsCaps
.dwCaps
= 0;
6101 surface_desc
.dwWidth
= 640;
6102 surface_desc
.dwHeight
= 480;
6103 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6104 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
6105 hr
= IDirectDrawSurface7_Flip(frontbuffer
, surface
, DDFLIP_WAIT
);
6106 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6107 IDirectDrawSurface7_Release(surface
);
6109 hr
= IDirectDrawSurface7_Flip(frontbuffer
, frontbuffer
, DDFLIP_WAIT
);
6110 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6111 hr
= IDirectDrawSurface7_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
6112 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6113 hr
= IDirectDrawSurface7_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
6114 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6115 hr
= IDirectDrawSurface7_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
6116 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6118 memset(&fx
, 0, sizeof(fx
));
6119 fx
.dwSize
= sizeof(fx
);
6120 U5(fx
).dwFillColor
= 0xffff0000;
6121 hr
= IDirectDrawSurface7_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6122 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6123 U5(fx
).dwFillColor
= 0xff00ff00;
6124 hr
= IDirectDrawSurface7_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6125 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6126 U5(fx
).dwFillColor
= 0xff0000ff;
6127 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6128 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6130 hr
= IDirectDrawSurface7_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
6131 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6132 color
= get_surface_color(backbuffer1
, 320, 240);
6133 /* The testbot seems to just copy the contents of one surface to all the
6134 * others, instead of properly flipping. */
6135 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6136 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6137 color
= get_surface_color(backbuffer2
, 320, 240);
6138 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6139 U5(fx
).dwFillColor
= 0xffff0000;
6140 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6141 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6143 hr
= IDirectDrawSurface7_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
6144 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6145 color
= get_surface_color(backbuffer1
, 320, 240);
6146 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6147 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6148 color
= get_surface_color(backbuffer2
, 320, 240);
6149 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6150 U5(fx
).dwFillColor
= 0xff00ff00;
6151 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6152 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6154 hr
= IDirectDrawSurface7_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
6155 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6156 color
= get_surface_color(backbuffer1
, 320, 240);
6157 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6158 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6159 color
= get_surface_color(backbuffer2
, 320, 240);
6160 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6161 U5(fx
).dwFillColor
= 0xff0000ff;
6162 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6163 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6165 hr
= IDirectDrawSurface7_Flip(frontbuffer
, backbuffer1
, DDFLIP_WAIT
);
6166 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6167 color
= get_surface_color(backbuffer2
, 320, 240);
6168 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6169 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6170 color
= get_surface_color(backbuffer3
, 320, 240);
6171 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6172 U5(fx
).dwFillColor
= 0xffff0000;
6173 hr
= IDirectDrawSurface7_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6174 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6176 hr
= IDirectDrawSurface7_Flip(frontbuffer
, backbuffer2
, DDFLIP_WAIT
);
6177 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6178 color
= get_surface_color(backbuffer1
, 320, 240);
6179 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6180 color
= get_surface_color(backbuffer3
, 320, 240);
6181 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6182 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6183 U5(fx
).dwFillColor
= 0xff00ff00;
6184 hr
= IDirectDrawSurface7_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6185 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6187 hr
= IDirectDrawSurface7_Flip(frontbuffer
, backbuffer3
, DDFLIP_WAIT
);
6188 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6189 color
= get_surface_color(backbuffer1
, 320, 240);
6190 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6191 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6192 color
= get_surface_color(backbuffer2
, 320, 240);
6193 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6195 IDirectDrawSurface7_Release(backbuffer3
);
6196 IDirectDrawSurface7_Release(backbuffer2
);
6197 IDirectDrawSurface7_Release(backbuffer1
);
6198 IDirectDrawSurface7_Release(frontbuffer
);
6201 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
6203 skip("Failed to create 3D device.\n");
6206 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
6207 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
6208 IDirect3DDevice7_Release(device
);
6209 if (!(device_desc
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
6211 skip("Cubemaps are not supported.\n");
6215 memset(&surface_desc
, 0, sizeof(surface_desc
));
6216 surface_desc
.dwSize
= sizeof(surface_desc
);
6217 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6218 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_TEXTURE
;
6219 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
;
6220 surface_desc
.dwWidth
= 128;
6221 surface_desc
.dwHeight
= 128;
6222 surface_desc
.dwBackBufferCount
= 3;
6223 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6224 ok(hr
== DDERR_INVALIDCAPS
, "Got unexpected hr %#x.\n", hr
);
6226 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_FLIP
;
6227 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
6228 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6229 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6231 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_COMPLEX
;
6232 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_FLIP
;
6233 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6234 ok(hr
== DDERR_INVALIDCAPS
, "Got unexpected hr %#x.\n", hr
);
6236 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_COMPLEX
;
6237 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6238 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6240 surface_desc
.dwBackBufferCount
= 1;
6241 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6242 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6244 surface_desc
.dwBackBufferCount
= 0;
6245 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6246 ok(hr
== DDERR_INVALIDCAPS
, "Got unexpected hr %#x.\n", hr
);
6249 refcount
= IDirectDraw7_Release(ddraw
);
6250 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
6251 DestroyWindow(window
);
6254 static void reset_ddsd(DDSURFACEDESC2
*ddsd
)
6256 memset(ddsd
, 0, sizeof(*ddsd
));
6257 ddsd
->dwSize
= sizeof(*ddsd
);
6260 static void test_set_surface_desc(void)
6262 IDirectDraw7
*ddraw
;
6265 DDSURFACEDESC2 ddsd
;
6266 IDirectDrawSurface7
*surface
;
6276 invalid_caps_tests
[] =
6278 {DDSCAPS_VIDEOMEMORY
, 0, FALSE
, "videomemory plain"},
6279 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, TRUE
, "systemmemory texture"},
6280 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
, "managed texture"},
6281 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
, "managed texture"},
6282 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
, "systemmemory primary"},
6285 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6286 0, 0, 640, 480, 0, 0, 0, 0);
6287 ddraw
= create_ddraw();
6288 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6289 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6290 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6293 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6296 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6297 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6298 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6299 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6300 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6301 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6302 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6304 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6305 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6308 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6309 ddsd
.lpSurface
= data
;
6310 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6311 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6313 /* Redundantly setting the same lpSurface is not an error. */
6314 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6315 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6317 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6318 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6319 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6320 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
6322 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
6323 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6324 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6325 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
6326 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
6327 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6330 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6331 ddsd
.lpSurface
= data
;
6332 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 1);
6333 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
6335 ddsd
.lpSurface
= NULL
;
6336 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6337 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
6339 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, NULL
, 0);
6340 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
6342 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6343 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6344 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6345 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6346 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6348 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
6349 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6350 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
6352 ddsd
.dwFlags
= DDSD_CAPS
;
6353 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6354 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6356 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
6357 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
6358 ddsd
.lpSurface
= data
;
6359 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6360 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6361 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6362 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6363 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6364 ddsd
.ddsCaps
.dwCaps
= 0;
6365 ddsd
.ddsCaps
.dwCaps2
= 0xdeadbeef;
6366 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6367 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6369 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6370 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6371 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6372 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6373 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6375 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
6377 ddsd
.dwFlags
= DDSD_HEIGHT
;
6379 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6380 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
6382 ddsd
.lpSurface
= data
;
6383 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
6384 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6385 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6388 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6389 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
6392 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6393 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
6394 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6395 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6397 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
6399 ddsd
.dwFlags
= DDSD_PITCH
;
6400 U1(ddsd
).lPitch
= 8 * 4;
6401 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6402 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
6404 ddsd
.dwFlags
= DDSD_WIDTH
;
6406 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6407 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
6409 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
6410 ddsd
.lpSurface
= data
;
6411 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6412 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
6414 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
6415 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6416 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
6418 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6419 U1(ddsd
).lPitch
= 16 * 4;
6421 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6422 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6425 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6426 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6427 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6428 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6429 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
6431 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
6433 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
6434 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6435 U1(ddsd
).lPitch
= 4 * 4;
6436 ddsd
.lpSurface
= data
;
6437 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6438 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6440 U1(ddsd
).lPitch
= 4;
6441 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6442 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6444 U1(ddsd
).lPitch
= 16 * 4 + 1;
6445 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6446 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6448 U1(ddsd
).lPitch
= 16 * 4 + 3;
6449 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6450 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6452 U1(ddsd
).lPitch
= -4;
6453 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6454 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
6456 U1(ddsd
).lPitch
= 16 * 4;
6457 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6458 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6461 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6462 U1(ddsd
).lPitch
= 0;
6464 ddsd
.lpSurface
= data
;
6465 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6466 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
6468 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6469 U1(ddsd
).lPitch
= 16 * 4;
6471 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6472 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
6474 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
6475 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
6476 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6477 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6478 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6479 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6480 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6481 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6482 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6483 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
6485 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
6486 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6487 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6489 /* Can't set color keys. */
6491 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
6492 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
6493 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
6494 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6495 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6497 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
6498 ddsd
.lpSurface
= data
;
6499 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6500 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6502 IDirectDrawSurface7_Release(surface
);
6504 /* SetSurfaceDesc needs systemmemory surfaces.
6506 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
6507 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
6510 ddsd
.dwFlags
= DDSD_CAPS
;
6511 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
6512 ddsd
.ddsCaps
.dwCaps2
= invalid_caps_tests
[i
].caps2
;
6513 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
6515 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6518 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6519 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6520 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6521 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6522 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6523 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6526 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6527 if (is_ddraw64
&& (invalid_caps_tests
[i
].caps
& DDSCAPS_TEXTURE
))
6528 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
6530 ok(hr
== DD_OK
|| hr
== DDERR_NODIRECTDRAWHW
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
6535 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6536 ddsd
.lpSurface
= data
;
6537 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6538 if (invalid_caps_tests
[i
].supported
)
6540 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6544 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6545 invalid_caps_tests
[i
].name
, hr
);
6547 /* Check priority of error conditions. */
6548 ddsd
.dwFlags
= DDSD_WIDTH
;
6549 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6550 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6551 invalid_caps_tests
[i
].name
, hr
);
6554 IDirectDrawSurface7_Release(surface
);
6557 ref
= IDirectDraw7_Release(ddraw
);
6558 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6559 DestroyWindow(window
);
6562 static void test_user_memory_getdc(void)
6564 IDirectDraw7
*ddraw
;
6567 DDSURFACEDESC2 ddsd
;
6568 IDirectDrawSurface7
*surface
;
6577 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6578 0, 0, 640, 480, 0, 0, 0, 0);
6579 ddraw
= create_ddraw();
6580 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6581 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6582 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6585 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6588 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6589 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6590 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6591 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6592 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6593 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6594 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6595 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6596 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6598 memset(data
, 0xaa, sizeof(data
));
6600 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6601 ddsd
.lpSurface
= data
;
6602 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6603 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6605 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
6606 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6607 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
6608 ok(!!bitmap
, "Failed to get bitmap.\n");
6609 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
6610 ok(size
== sizeof(dib
), "Got unexpected size %d.\n", size
);
6611 ok(dib
.dsBm
.bmBits
== data
, "Got unexpected bits %p, expected %p.\n", dib
.dsBm
.bmBits
, data
);
6612 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
6613 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
6614 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
6615 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6617 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
6618 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
6620 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
6621 ddsd
.lpSurface
= data
;
6624 U1(ddsd
).lPitch
= sizeof(*data
);
6625 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6626 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6628 memset(data
, 0xaa, sizeof(data
));
6629 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
6630 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6631 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
6632 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
6633 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
6634 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6636 for (y
= 0; y
< 4; y
++)
6638 for (x
= 0; x
< 4; x
++)
6640 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
6641 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6644 ok(data
[y
][x
] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6648 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6650 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6652 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6654 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6657 IDirectDrawSurface7_Release(surface
);
6658 ref
= IDirectDraw7_Release(ddraw
);
6659 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6660 DestroyWindow(window
);
6663 static void test_sysmem_overlay(void)
6665 IDirectDraw7
*ddraw
;
6668 DDSURFACEDESC2 ddsd
;
6669 IDirectDrawSurface7
*surface
;
6672 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6673 0, 0, 640, 480, 0, 0, 0, 0);
6674 ddraw
= create_ddraw();
6675 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6676 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6677 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6680 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
6683 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
6684 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6685 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6686 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6687 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6688 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6689 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6690 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6691 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
6693 ref
= IDirectDraw7_Release(ddraw
);
6694 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6695 DestroyWindow(window
);
6698 static void test_primary_palette(void)
6700 DDSCAPS2 surface_caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
6701 IDirectDrawSurface7
*primary
, *backbuffer
;
6702 PALETTEENTRY palette_entries
[256];
6703 IDirectDrawPalette
*palette
, *tmp
;
6704 DDSURFACEDESC2 surface_desc
;
6705 IDirectDraw7
*ddraw
;
6711 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6712 0, 0, 640, 480, 0, 0, 0, 0);
6713 ddraw
= create_ddraw();
6714 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6715 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
6717 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6718 IDirectDraw7_Release(ddraw
);
6719 DestroyWindow(window
);
6722 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6723 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6725 memset(&surface_desc
, 0, sizeof(surface_desc
));
6726 surface_desc
.dwSize
= sizeof(surface_desc
);
6727 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6728 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6729 U5(surface_desc
).dwBackBufferCount
= 1;
6730 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6731 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6732 hr
= IDirectDrawSurface7_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
6733 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6735 memset(palette_entries
, 0, sizeof(palette_entries
));
6736 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
6737 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6738 refcount
= get_refcount((IUnknown
*)palette
);
6739 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6741 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6742 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6743 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6745 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
6746 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6748 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6749 * and is generally somewhat broken with respect to 8 bpp / palette
6751 if (SUCCEEDED(IDirectDrawSurface7_GetPalette(backbuffer
, &tmp
)))
6753 win_skip("Broken palette handling detected, skipping tests.\n");
6754 IDirectDrawPalette_Release(tmp
);
6755 IDirectDrawPalette_Release(palette
);
6756 /* The Windows 8 testbot keeps extra references to the primary and
6757 * backbuffer while in 8 bpp mode. */
6758 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
6759 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
6763 refcount
= get_refcount((IUnknown
*)palette
);
6764 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6766 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6767 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6768 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
6769 "Got unexpected palette caps %#x.\n", palette_caps
);
6771 hr
= IDirectDrawSurface7_SetPalette(primary
, NULL
);
6772 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6773 refcount
= get_refcount((IUnknown
*)palette
);
6774 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6776 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6777 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6778 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6780 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
6781 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6782 refcount
= get_refcount((IUnknown
*)palette
);
6783 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6785 hr
= IDirectDrawSurface7_GetPalette(primary
, &tmp
);
6786 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6787 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
6788 IDirectDrawPalette_Release(tmp
);
6789 hr
= IDirectDrawSurface7_GetPalette(backbuffer
, &tmp
);
6790 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6792 refcount
= IDirectDrawPalette_Release(palette
);
6793 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6794 refcount
= IDirectDrawPalette_Release(palette
);
6795 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6797 /* Note that this only seems to work when the palette is attached to the
6798 * primary surface. When attached to a regular surface, attempting to get
6799 * the palette here will cause an access violation. */
6800 hr
= IDirectDrawSurface7_GetPalette(primary
, &tmp
);
6801 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6804 refcount
= IDirectDrawSurface7_Release(backbuffer
);
6805 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6806 refcount
= IDirectDrawSurface7_Release(primary
);
6807 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6808 refcount
= IDirectDraw7_Release(ddraw
);
6809 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6810 DestroyWindow(window
);
6813 static HRESULT WINAPI
surface_counter(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
6815 UINT
*surface_count
= context
;
6818 IDirectDrawSurface_Release(surface
);
6820 return DDENUMRET_OK
;
6823 static void test_surface_attachment(void)
6825 IDirectDrawSurface7
*surface1
, *surface2
, *surface3
, *surface4
;
6826 IDirectDrawSurface
*surface1v1
, *surface2v1
;
6827 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, {0}};
6828 DDSURFACEDESC2 surface_desc
;
6829 IDirectDraw7
*ddraw
;
6835 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6836 0, 0, 640, 480, 0, 0, 0, 0);
6837 ddraw
= create_ddraw();
6838 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6839 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6840 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6842 memset(&surface_desc
, 0, sizeof(surface_desc
));
6843 surface_desc
.dwSize
= sizeof(surface_desc
);
6844 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
6845 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6846 U2(surface_desc
).dwMipMapCount
= 3;
6847 surface_desc
.dwWidth
= 128;
6848 surface_desc
.dwHeight
= 128;
6849 if (FAILED(IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
)))
6851 skip("Failed to create a texture, skipping tests.\n");
6852 IDirectDraw7_Release(ddraw
);
6853 DestroyWindow(window
);
6857 hr
= IDirectDrawSurface7_GetAttachedSurface(surface1
, &caps
, &surface2
);
6858 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6859 hr
= IDirectDrawSurface7_GetAttachedSurface(surface2
, &caps
, &surface3
);
6860 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6861 hr
= IDirectDrawSurface7_GetAttachedSurface(surface3
, &caps
, &surface4
);
6862 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6865 IDirectDrawSurface7_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
6866 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6868 IDirectDrawSurface7_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
6869 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6871 IDirectDrawSurface7_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
6872 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
6874 memset(&surface_desc
, 0, sizeof(surface_desc
));
6875 surface_desc
.dwSize
= sizeof(surface_desc
);
6876 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6877 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6878 surface_desc
.dwWidth
= 16;
6879 surface_desc
.dwHeight
= 16;
6880 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6881 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6883 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
6884 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6885 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
6886 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6887 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
);
6888 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6889 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
6890 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6891 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
);
6892 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6893 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
6894 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6896 IDirectDrawSurface7_Release(surface4
);
6898 memset(&surface_desc
, 0, sizeof(surface_desc
));
6899 surface_desc
.dwSize
= sizeof(surface_desc
);
6900 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6901 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6902 surface_desc
.dwWidth
= 16;
6903 surface_desc
.dwHeight
= 16;
6904 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6905 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6907 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
6908 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6909 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
6910 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6911 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
);
6912 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6913 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
6914 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6915 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
);
6916 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6917 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
6918 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6920 IDirectDrawSurface7_Release(surface4
);
6921 IDirectDrawSurface7_Release(surface3
);
6922 IDirectDrawSurface7_Release(surface2
);
6923 IDirectDrawSurface7_Release(surface1
);
6925 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6926 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6928 /* Try a single primary and two offscreen plain surfaces. */
6929 memset(&surface_desc
, 0, sizeof(surface_desc
));
6930 surface_desc
.dwSize
= sizeof(surface_desc
);
6931 surface_desc
.dwFlags
= DDSD_CAPS
;
6932 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6933 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6934 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6936 memset(&surface_desc
, 0, sizeof(surface_desc
));
6937 surface_desc
.dwSize
= sizeof(surface_desc
);
6938 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6939 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6940 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6941 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6942 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
6943 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6945 memset(&surface_desc
, 0, sizeof(surface_desc
));
6946 surface_desc
.dwSize
= sizeof(surface_desc
);
6947 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6948 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6949 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6950 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6951 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6952 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6954 /* This one has a different size. */
6955 memset(&surface_desc
, 0, sizeof(surface_desc
));
6956 surface_desc
.dwSize
= sizeof(surface_desc
);
6957 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6958 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6959 surface_desc
.dwWidth
= 128;
6960 surface_desc
.dwHeight
= 128;
6961 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6962 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6964 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
6965 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6966 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface1
);
6967 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6968 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface3
);
6969 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6970 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
6971 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6972 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
6973 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6975 IDirectDrawSurface7_Release(surface4
);
6976 IDirectDrawSurface7_Release(surface3
);
6977 IDirectDrawSurface7_Release(surface2
);
6978 IDirectDrawSurface7_Release(surface1
);
6980 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
6981 memset(&surface_desc
, 0, sizeof(surface_desc
));
6982 surface_desc
.dwSize
= sizeof(surface_desc
);
6983 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6984 surface_desc
.dwWidth
= 64;
6985 surface_desc
.dwHeight
= 64;
6986 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
6987 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6988 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
6989 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
6990 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
6991 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
6992 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
6993 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6994 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6995 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6996 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6998 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
6999 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
7000 U1(U4(surface_desc
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
7001 U3(U4(surface_desc
).ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
7002 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
7003 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7005 hr
= IDirectDrawSurface7_QueryInterface(surface1
, &IID_IDirectDrawSurface
, (void **)&surface1v1
);
7006 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
7007 hr
= IDirectDrawSurface7_QueryInterface(surface2
, &IID_IDirectDrawSurface
, (void **)&surface2v1
);
7008 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
7010 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
7011 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7012 refcount
= get_refcount((IUnknown
*)surface2
);
7013 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
7014 refcount
= get_refcount((IUnknown
*)surface2v1
);
7015 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7016 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
7017 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
7018 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7019 todo_wine
ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7020 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
7021 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
7023 /* Attaching while already attached to other surface. */
7024 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface2
);
7025 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7026 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface3
, 0, surface2
);
7027 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7028 IDirectDrawSurface7_Release(surface3
);
7030 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface2
);
7031 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7032 refcount
= get_refcount((IUnknown
*)surface2
);
7033 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7034 refcount
= get_refcount((IUnknown
*)surface2v1
);
7035 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7037 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
7038 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7039 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7040 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface2
);
7041 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
7042 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
7043 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7044 refcount
= IDirectDrawSurface7_Release(surface2
);
7045 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7046 refcount
= IDirectDrawSurface7_Release(surface1
);
7047 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7049 /* Automatic detachment on release. */
7050 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7051 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7052 refcount
= get_refcount((IUnknown
*)surface2v1
);
7053 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
7054 refcount
= IDirectDrawSurface_Release(surface1v1
);
7055 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7056 refcount
= IDirectDrawSurface_Release(surface2v1
);
7057 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7058 refcount
= IDirectDraw7_Release(ddraw
);
7059 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7060 DestroyWindow(window
);
7063 static void test_private_data(void)
7065 IDirectDraw7
*ddraw
;
7066 IDirectDrawSurface7
*surface
, *surface2
;
7067 DDSURFACEDESC2 surface_desc
;
7068 ULONG refcount
, refcount2
, refcount3
;
7070 DWORD size
= sizeof(ptr
);
7073 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7074 DWORD data
[] = {1, 2, 3, 4};
7076 static const GUID ddraw_private_data_test_guid
=
7081 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
7083 static const GUID ddraw_private_data_test_guid2
=
7088 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
7091 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7092 0, 0, 640, 480, 0, 0, 0, 0);
7093 ddraw
= create_ddraw();
7094 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7095 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7096 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7098 reset_ddsd(&surface_desc
);
7099 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
7100 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
7101 surface_desc
.dwHeight
= 4;
7102 surface_desc
.dwWidth
= 4;
7103 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7104 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7106 /* NULL pointers are not valid, but don't cause a crash. */
7107 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
,
7108 sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
7109 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7110 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 0, 0);
7111 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7112 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 1, 0);
7113 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7115 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
7116 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7117 0, DDSPD_IUNKNOWNPOINTER
);
7118 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7119 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7120 5, DDSPD_IUNKNOWNPOINTER
);
7121 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7122 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7123 sizeof(ddraw
) * 2, DDSPD_IUNKNOWNPOINTER
);
7124 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7126 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
7127 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
7128 * erases the old content and returns an error. This behavior has
7129 * been fixed in d3d8 and d3d9. Unless an application is found
7130 * that depends on this we don't care about this behavior. */
7131 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7132 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7133 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7134 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7135 0, DDSPD_IUNKNOWNPOINTER
);
7136 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7138 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7139 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7140 hr
= IDirectDrawSurface7_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7141 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7143 refcount
= get_refcount((IUnknown
*)ddraw
);
7144 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7145 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7146 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7147 refcount2
= get_refcount((IUnknown
*)ddraw
);
7148 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7150 hr
= IDirectDrawSurface7_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7151 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7152 refcount2
= get_refcount((IUnknown
*)ddraw
);
7153 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7155 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7156 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7157 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7158 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, surface
,
7159 sizeof(surface
), DDSPD_IUNKNOWNPOINTER
);
7160 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7161 refcount2
= get_refcount((IUnknown
*)ddraw
);
7162 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7164 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7165 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7166 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7167 size
= 2 * sizeof(ptr
);
7168 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7169 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7170 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7171 refcount2
= get_refcount(ptr
);
7172 /* Object is NOT addref'ed by the getter. */
7173 ok(ptr
== (IUnknown
*)ddraw
, "Returned interface pointer is %p, expected %p.\n", ptr
, ddraw
);
7174 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7176 ptr
= (IUnknown
*)0xdeadbeef;
7178 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7179 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7180 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7181 size
= 2 * sizeof(ptr
);
7182 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7183 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7184 ok(size
== 2 * sizeof(ptr
), "Got unexpected size %u.\n", size
);
7186 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7187 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7188 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7189 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7190 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, NULL
, NULL
);
7191 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7193 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, &ptr
, &size
);
7194 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7195 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7196 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
7197 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7198 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7200 refcount3
= IDirectDrawSurface7_Release(surface
);
7201 ok(!refcount3
, "Got unexpected refcount %u.\n", refcount3
);
7203 /* Destroying the surface frees the reference held on the private data. It also frees
7204 * the reference the surface is holding on its creating object. */
7205 refcount2
= get_refcount((IUnknown
*)ddraw
);
7206 ok(refcount2
== refcount
- 1, "Got unexpected refcount %u.\n", refcount2
);
7208 memset(&hal_caps
, 0, sizeof(hal_caps
));
7209 hal_caps
.dwSize
= sizeof(hal_caps
);
7210 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7211 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7212 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) == (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)
7215 reset_ddsd(&surface_desc
);
7216 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_MIPMAPCOUNT
;
7217 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7218 surface_desc
.dwHeight
= 4;
7219 surface_desc
.dwWidth
= 4;
7220 U2(surface_desc
).dwMipMapCount
= 2;
7221 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7222 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7223 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &surface2
);
7224 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7226 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, data
, sizeof(data
), 0);
7227 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7228 hr
= IDirectDrawSurface7_GetPrivateData(surface2
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7229 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7231 IDirectDrawSurface7_Release(surface2
);
7232 IDirectDrawSurface7_Release(surface
);
7235 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7237 refcount
= IDirectDraw7_Release(ddraw
);
7238 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7239 DestroyWindow(window
);
7242 static void test_pixel_format(void)
7244 HWND window
, window2
= NULL
;
7245 HDC hdc
, hdc2
= NULL
;
7247 int format
, test_format
;
7248 PIXELFORMATDESCRIPTOR pfd
;
7249 IDirectDraw7
*ddraw
= NULL
;
7250 IDirectDrawClipper
*clipper
= NULL
;
7251 DDSURFACEDESC2 ddsd
;
7252 IDirectDrawSurface7
*primary
= NULL
;
7256 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7257 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7260 skip("Failed to create window\n");
7264 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7265 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7267 hdc
= GetDC(window
);
7270 skip("Failed to get DC\n");
7275 hdc2
= GetDC(window2
);
7277 gl
= LoadLibraryA("opengl32.dll");
7278 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7280 format
= GetPixelFormat(hdc
);
7281 ok(format
== 0, "new window has pixel format %d\n", format
);
7283 ZeroMemory(&pfd
, sizeof(pfd
));
7284 pfd
.nSize
= sizeof(pfd
);
7286 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
7287 pfd
.iPixelType
= PFD_TYPE_RGBA
;
7288 pfd
.iLayerType
= PFD_MAIN_PLANE
;
7289 format
= ChoosePixelFormat(hdc
, &pfd
);
7292 skip("no pixel format available\n");
7296 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
7298 skip("failed to set pixel format\n");
7302 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
7304 skip("failed to set pixel format on second window\n");
7307 ReleaseDC(window2
, hdc2
);
7312 ddraw
= create_ddraw();
7313 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7315 test_format
= GetPixelFormat(hdc
);
7316 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7318 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7321 skip("Failed to set cooperative level, hr %#x.\n", hr
);
7325 test_format
= GetPixelFormat(hdc
);
7326 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7330 hr
= IDirectDraw7_CreateClipper(ddraw
, 0, &clipper
, NULL
);
7331 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
7332 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
7333 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
7335 test_format
= GetPixelFormat(hdc
);
7336 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7338 test_format
= GetPixelFormat(hdc2
);
7339 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7342 memset(&ddsd
, 0, sizeof(ddsd
));
7343 ddsd
.dwSize
= sizeof(ddsd
);
7344 ddsd
.dwFlags
= DDSD_CAPS
;
7345 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7347 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
7348 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
7350 test_format
= GetPixelFormat(hdc
);
7351 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7355 test_format
= GetPixelFormat(hdc2
);
7356 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7361 hr
= IDirectDrawSurface7_SetClipper(primary
, clipper
);
7362 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
7364 test_format
= GetPixelFormat(hdc
);
7365 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7367 test_format
= GetPixelFormat(hdc2
);
7368 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7371 memset(&fx
, 0, sizeof(fx
));
7372 fx
.dwSize
= sizeof(fx
);
7373 hr
= IDirectDrawSurface7_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7374 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
7376 test_format
= GetPixelFormat(hdc
);
7377 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7381 test_format
= GetPixelFormat(hdc2
);
7382 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7386 if (primary
) IDirectDrawSurface7_Release(primary
);
7387 if (clipper
) IDirectDrawClipper_Release(clipper
);
7388 if (ddraw
) IDirectDraw7_Release(ddraw
);
7389 if (gl
) FreeLibrary(gl
);
7390 if (hdc
) ReleaseDC(window
, hdc
);
7391 if (hdc2
) ReleaseDC(window2
, hdc2
);
7392 if (window
) DestroyWindow(window
);
7393 if (window2
) DestroyWindow(window2
);
7396 static void test_create_surface_pitch(void)
7398 IDirectDrawSurface7
*surface
;
7399 DDSURFACEDESC2 surface_desc
;
7400 IDirectDraw7
*ddraw
;
7420 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7422 DDSD_PITCH
, 0x100, 0x100},
7423 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7424 DDSD_PITCH
, 0x104, DD_OK
,
7425 DDSD_PITCH
, 0x100, 0x100},
7426 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7427 DDSD_PITCH
, 0x0f8, DD_OK
,
7428 DDSD_PITCH
, 0x100, 0x100},
7429 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7430 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7432 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7434 DDSD_PITCH
, 0x100, 0x0fc},
7436 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7437 DDSD_PITCH
, 0x104, DD_OK
,
7438 DDSD_PITCH
, 0x100, 0x0fc},
7439 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7440 DDSD_PITCH
, 0x0f8, DD_OK
,
7441 DDSD_PITCH
, 0x100, 0x0fc},
7442 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7443 DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
7444 DDSD_PITCH
, 0x100, 0x0fc},
7445 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7446 DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
7448 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7449 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7450 DDSD_PITCH
, 0x100, 0x100},
7452 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7453 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fe, DDERR_INVALIDPARAMS
,
7455 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7456 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fc, DD_OK
,
7457 DDSD_PITCH
, 0x0fc, 0x0fc},
7458 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7459 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0f8, DDERR_INVALIDPARAMS
,
7461 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7462 DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x100, DDERR_INVALIDPARAMS
,
7464 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7465 DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x3f00, DDERR_INVALIDPARAMS
,
7468 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7469 DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, 0x100, DD_OK
,
7470 DDSD_PITCH
, 0x100, 0x100},
7471 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
7472 0, 0, DDERR_INVALIDCAPS
,
7474 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7476 DDSD_PITCH
, 0x100, 0 },
7477 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7478 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7480 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
7481 0, 0, DDERR_INVALIDCAPS
,
7484 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7486 DDSD_PITCH
, 0x100, 0 },
7487 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7488 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7489 DDSD_PITCH
, 0x100, 0 },
7491 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
7493 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7494 0, 0, 640, 480, 0, 0, 0, 0);
7495 ddraw
= create_ddraw();
7496 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7497 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7498 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7500 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
7502 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
7504 memset(&surface_desc
, 0, sizeof(surface_desc
));
7505 surface_desc
.dwSize
= sizeof(surface_desc
);
7506 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
7507 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
7508 surface_desc
.dwWidth
= 63;
7509 surface_desc
.dwHeight
= 63;
7510 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
7511 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7512 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7513 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7514 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7515 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7516 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7517 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7518 if (test_data
[i
].flags_in
& DDSD_LPSURFACE
)
7520 HRESULT expected_hr
= SUCCEEDED(test_data
[i
].hr
) ? DDERR_INVALIDPARAMS
: test_data
[i
].hr
;
7521 ok(hr
== expected_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, expected_hr
);
7522 surface_desc
.lpSurface
= mem
;
7523 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7525 if ((test_data
[i
].caps
& DDSCAPS_VIDEOMEMORY
) && hr
== DDERR_NODIRECTDRAWHW
)
7527 if (is_ddraw64
&& (test_data
[i
].caps
& DDSCAPS_TEXTURE
) && SUCCEEDED(test_data
[i
].hr
))
7528 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
7530 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
7534 memset(&surface_desc
, 0, sizeof(surface_desc
));
7535 surface_desc
.dwSize
= sizeof(surface_desc
);
7536 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
7537 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7538 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
7539 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7540 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
7541 /* The pitch for textures seems to be implementation specific. */
7542 if (!(test_data
[i
].caps
& DDSCAPS_TEXTURE
))
7544 if (is_ddraw64
&& test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
7545 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
7546 "Test %u: Got unexpected pitch %u, expected %u.\n",
7547 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
7549 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
7550 "Test %u: Got unexpected pitch %u, expected %u.\n",
7551 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
7553 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
7555 IDirectDrawSurface7_Release(surface
);
7558 HeapFree(GetProcessHeap(), 0, mem
);
7559 refcount
= IDirectDraw7_Release(ddraw
);
7560 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7561 DestroyWindow(window
);
7564 static void test_mipmap(void)
7566 IDirectDrawSurface7
*surface
, *surface2
;
7567 DDSURFACEDESC2 surface_desc
;
7568 IDirectDraw7
*ddraw
;
7573 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7582 DWORD mipmap_count_in
;
7584 DWORD mipmap_count_out
;
7588 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 3, DD_OK
, 3},
7589 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDPARAMS
, 0},
7590 {0, DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 1},
7591 {0, DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDCAPS
, 0},
7592 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 8},
7593 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 32, 64, 0, DD_OK
, 7},
7596 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7597 0, 0, 640, 480, 0, 0, 0, 0);
7598 ddraw
= create_ddraw();
7599 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7600 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7601 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7603 memset(&hal_caps
, 0, sizeof(hal_caps
));
7604 hal_caps
.dwSize
= sizeof(hal_caps
);
7605 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7606 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7607 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)
7610 skip("Mipmapped textures not supported, skipping tests.\n");
7611 IDirectDraw7_Release(ddraw
);
7612 DestroyWindow(window
);
7616 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
7618 memset(&surface_desc
, 0, sizeof(surface_desc
));
7619 surface_desc
.dwSize
= sizeof(surface_desc
);
7620 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| tests
[i
].flags
;
7621 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
7622 surface_desc
.dwWidth
= tests
[i
].width
;
7623 surface_desc
.dwHeight
= tests
[i
].height
;
7624 if (tests
[i
].flags
& DDSD_MIPMAPCOUNT
)
7625 U2(surface_desc
).dwMipMapCount
= tests
[i
].mipmap_count_in
;
7626 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7627 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
7631 memset(&surface_desc
, 0, sizeof(surface_desc
));
7632 surface_desc
.dwSize
= sizeof(surface_desc
);
7633 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
7634 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7635 ok(surface_desc
.dwFlags
& DDSD_MIPMAPCOUNT
,
7636 "Test %u: Got unexpected flags %#x.\n", i
, surface_desc
.dwFlags
);
7637 ok(U2(surface_desc
).dwMipMapCount
== tests
[i
].mipmap_count_out
,
7638 "Test %u: Got unexpected mipmap count %u.\n", i
, U2(surface_desc
).dwMipMapCount
);
7640 if (U2(surface_desc
).dwMipMapCount
> 1)
7642 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &surface2
);
7643 ok(SUCCEEDED(hr
), "Test %u: Failed to get attached surface, hr %#x.\n", i
, hr
);
7645 memset(&surface_desc
, 0, sizeof(surface_desc
));
7646 surface_desc
.dwSize
= sizeof(surface_desc
);
7647 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7648 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
7649 memset(&surface_desc
, 0, sizeof(surface_desc
));
7650 surface_desc
.dwSize
= sizeof(surface_desc
);
7651 hr
= IDirectDrawSurface7_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
7652 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
7653 IDirectDrawSurface7_Unlock(surface2
, NULL
);
7654 IDirectDrawSurface7_Unlock(surface
, NULL
);
7656 IDirectDrawSurface7_Release(surface2
);
7659 IDirectDrawSurface7_Release(surface
);
7662 refcount
= IDirectDraw7_Release(ddraw
);
7663 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7664 DestroyWindow(window
);
7667 static void test_palette_complex(void)
7669 IDirectDrawSurface7
*surface
, *mipmap
, *tmp
;
7670 DDSURFACEDESC2 surface_desc
;
7671 IDirectDraw7
*ddraw
;
7672 IDirectDrawPalette
*palette
, *palette2
;
7676 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7678 PALETTEENTRY palette_entries
[256];
7681 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7682 0, 0, 640, 480, 0, 0, 0, 0);
7683 ddraw
= create_ddraw();
7684 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7685 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7686 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7688 memset(&hal_caps
, 0, sizeof(hal_caps
));
7689 hal_caps
.dwSize
= sizeof(hal_caps
);
7690 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7691 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7692 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)
7695 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7696 IDirectDraw7_Release(ddraw
);
7697 DestroyWindow(window
);
7701 memset(&surface_desc
, 0, sizeof(surface_desc
));
7702 surface_desc
.dwSize
= sizeof(surface_desc
);
7703 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7704 surface_desc
.dwWidth
= 128;
7705 surface_desc
.dwHeight
= 128;
7706 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7707 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7708 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7709 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7710 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7711 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7713 memset(palette_entries
, 0, sizeof(palette_entries
));
7714 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7715 palette_entries
, &palette
, NULL
);
7716 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7718 palette2
= (void *)0xdeadbeef;
7719 hr
= IDirectDrawSurface7_GetPalette(surface
, &palette2
);
7720 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
7721 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
7722 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
7723 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7724 hr
= IDirectDrawSurface7_GetPalette(surface
, &palette2
);
7725 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
7726 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
7727 IDirectDrawPalette_Release(palette2
);
7730 IDirectDrawSurface7_AddRef(mipmap
);
7731 for (i
= 0; i
< 7; ++i
)
7733 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7734 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
7735 palette2
= (void *)0xdeadbeef;
7736 hr
= IDirectDrawSurface7_GetPalette(tmp
, &palette2
);
7737 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7738 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
7740 hr
= IDirectDrawSurface7_SetPalette(tmp
, palette
);
7741 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7743 hr
= IDirectDrawSurface7_GetPalette(tmp
, &palette2
);
7744 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7745 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
7747 /* Ddraw7 uses the palette of the mipmap for GetDC, just like previous
7748 * ddraw versions. Combined with the test results above this means no
7749 * palette is available. So depending on the driver either GetDC fails
7750 * or the DIB color table contains random data. */
7752 IDirectDrawSurface7_Release(mipmap
);
7756 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7757 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7758 IDirectDrawSurface7_Release(mipmap
);
7759 refcount
= IDirectDrawSurface7_Release(surface
);
7760 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7762 /* Test DDERR_INVALIDPIXELFORMAT vs DDERR_NOTONMIPMAPSUBLEVEL. */
7763 memset(&surface_desc
, 0, sizeof(surface_desc
));
7764 surface_desc
.dwSize
= sizeof(surface_desc
);
7765 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7766 surface_desc
.dwWidth
= 128;
7767 surface_desc
.dwHeight
= 128;
7768 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7769 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7770 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7771 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7772 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7773 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7774 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7775 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7776 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7778 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &mipmap
);
7779 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7780 hr
= IDirectDrawSurface7_SetPalette(mipmap
, palette
);
7781 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x.\n", hr
);
7783 IDirectDrawSurface7_Release(mipmap
);
7784 refcount
= IDirectDrawSurface7_Release(surface
);
7785 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7786 refcount
= IDirectDrawPalette_Release(palette
);
7787 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7789 refcount
= IDirectDraw7_Release(ddraw
);
7790 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7791 DestroyWindow(window
);
7794 static BOOL
ddraw_is_warp(IDirectDraw7
*ddraw
)
7796 DDDEVICEIDENTIFIER2 identifier
;
7799 if (!strcmp(winetest_platform
, "wine"))
7802 hr
= IDirectDraw7_GetDeviceIdentifier(ddraw
, &identifier
, 0);
7803 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
7804 return !!strstr(identifier
.szDriver
, "warp");
7807 static void test_p8_blit(void)
7809 IDirectDrawSurface7
*src
, *dst
, *dst_p8
;
7810 DDSURFACEDESC2 surface_desc
;
7811 IDirectDraw7
*ddraw
;
7812 IDirectDrawPalette
*palette
, *palette2
;
7816 PALETTEENTRY palette_entries
[256];
7820 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7821 static const BYTE src_data2
[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
7822 static const BYTE expected_p8
[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
7823 static const D3DCOLOR expected
[] =
7825 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7826 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7830 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7831 0, 0, 640, 480, 0, 0, 0, 0);
7832 ddraw
= create_ddraw();
7833 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7834 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7835 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7836 is_warp
= ddraw_is_warp(ddraw
);
7838 memset(palette_entries
, 0, sizeof(palette_entries
));
7839 palette_entries
[1].peGreen
= 0xff;
7840 palette_entries
[2].peBlue
= 0xff;
7841 palette_entries
[3].peFlags
= 0xff;
7842 palette_entries
[4].peRed
= 0xff;
7843 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7844 palette_entries
, &palette
, NULL
);
7845 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7846 palette_entries
[1].peBlue
= 0xff;
7847 palette_entries
[2].peGreen
= 0xff;
7848 palette_entries
[3].peRed
= 0xff;
7849 palette_entries
[4].peFlags
= 0x0;
7850 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7851 palette_entries
, &palette2
, NULL
);
7852 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7854 memset(&surface_desc
, 0, sizeof(surface_desc
));
7855 surface_desc
.dwSize
= sizeof(surface_desc
);
7856 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7857 surface_desc
.dwWidth
= 8;
7858 surface_desc
.dwHeight
= 1;
7859 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7860 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7861 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7862 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7863 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
7864 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7865 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst_p8
, NULL
);
7866 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7867 hr
= IDirectDrawSurface7_SetPalette(dst_p8
, palette2
);
7868 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7870 memset(&surface_desc
, 0, sizeof(surface_desc
));
7871 surface_desc
.dwSize
= sizeof(surface_desc
);
7872 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7873 surface_desc
.dwWidth
= 8;
7874 surface_desc
.dwHeight
= 1;
7875 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7876 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7877 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
7878 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7879 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7880 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7881 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7882 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
7883 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
7884 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7886 memset(&surface_desc
, 0, sizeof(surface_desc
));
7887 surface_desc
.dwSize
= sizeof(surface_desc
);
7888 hr
= IDirectDrawSurface7_Lock(src
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
7889 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
7890 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
7891 hr
= IDirectDrawSurface7_Unlock(src
, NULL
);
7892 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
7894 hr
= IDirectDrawSurface7_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
7895 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
7896 memcpy(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
));
7897 hr
= IDirectDrawSurface7_Unlock(dst_p8
, NULL
);
7898 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
7900 hr
= IDirectDrawSurface7_SetPalette(src
, palette
);
7901 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7902 hr
= IDirectDrawSurface7_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
7903 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
7904 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
7905 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
7906 "Failed to blit, hr %#x.\n", hr
);
7910 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
7912 color
= get_surface_color(dst
, x
, 0);
7913 todo_wine
ok(compare_color(color
, expected
[x
], 0),
7914 "Pixel %u: Got color %#x, expected %#x.\n",
7915 x
, color
, expected
[x
]);
7919 memset(&fx
, 0, sizeof(fx
));
7920 fx
.dwSize
= sizeof(fx
);
7921 fx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 0x2;
7922 fx
.ddckSrcColorkey
.dwColorSpaceLowValue
= 0x2;
7923 hr
= IDirectDrawSurface7_Blt(dst_p8
, NULL
, src
, NULL
, DDBLT_WAIT
| DDBLT_KEYSRCOVERRIDE
, &fx
);
7924 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
7926 hr
= IDirectDrawSurface7_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
7927 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
7928 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
7929 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
7930 * for example) also works as expected.
7932 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
7933 * the display mode set to P8 doesn't help either. */
7934 ok(!memcmp(surface_desc
.lpSurface
, expected_p8
, sizeof(expected_p8
))
7935 || broken(is_warp
&& !memcmp(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
))),
7936 "Got unexpected P8 color key blit result.\n");
7937 hr
= IDirectDrawSurface7_Unlock(dst_p8
, NULL
);
7938 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
7940 IDirectDrawSurface7_Release(src
);
7941 IDirectDrawSurface7_Release(dst
);
7942 IDirectDrawSurface7_Release(dst_p8
);
7943 IDirectDrawPalette_Release(palette
);
7944 IDirectDrawPalette_Release(palette2
);
7946 refcount
= IDirectDraw7_Release(ddraw
);
7947 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7948 DestroyWindow(window
);
7951 static void test_material(void)
7953 static const D3DCOLORVALUE null_color
;
7954 IDirect3DDevice7
*device
;
7955 D3DMATERIAL7 material
;
7960 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7961 0, 0, 640, 480, 0, 0, 0, 0);
7962 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
7964 skip("Failed to create a 3D device, skipping test.\n");
7965 DestroyWindow(window
);
7969 hr
= IDirect3DDevice7_GetMaterial(device
, &material
);
7970 ok(SUCCEEDED(hr
), "Failed to get material, hr %#x.\n", hr
);
7971 ok(!memcmp(&U(material
).diffuse
, &null_color
, sizeof(null_color
)),
7972 "Got unexpected diffuse color {%.8e, %.8e, %.8e, %.8e}.\n",
7973 U1(U(material
).diffuse
).r
, U2(U(material
).diffuse
).g
,
7974 U3(U(material
).diffuse
).b
, U4(U(material
).diffuse
).a
);
7975 ok(!memcmp(&U1(material
).ambient
, &null_color
, sizeof(null_color
)),
7976 "Got unexpected ambient color {%.8e, %.8e, %.8e, %.8e}.\n",
7977 U1(U1(material
).ambient
).r
, U2(U1(material
).ambient
).g
,
7978 U3(U1(material
).ambient
).b
, U4(U1(material
).ambient
).a
);
7979 ok(!memcmp(&U2(material
).specular
, &null_color
, sizeof(null_color
)),
7980 "Got unexpected specular color {%.8e, %.8e, %.8e, %.8e}.\n",
7981 U1(U2(material
).specular
).r
, U2(U2(material
).specular
).g
,
7982 U3(U2(material
).specular
).b
, U4(U2(material
).specular
).a
);
7983 ok(!memcmp(&U3(material
).emissive
, &null_color
, sizeof(null_color
)),
7984 "Got unexpected emissive color {%.8e, %.8e, %.8e, %.8e}.\n",
7985 U1(U3(material
).emissive
).r
, U2(U3(material
).emissive
).g
,
7986 U3(U3(material
).emissive
).b
, U4(U3(material
).emissive
).a
);
7987 ok(U4(material
).power
== 0.0f
, "Got unexpected power %.8e.\n", U4(material
).power
);
7989 refcount
= IDirect3DDevice7_Release(device
);
7990 ok(!refcount
, "Device has %u references left.\n", refcount
);
7991 DestroyWindow(window
);
7994 static void test_palette_gdi(void)
7996 IDirectDrawSurface7
*surface
, *primary
;
7997 DDSURFACEDESC2 surface_desc
;
7998 IDirectDraw7
*ddraw
;
7999 IDirectDrawPalette
*palette
, *palette2
;
8003 PALETTEENTRY palette_entries
[256];
8009 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
8010 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
8011 * not the point of this test. */
8012 static const RGBQUAD expected1
[] =
8014 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8015 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
8017 static const RGBQUAD expected2
[] =
8019 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8020 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
8022 static const RGBQUAD expected3
[] =
8024 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
8025 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
8027 HPALETTE ddraw_palette_handle
;
8028 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
8029 RGBQUAD rgbquad
[255];
8030 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
8032 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8033 0, 0, 640, 480, 0, 0, 0, 0);
8034 ddraw
= create_ddraw();
8035 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8036 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8037 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8039 memset(&surface_desc
, 0, sizeof(surface_desc
));
8040 surface_desc
.dwSize
= sizeof(surface_desc
);
8041 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8042 surface_desc
.dwWidth
= 16;
8043 surface_desc
.dwHeight
= 16;
8044 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8045 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8046 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
8047 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
8048 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8049 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8051 /* Avoid colors from the Windows default palette. */
8052 memset(palette_entries
, 0, sizeof(palette_entries
));
8053 palette_entries
[1].peRed
= 0x01;
8054 palette_entries
[2].peGreen
= 0x02;
8055 palette_entries
[3].peBlue
= 0x03;
8056 palette_entries
[4].peRed
= 0x13;
8057 palette_entries
[4].peGreen
= 0x14;
8058 palette_entries
[4].peBlue
= 0x15;
8059 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
8060 palette_entries
, &palette
, NULL
);
8061 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8063 /* If there is no palette assigned and the display mode is not 8 bpp, some
8064 * drivers refuse to create a DC while others allow it. If a DC is created,
8065 * the DIB color table is uninitialized and contains random colors. No error
8066 * is generated when trying to read pixels and random garbage is returned.
8068 * The most likely explanation is that if the driver creates a DC, it (or
8069 * the higher-level runtime) uses GetSystemPaletteEntries to find the
8070 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
8071 * contains uninitialized garbage. See comments below for the P8 case. */
8073 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
8074 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8075 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
8076 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8077 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
8078 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
8079 "Got unexpected palette %p, expected %p.\n",
8080 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
8082 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8083 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8084 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
8086 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
8087 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8088 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8089 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
8091 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8093 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8094 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8095 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8098 /* Update the palette while the DC is in use. This does not modify the DC. */
8099 palette_entries
[4].peRed
= 0x23;
8100 palette_entries
[4].peGreen
= 0x24;
8101 palette_entries
[4].peBlue
= 0x25;
8102 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
8103 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
8105 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
8106 ok(i
== 1, "Expected count 1, got %u.\n", i
);
8107 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
8108 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8109 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
8110 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
8112 /* Neither does re-setting the palette. */
8113 hr
= IDirectDrawSurface7_SetPalette(surface
, NULL
);
8114 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8115 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
8116 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8118 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
8119 ok(i
== 1, "Expected count 1, got %u.\n", i
);
8120 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
8121 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8122 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
8123 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
8125 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
8126 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8128 /* Refresh the DC. This updates the palette. */
8129 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
8130 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8131 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8132 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8133 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8135 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8136 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8137 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8138 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8140 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8142 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8143 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8144 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8146 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
8147 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8149 refcount
= IDirectDrawSurface7_Release(surface
);
8150 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8152 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
8153 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8154 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8156 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8157 IDirectDrawPalette_Release(palette
);
8158 IDirectDraw7_Release(ddraw
);
8159 DestroyWindow(window
);
8162 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
8164 memset(&surface_desc
, 0, sizeof(surface_desc
));
8165 surface_desc
.dwSize
= sizeof(surface_desc
);
8166 surface_desc
.dwFlags
= DDSD_CAPS
;
8167 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8168 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
8169 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8171 memset(&fx
, 0, sizeof(fx
));
8172 fx
.dwSize
= sizeof(fx
);
8174 SetRect(&r
, 0, 0, 319, 479);
8175 hr
= IDirectDrawSurface7_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8176 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
8177 SetRect(&r
, 320, 0, 639, 479);
8179 hr
= IDirectDrawSurface7_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8180 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
8182 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
8183 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8184 hr
= IDirectDrawSurface7_GetDC(primary
, &dc
);
8185 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8187 color
= GetPixel(dc
, 160, 240);
8188 ok(color
== 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color
);
8189 color
= GetPixel(dc
, 480, 240);
8190 ok(color
== 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color
);
8192 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
8193 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
8194 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
8195 "Got unexpected palette %p, expected %p.\n",
8196 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
8197 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
8199 /* The primary uses the system palette. In exclusive mode, the system palette matches
8200 * the ddraw palette attached to the primary, so the result is what you would expect
8201 * from a regular surface. Tests for the interaction between the ddraw palette and
8202 * the system palette are not included pending an application that depends on this.
8203 * The relation between those causes problems on Windows Vista and newer for games
8204 * like Age of Empires or StarcCaft. Don't emulate it without a real need. */
8205 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8206 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8207 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8209 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8210 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8211 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8212 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8214 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8216 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8217 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8218 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8220 hr
= IDirectDrawSurface7_ReleaseDC(primary
, dc
);
8221 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8223 memset(&surface_desc
, 0, sizeof(surface_desc
));
8224 surface_desc
.dwSize
= sizeof(surface_desc
);
8225 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8226 surface_desc
.dwWidth
= 16;
8227 surface_desc
.dwHeight
= 16;
8228 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8229 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8230 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8232 /* Here the offscreen surface appears to use the primary's palette,
8233 * but in all likelihood it is actually the system palette. */
8234 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
8235 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8236 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8237 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8238 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8240 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8241 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8242 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8243 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8245 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8247 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8248 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8249 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8251 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
8252 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8254 /* On real hardware a change to the primary surface's palette applies immediately,
8255 * even on device contexts from offscreen surfaces that do not have their own
8256 * palette. On the testbot VMs this is not the case. Don't test this until we
8257 * know of an application that depends on this. */
8259 memset(palette_entries
, 0, sizeof(palette_entries
));
8260 palette_entries
[1].peBlue
= 0x40;
8261 palette_entries
[2].peRed
= 0x40;
8262 palette_entries
[3].peGreen
= 0x40;
8263 palette_entries
[4].peRed
= 0x12;
8264 palette_entries
[4].peGreen
= 0x34;
8265 palette_entries
[4].peBlue
= 0x56;
8266 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
8267 palette_entries
, &palette2
, NULL
);
8268 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8269 hr
= IDirectDrawSurface7_SetPalette(surface
, palette2
);
8270 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8272 /* A palette assigned to the offscreen surface overrides the primary / system
8274 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
8275 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8276 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8277 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8278 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
8280 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
8281 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8282 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8283 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
8285 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8287 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8288 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8289 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8291 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
8292 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8294 refcount
= IDirectDrawSurface7_Release(surface
);
8295 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8297 /* The Windows 8 testbot keeps extra references to the primary and
8298 * backbuffer while in 8 bpp mode. */
8299 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
8300 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8302 refcount
= IDirectDrawSurface7_Release(primary
);
8303 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8304 refcount
= IDirectDrawPalette_Release(palette2
);
8305 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8306 refcount
= IDirectDrawPalette_Release(palette
);
8307 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8308 refcount
= IDirectDraw7_Release(ddraw
);
8309 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8310 DestroyWindow(window
);
8313 static void test_palette_alpha(void)
8315 IDirectDrawSurface7
*surface
;
8316 DDSURFACEDESC2 surface_desc
;
8317 IDirectDraw7
*ddraw
;
8318 IDirectDrawPalette
*palette
;
8322 PALETTEENTRY palette_entries
[256];
8327 BOOL attach_allowed
;
8332 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
8333 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
8334 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
8337 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8338 0, 0, 640, 480, 0, 0, 0, 0);
8339 ddraw
= create_ddraw();
8340 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8341 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8343 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8344 IDirectDraw7_Release(ddraw
);
8345 DestroyWindow(window
);
8348 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8349 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8351 memset(palette_entries
, 0, sizeof(palette_entries
));
8352 palette_entries
[1].peFlags
= 0x42;
8353 palette_entries
[2].peFlags
= 0xff;
8354 palette_entries
[3].peFlags
= 0x80;
8355 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
8356 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8358 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8359 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8360 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8361 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8362 palette_entries
[0].peFlags
);
8363 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8364 palette_entries
[1].peFlags
);
8365 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8366 palette_entries
[2].peFlags
);
8367 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8368 palette_entries
[3].peFlags
);
8370 IDirectDrawPalette_Release(palette
);
8372 memset(palette_entries
, 0, sizeof(palette_entries
));
8373 palette_entries
[1].peFlags
= 0x42;
8374 palette_entries
[1].peRed
= 0xff;
8375 palette_entries
[2].peFlags
= 0xff;
8376 palette_entries
[3].peFlags
= 0x80;
8377 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
8378 palette_entries
, &palette
, NULL
);
8379 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8381 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8382 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8383 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8384 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8385 palette_entries
[0].peFlags
);
8386 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8387 palette_entries
[1].peFlags
);
8388 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8389 palette_entries
[2].peFlags
);
8390 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8391 palette_entries
[3].peFlags
);
8393 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
8395 memset(&surface_desc
, 0, sizeof(surface_desc
));
8396 surface_desc
.dwSize
= sizeof(surface_desc
);
8397 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
8398 surface_desc
.dwWidth
= 128;
8399 surface_desc
.dwHeight
= 128;
8400 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
8401 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8402 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8404 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
8405 if (test_data
[i
].attach_allowed
)
8406 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8408 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8416 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
8417 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8418 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
8419 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
8420 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8421 rgbquad
.rgbRed
, test_data
[i
].name
);
8422 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8423 rgbquad
.rgbGreen
, test_data
[i
].name
);
8424 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8425 rgbquad
.rgbBlue
, test_data
[i
].name
);
8426 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8427 rgbquad
.rgbReserved
, test_data
[i
].name
);
8428 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
8429 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8431 IDirectDrawSurface7_Release(surface
);
8434 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8435 memset(&surface_desc
, 0, sizeof(surface_desc
));
8436 surface_desc
.dwSize
= sizeof(surface_desc
);
8437 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8438 surface_desc
.dwWidth
= 128;
8439 surface_desc
.dwHeight
= 128;
8440 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8441 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8442 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8443 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
8444 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8445 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8446 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8447 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8448 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8449 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
8450 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
8451 IDirectDrawSurface7_Release(surface
);
8453 /* The Windows 8 testbot keeps extra references to the primary
8454 * while in 8 bpp mode. */
8455 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
8456 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8458 refcount
= IDirectDrawPalette_Release(palette
);
8459 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8460 refcount
= IDirectDraw7_Release(ddraw
);
8461 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8462 DestroyWindow(window
);
8465 static void test_vb_writeonly(void)
8467 IDirect3DDevice7
*device
;
8469 IDirect3DVertexBuffer7
*buffer
;
8472 D3DVERTEXBUFFERDESC desc
;
8474 static const struct vec4 quad
[] =
8476 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
8477 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
8478 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
8479 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
8482 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8483 0, 0, 640, 480, 0, 0, 0, 0);
8485 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8487 skip("Failed to create a 3D device, skipping test.\n");
8488 DestroyWindow(window
);
8492 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
8493 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
8495 memset(&desc
, 0, sizeof(desc
));
8496 desc
.dwSize
= sizeof(desc
);
8497 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
8498 desc
.dwFVF
= D3DFVF_XYZRHW
;
8499 desc
.dwNumVertices
= sizeof(quad
) / sizeof(*quad
);
8500 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0);
8501 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
8503 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, &ptr
, NULL
);
8504 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8505 memcpy(ptr
, quad
, sizeof(quad
));
8506 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
8507 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8509 hr
= IDirect3DDevice7_BeginScene(device
);
8510 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8511 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
8512 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8513 hr
= IDirect3DDevice7_EndScene(device
);
8514 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8516 hr
= IDirect3DVertexBuffer7_Lock(buffer
, 0, &ptr
, NULL
);
8517 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8518 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8519 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
8520 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8522 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_READONLY
, &ptr
, NULL
);
8523 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8524 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8525 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
8526 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8528 IDirect3DVertexBuffer7_Release(buffer
);
8529 IDirect3D7_Release(d3d
);
8530 IDirect3DDevice7_Release(device
);
8531 DestroyWindow(window
);
8534 static void test_lost_device(void)
8536 IDirectDrawSurface7
*surface
;
8537 DDSURFACEDESC2 surface_desc
;
8538 HWND window1
, window2
;
8539 IDirectDraw7
*ddraw
;
8544 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8545 0, 0, 640, 480, 0, 0, 0, 0);
8546 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8547 0, 0, 640, 480, 0, 0, 0, 0);
8548 ddraw
= create_ddraw();
8549 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8550 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8551 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8553 memset(&surface_desc
, 0, sizeof(surface_desc
));
8554 surface_desc
.dwSize
= sizeof(surface_desc
);
8555 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8556 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8557 U5(surface_desc
).dwBackBufferCount
= 1;
8558 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8559 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8561 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8562 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8563 hr
= IDirectDrawSurface7_IsLost(surface
);
8564 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8565 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8566 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8568 ret
= SetForegroundWindow(GetDesktopWindow());
8569 ok(ret
, "Failed to set foreground window.\n");
8570 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8571 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8572 hr
= IDirectDrawSurface7_IsLost(surface
);
8573 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8574 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8575 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8577 ret
= SetForegroundWindow(window1
);
8578 ok(ret
, "Failed to set foreground window.\n");
8579 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8580 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8581 hr
= IDirectDrawSurface7_IsLost(surface
);
8582 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8583 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8584 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8586 hr
= IDirectDraw7_RestoreAllSurfaces(ddraw
);
8587 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8588 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8589 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8590 hr
= IDirectDrawSurface7_IsLost(surface
);
8591 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8592 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8593 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8595 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8596 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8597 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8598 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8599 hr
= IDirectDrawSurface7_IsLost(surface
);
8600 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8601 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8602 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8604 /* Trying to restore the primary will crash, probably because flippable
8605 * surfaces can't exist in DDSCL_NORMAL. */
8606 IDirectDrawSurface7_Release(surface
);
8607 memset(&surface_desc
, 0, sizeof(surface_desc
));
8608 surface_desc
.dwSize
= sizeof(surface_desc
);
8609 surface_desc
.dwFlags
= DDSD_CAPS
;
8610 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8611 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8612 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8614 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8615 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8616 hr
= IDirectDrawSurface7_IsLost(surface
);
8617 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8619 ret
= SetForegroundWindow(GetDesktopWindow());
8620 ok(ret
, "Failed to set foreground window.\n");
8621 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8622 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8623 hr
= IDirectDrawSurface7_IsLost(surface
);
8624 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8626 ret
= SetForegroundWindow(window1
);
8627 ok(ret
, "Failed to set foreground window.\n");
8628 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8629 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8630 hr
= IDirectDrawSurface7_IsLost(surface
);
8631 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8633 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8634 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8635 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8636 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8637 hr
= IDirectDrawSurface7_IsLost(surface
);
8638 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8640 hr
= IDirectDraw7_RestoreAllSurfaces(ddraw
);
8641 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8642 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8643 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8644 hr
= IDirectDrawSurface7_IsLost(surface
);
8645 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8647 IDirectDrawSurface7_Release(surface
);
8648 memset(&surface_desc
, 0, sizeof(surface_desc
));
8649 surface_desc
.dwSize
= sizeof(surface_desc
);
8650 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8651 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8652 U5(surface_desc
).dwBackBufferCount
= 1;
8653 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8654 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8656 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8657 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8658 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8659 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8660 hr
= IDirectDrawSurface7_IsLost(surface
);
8661 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8662 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8663 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8665 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8666 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8667 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8668 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8669 hr
= IDirectDrawSurface7_IsLost(surface
);
8670 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8671 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8672 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8674 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8675 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8676 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8677 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8678 hr
= IDirectDrawSurface7_IsLost(surface
);
8679 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8680 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8681 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8683 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
8684 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8685 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8686 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8687 hr
= IDirectDrawSurface7_IsLost(surface
);
8688 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8689 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8690 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8692 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8693 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8694 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8695 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8696 hr
= IDirectDrawSurface7_IsLost(surface
);
8697 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8698 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8699 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8701 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8702 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8703 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8704 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8705 hr
= IDirectDrawSurface7_IsLost(surface
);
8706 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8707 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8708 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8710 IDirectDrawSurface7_Release(surface
);
8711 refcount
= IDirectDraw7_Release(ddraw
);
8712 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8713 DestroyWindow(window2
);
8714 DestroyWindow(window1
);
8717 static void test_resource_priority(void)
8719 IDirectDrawSurface7
*surface
, *mipmap
;
8720 DDSURFACEDESC2 surface_desc
;
8721 IDirectDraw7
*ddraw
;
8725 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
8727 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_MIPMAP
;
8735 /* SetPriority on offscreenplain surfaces crashes on AMD GPUs on Win7. */
8740 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem texture", DDERR_INVALIDPARAMS
, FALSE
},
8741 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem texture", DDERR_INVALIDPARAMS
, FALSE
},
8742 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, "managed texture", DD_OK
, FALSE
},
8743 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, "managed texture", DD_OK
, FALSE
},
8744 {DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
,
8745 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_TEXTUREMANAGE
,
8746 "cubemap", DD_OK
, FALSE
},
8747 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem offscreenplain", DDERR_INVALIDOBJECT
, TRUE
},
8748 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem offscreenplain", DDERR_INVALIDOBJECT
, TRUE
},
8751 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8752 0, 0, 640, 480, 0, 0, 0, 0);
8753 ddraw
= create_ddraw();
8754 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8755 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8756 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8758 memset(&hal_caps
, 0, sizeof(hal_caps
));
8759 hal_caps
.dwSize
= sizeof(hal_caps
);
8760 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
8761 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
8762 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
8763 || !(hal_caps
.ddsCaps
.dwCaps
& DDSCAPS2_TEXTUREMANAGE
))
8765 skip("Required surface types not supported, skipping test.\n");
8769 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
8771 memset(&surface_desc
, 0, sizeof(surface_desc
));
8772 surface_desc
.dwSize
= sizeof(surface_desc
);
8773 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
8774 surface_desc
.dwWidth
= 32;
8775 surface_desc
.dwHeight
= 32;
8776 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
8777 surface_desc
.ddsCaps
.dwCaps2
= test_data
[i
].caps2
;
8778 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8779 if (is_ddraw64
&& (test_data
[i
].caps
& DDSCAPS_TEXTURE
))
8781 todo_wine
ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8783 IDirectDrawSurface7_Release(surface
);
8786 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8788 /* Priority == NULL segfaults. */
8789 priority
= 0xdeadbeef;
8790 hr
= IDirectDrawSurface7_GetPriority(surface
, &priority
);
8791 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8792 if (SUCCEEDED(test_data
[i
].hr
))
8793 ok(priority
== 0, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8795 ok(priority
== 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8797 if (!test_data
[i
].crash
)
8799 hr
= IDirectDrawSurface7_SetPriority(surface
, 1);
8800 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8801 hr
= IDirectDrawSurface7_GetPriority(surface
, &priority
);
8802 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8803 if (SUCCEEDED(test_data
[i
].hr
))
8805 ok(priority
== 1, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8806 hr
= IDirectDrawSurface7_SetPriority(surface
, 2);
8807 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8810 ok(priority
== 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8813 if (test_data
[i
].caps2
& DDSCAPS2_CUBEMAP
)
8815 caps
.dwCaps2
= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
8816 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &mipmap
);
8817 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
8818 /* IDirectDrawSurface7_SetPriority crashes when called on non-positive X surfaces on Windows */
8819 priority
= 0xdeadbeef;
8820 hr
= IDirectDrawSurface7_GetPriority(mipmap
, &priority
);
8821 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8822 ok(priority
== 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8824 IDirectDrawSurface7_Release(mipmap
);
8827 IDirectDrawSurface7_Release(surface
);
8833 memset(&surface_desc
, 0, sizeof(surface_desc
));
8834 surface_desc
.dwSize
= sizeof(surface_desc
);
8835 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_MIPMAPCOUNT
;
8836 surface_desc
.dwWidth
= 32;
8837 surface_desc
.dwHeight
= 32;
8838 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
8839 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
8840 U2(surface_desc
).dwMipMapCount
= 2;
8841 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8842 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8844 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &mipmap
);
8845 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
8847 priority
= 0xdeadbeef;
8848 hr
= IDirectDrawSurface7_GetPriority(mipmap
, &priority
);
8849 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type managed mipmap.\n", hr
);
8850 ok(priority
== 0xdeadbeef, "Got unexpected priority %u, type managed mipmap.\n", priority
);
8851 /* SetPriority on the mipmap surface crashes. */
8852 hr
= IDirectDrawSurface7_GetPriority(surface
, &priority
);
8853 ok(SUCCEEDED(hr
), "Failed to get priority, hr %#x.\n", hr
);
8854 ok(priority
== 0, "Got unexpected priority %u, type managed mipmap.\n", priority
);
8856 IDirectDrawSurface7_Release(mipmap
);
8857 refcount
= IDirectDrawSurface7_Release(surface
);
8858 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8861 refcount
= IDirectDraw7_Release(ddraw
);
8862 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8863 DestroyWindow(window
);
8866 static void test_surface_desc_lock(void)
8868 IDirectDrawSurface7
*surface
;
8869 DDSURFACEDESC2 surface_desc
;
8870 IDirectDraw7
*ddraw
;
8875 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8876 0, 0, 640, 480, 0, 0, 0, 0);
8877 ddraw
= create_ddraw();
8878 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8879 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8880 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8882 memset(&surface_desc
, 0, sizeof(surface_desc
));
8883 surface_desc
.dwSize
= sizeof(surface_desc
);
8884 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8885 surface_desc
.dwWidth
= 16;
8886 surface_desc
.dwHeight
= 16;
8887 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8888 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8889 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8891 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8892 surface_desc
.dwSize
= sizeof(surface_desc
);
8893 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
8894 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8895 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8897 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8898 surface_desc
.dwSize
= sizeof(surface_desc
);
8899 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
8900 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8901 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8902 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8903 surface_desc
.dwSize
= sizeof(surface_desc
);
8904 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
8905 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8906 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8907 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
8908 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8910 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8911 surface_desc
.dwSize
= sizeof(surface_desc
);
8912 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
8913 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8914 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8916 IDirectDrawSurface7_Release(surface
);
8917 refcount
= IDirectDraw7_Release(ddraw
);
8918 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8919 DestroyWindow(window
);
8922 static void test_fog_interpolation(void)
8925 IDirect3DDevice7
*device
;
8926 IDirectDrawSurface7
*rt
;
8932 struct vec3 position
;
8938 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff000000},
8939 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff000000},
8940 {{ 1.0f
, -1.0f
, 1.0f
}, 0xffff0000, 0x00000000},
8941 {{ 1.0f
, 1.0f
, 1.0f
}, 0xffff0000, 0x00000000},
8951 D3DFOGMODE vfog
, tfog
;
8953 D3DCOLOR middle_color
;
8958 {D3DFOG_NONE
, D3DFOG_NONE
, D3DSHADE_FLAT
, 0x00007f80, FALSE
},
8959 {D3DFOG_NONE
, D3DFOG_NONE
, D3DSHADE_GOURAUD
, 0x00007f80, FALSE
},
8960 {D3DFOG_EXP
, D3DFOG_NONE
, D3DSHADE_FLAT
, 0x00007f80, TRUE
},
8961 {D3DFOG_EXP
, D3DFOG_NONE
, D3DSHADE_GOURAUD
, 0x00007f80, TRUE
},
8962 {D3DFOG_NONE
, D3DFOG_EXP
, D3DSHADE_FLAT
, 0x0000ea15, FALSE
},
8963 {D3DFOG_NONE
, D3DFOG_EXP
, D3DSHADE_GOURAUD
, 0x0000ea15, FALSE
},
8964 {D3DFOG_EXP
, D3DFOG_EXP
, D3DSHADE_FLAT
, 0x0000ea15, FALSE
},
8965 {D3DFOG_EXP
, D3DFOG_EXP
, D3DSHADE_GOURAUD
, 0x0000ea15, FALSE
},
8967 D3DDEVICEDESC7 caps
;
8969 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8970 0, 0, 640, 480, 0, 0, 0, 0);
8972 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8974 skip("Failed to create a 3D device, skipping test.\n");
8975 DestroyWindow(window
);
8979 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
8980 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8981 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
8982 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8983 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
8984 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
8986 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
8987 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8988 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
8989 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8990 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
8991 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8992 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0x0000ff00);
8993 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8995 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGDENSITY
, conv
.d
);
8996 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8998 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
8999 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9000 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
9001 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9002 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x000000ff);
9003 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9005 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
9007 if(!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
) && tests
[i
].tfog
)
9010 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00808080, 0.0f
, 0);
9011 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9013 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shade
);
9014 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9015 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, tests
[i
].vfog
);
9016 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9017 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, tests
[i
].tfog
);
9018 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9019 hr
= IDirect3DDevice7_BeginScene(device
);
9020 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9021 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
9022 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, quad
, 4, 0);
9023 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9024 hr
= IDirect3DDevice7_EndScene(device
);
9025 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9027 color
= get_surface_color(rt
, 0, 240);
9028 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color
, i
);
9029 color
= get_surface_color(rt
, 320, 240);
9030 todo_wine_if (tests
[i
].todo
)
9031 ok(compare_color(color
, tests
[i
].middle_color
, 2),
9032 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
9033 color
= get_surface_color(rt
, 639, 240);
9034 ok(compare_color(color
, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color
, i
);
9037 IDirectDrawSurface7_Release(rt
);
9038 refcount
= IDirect3DDevice7_Release(device
);
9039 ok(!refcount
, "Device has %u references left.\n", refcount
);
9040 DestroyWindow(window
);
9043 static void test_negative_fixedfunction_fog(void)
9046 IDirect3DDevice7
*device
;
9047 IDirectDrawSurface7
*rt
;
9053 struct vec3 position
;
9058 {{-1.0f
, -1.0f
, -0.5f
}, 0xffff0000},
9059 {{-1.0f
, 1.0f
, -0.5f
}, 0xffff0000},
9060 {{ 1.0f
, -1.0f
, -0.5f
}, 0xffff0000},
9061 {{ 1.0f
, 1.0f
, -0.5f
}, 0xffff0000},
9065 struct vec4 position
;
9070 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xffff0000},
9071 {{640.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xffff0000},
9072 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xffff0000},
9073 {{640.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xffff0000},
9076 static D3DMATRIX zero
=
9078 1.0f
, 0.0f
, 0.0f
, 0.0f
,
9079 0.0f
, 1.0f
, 0.0f
, 0.0f
,
9080 0.0f
, 0.0f
, 0.0f
, 0.0f
,
9081 0.0f
, 0.0f
, 0.0f
, 1.0f
9083 static D3DMATRIX identity
=
9085 1.0f
, 0.0f
, 0.0f
, 0.0f
,
9086 0.0f
, 1.0f
, 0.0f
, 0.0f
,
9087 0.0f
, 0.0f
, 1.0f
, 0.0f
,
9088 0.0f
, 0.0f
, 0.0f
, 1.0f
9100 D3DFOGMODE vfog
, tfog
;
9101 DWORD color
, color_broken
, color_broken2
;
9105 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot.
9107 * Geforce8+ GPUs on Windows abs() table fog, everything else does not. */
9108 {D3DFVF_XYZRHW
, tquad
, &identity
, { 0.0f
}, {1.0f
}, D3DFOG_NONE
, D3DFOG_LINEAR
,
9109 0x00ff0000, 0x00808000, 0x00808000},
9110 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
9111 * parameters to 0.0 and 1.0 in the table fog case. */
9112 {D3DFVF_XYZRHW
, tquad
, &identity
, {-1.0f
}, {0.0f
}, D3DFOG_NONE
, D3DFOG_LINEAR
,
9113 0x00808000, 0x00ff0000, 0x0000ff00},
9114 /* test_fog_interpolation shows that vertex fog evaluates the fog
9115 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
9116 * that the abs happens before the fog equation is evaluated.
9118 * Vertex fog abs() behavior is the same on all GPUs. */
9119 {D3DFVF_XYZ
, quad
, &zero
, { 0.0f
}, {1.0f
}, D3DFOG_LINEAR
, D3DFOG_NONE
,
9120 0x00808000, 0x00808000, 0x00808000},
9121 {D3DFVF_XYZ
, quad
, &zero
, {-1.0f
}, {0.0f
}, D3DFOG_LINEAR
, D3DFOG_NONE
,
9122 0x0000ff00, 0x0000ff00, 0x0000ff00},
9123 {D3DFVF_XYZ
, quad
, &zero
, { 0.0f
}, {1.0f
}, D3DFOG_EXP
, D3DFOG_NONE
,
9124 0x009b6400, 0x009b6400, 0x009b6400},
9126 D3DDEVICEDESC7 caps
;
9128 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9129 0, 0, 640, 480, 0, 0, 0, 0);
9131 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9133 skip("Failed to create a 3D device, skipping test.\n");
9134 DestroyWindow(window
);
9138 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
9139 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9140 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
9141 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9142 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
9143 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
9145 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9146 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9147 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9148 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9149 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
9150 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9151 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0x0000ff00);
9152 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9153 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
9154 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
9156 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
9158 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
) && tests
[i
].tfog
)
9161 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 0.0f
, 0);
9162 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9164 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, tests
[i
].matrix
);
9165 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
9166 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, tests
[i
].start
.d
);
9167 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9168 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, tests
[i
].end
.d
);
9169 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9170 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, tests
[i
].vfog
);
9171 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9172 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, tests
[i
].tfog
);
9173 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9175 hr
= IDirect3DDevice7_BeginScene(device
);
9176 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9177 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
9178 tests
[i
].pos_type
| D3DFVF_DIFFUSE
, tests
[i
].quad
, 4, 0);
9179 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9180 hr
= IDirect3DDevice7_EndScene(device
);
9181 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9183 color
= get_surface_color(rt
, 0, 240);
9184 ok(compare_color(color
, tests
[i
].color
, 2) || broken(compare_color(color
, tests
[i
].color_broken
, 2))
9185 || broken(compare_color(color
, tests
[i
].color_broken2
, 2)),
9186 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
9189 IDirectDrawSurface7_Release(rt
);
9190 refcount
= IDirect3DDevice7_Release(device
);
9191 ok(!refcount
, "Device has %u references left.\n", refcount
);
9192 DestroyWindow(window
);
9195 static void test_table_fog_zw(void)
9198 IDirect3DDevice7
*device
;
9199 IDirectDrawSurface7
*rt
;
9205 struct vec4 position
;
9210 {{ 0.0f
, 0.0f
, 0.0f
, 0.0f
}, 0xffff0000},
9211 {{640.0f
, 0.0f
, 0.0f
, 0.0f
}, 0xffff0000},
9212 {{ 0.0f
, 480.0f
, 0.0f
, 0.0f
}, 0xffff0000},
9213 {{640.0f
, 480.0f
, 0.0f
, 0.0f
}, 0xffff0000},
9215 static D3DMATRIX identity
=
9217 1.0f
, 0.0f
, 0.0f
, 0.0f
,
9218 0.0f
, 1.0f
, 0.0f
, 0.0f
,
9219 0.0f
, 0.0f
, 1.0f
, 0.0f
,
9220 0.0f
, 0.0f
, 0.0f
, 1.0f
9222 D3DDEVICEDESC7 caps
;
9226 D3DZBUFFERTYPE z_test
;
9231 {0.7f
, 0.0f
, D3DZB_TRUE
, 0x004cb200},
9232 {0.7f
, 0.0f
, D3DZB_FALSE
, 0x004cb200},
9233 {0.7f
, 0.3f
, D3DZB_TRUE
, 0x004cb200},
9234 {0.7f
, 0.3f
, D3DZB_FALSE
, 0x004cb200},
9235 {0.7f
, 3.0f
, D3DZB_TRUE
, 0x004cb200},
9236 {0.7f
, 3.0f
, D3DZB_FALSE
, 0x004cb200},
9237 {0.3f
, 0.0f
, D3DZB_TRUE
, 0x00b24c00},
9238 {0.3f
, 0.0f
, D3DZB_FALSE
, 0x00b24c00},
9242 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9243 0, 0, 640, 480, 0, 0, 0, 0);
9245 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9247 skip("Failed to create a 3D device, skipping test.\n");
9248 DestroyWindow(window
);
9252 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
9253 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9254 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
9256 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping POSITIONT table fog test.\n");
9259 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
9260 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9262 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9263 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9264 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
9265 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9266 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0x0000ff00);
9267 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9268 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
9269 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
9270 /* Work around an AMD Windows driver bug. Needs a proj matrix applied redundantly. */
9271 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &identity
);
9272 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
9273 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_LINEAR
);
9274 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9276 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
9278 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x000000ff, 1.0f
, 0);
9279 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9281 quad
[0].position
.z
= tests
[i
].z
;
9282 quad
[1].position
.z
= tests
[i
].z
;
9283 quad
[2].position
.z
= tests
[i
].z
;
9284 quad
[3].position
.z
= tests
[i
].z
;
9285 quad
[0].position
.w
= tests
[i
].w
;
9286 quad
[1].position
.w
= tests
[i
].w
;
9287 quad
[2].position
.w
= tests
[i
].w
;
9288 quad
[3].position
.w
= tests
[i
].w
;
9289 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, tests
[i
].z_test
);
9290 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9292 hr
= IDirect3DDevice7_BeginScene(device
);
9293 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9294 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
9295 D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad
, 4, 0);
9296 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9297 hr
= IDirect3DDevice7_EndScene(device
);
9298 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9300 color
= get_surface_color(rt
, 0, 240);
9301 ok(compare_color(color
, tests
[i
].color
, 2),
9302 "Got unexpected color 0x%08x, expected 0x%8x, case %u.\n", color
, tests
[i
].color
, i
);
9305 IDirectDrawSurface7_Release(rt
);
9307 refcount
= IDirect3DDevice7_Release(device
);
9308 ok(!refcount
, "Device has %u references left.\n", refcount
);
9309 DestroyWindow(window
);
9312 static void test_signed_formats(void)
9315 IDirect3DDevice7
*device
;
9317 IDirectDraw7
*ddraw
;
9318 IDirectDrawSurface7
*surface
, *rt
;
9319 DDSURFACEDESC2 surface_desc
;
9322 D3DCOLOR color
, expected_color
;
9325 struct vec3 position
;
9326 struct vec2 texcoord
;
9330 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9331 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
9332 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9333 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
9335 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
9336 * of these values. */
9337 static const USHORT content_v8u8
[4][4] =
9339 {0x0000, 0x7f7f, 0x8880, 0x0000},
9340 {0x0080, 0x8000, 0x7f00, 0x007f},
9341 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
9342 {0x4444, 0xc0c0, 0xa066, 0x22e0},
9344 static const DWORD content_x8l8v8u8
[4][4] =
9346 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
9347 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
9348 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
9349 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
9351 static const USHORT content_l6v5u5
[4][4] =
9353 {0x0000, 0xfdef, 0x0230, 0xfc00},
9354 {0x0010, 0x0200, 0x01e0, 0x000f},
9355 {0x4067, 0x53b9, 0x0421, 0xffff},
9356 {0x8108, 0x0318, 0xc28c, 0x909c},
9361 const void *content
;
9364 unsigned int slop
, slop_broken
;
9365 DDPIXELFORMAT format
;
9370 "D3DFMT_V8U8", content_v8u8
, sizeof(WORD
), FALSE
, 1, 0,
9372 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
, 0,
9373 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
9377 "D3DFMT_X8L8V8U8", content_x8l8v8u8
, sizeof(DWORD
), TRUE
, 1, 0,
9379 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
9380 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
9384 "D3DFMT_L6V5U5", content_l6v5u5
, sizeof(WORD
), TRUE
, 4, 7,
9386 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
9387 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
9391 /* No V16U16 or Q8W8V8U8 support in ddraw. */
9393 static const D3DCOLOR expected_colors
[4][4] =
9395 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
9396 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
9397 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
9398 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
9400 unsigned int i
, width
, x
, y
;
9401 D3DDEVICEDESC7 device_desc
;
9403 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9404 0, 0, 640, 480, 0, 0, 0, 0);
9406 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9408 skip("Failed to create a 3D device, skipping test.\n");
9409 DestroyWindow(window
);
9413 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
9414 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9415 if (!(device_desc
.dwTextureOpCaps
& D3DTEXOPCAPS_BLENDFACTORALPHA
))
9417 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
9421 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
9422 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9423 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
9424 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9425 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
9426 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9428 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9429 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9431 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
9432 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x80ffffff);
9433 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9434 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BLENDFACTORALPHA
);
9435 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9436 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9437 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9438 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
9439 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9441 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
9443 for (width
= 1; width
< 5; width
+= 3)
9445 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
9446 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
9448 memset(&surface_desc
, 0, sizeof(surface_desc
));
9449 surface_desc
.dwSize
= sizeof(surface_desc
);
9450 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
9451 surface_desc
.dwWidth
= width
;
9452 surface_desc
.dwHeight
= 4;
9453 U4(surface_desc
).ddpfPixelFormat
= formats
[i
].format
;
9454 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
9455 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9458 skip("%s textures not supported, skipping.\n", formats
[i
].name
);
9461 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9462 hr
= IDirect3DDevice7_SetTexture(device
, 0, surface
);
9463 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9465 memset(&surface_desc
, 0, sizeof(surface_desc
));
9466 surface_desc
.dwSize
= sizeof(surface_desc
);
9467 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
9468 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9469 for (y
= 0; y
< 4; y
++)
9471 memcpy((char *)surface_desc
.lpSurface
+ y
* U1(surface_desc
).lPitch
,
9472 (char *)formats
[i
].content
+ y
* 4 * formats
[i
].pixel_size
,
9473 width
* formats
[i
].pixel_size
);
9475 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9476 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9478 hr
= IDirect3DDevice7_BeginScene(device
);
9479 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9480 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
9481 D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
9482 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9483 hr
= IDirect3DDevice7_EndScene(device
);
9484 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9486 for (y
= 0; y
< 4; y
++)
9488 for (x
= 0; x
< width
; x
++)
9490 expected_color
= expected_colors
[y
][x
];
9491 if (!formats
[i
].blue
)
9492 expected_color
|= 0x000000ff;
9494 color
= get_surface_color(rt
, 80 + 160 * x
, 60 + 120 * y
);
9495 ok(compare_color(color
, expected_color
, formats
[i
].slop
)
9496 || broken(compare_color(color
, expected_color
, formats
[i
].slop_broken
)),
9497 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9498 expected_color
, color
, formats
[i
].name
, x
, y
);
9502 IDirectDrawSurface7_Release(surface
);
9507 IDirectDrawSurface7_Release(rt
);
9508 IDirectDraw7_Release(ddraw
);
9509 IDirect3D7_Release(d3d
);
9512 refcount
= IDirect3DDevice7_Release(device
);
9513 ok(!refcount
, "Device has %u references left.\n", refcount
);
9514 DestroyWindow(window
);
9517 static void test_color_fill(void)
9520 IDirect3DDevice7
*device
;
9522 IDirectDraw7
*ddraw
;
9523 IDirectDrawSurface7
*surface
, *surface2
;
9524 DDSURFACEDESC2 surface_desc
;
9525 DDPIXELFORMAT z_fmt
;
9530 RECT rect
= {5, 5, 7, 7};
9532 DWORD supported_fmts
= 0, num_fourcc_codes
, *fourcc_codes
;
9537 HRESULT colorfill_hr
, depthfill_hr
;
9542 DDPIXELFORMAT format
;
9547 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9548 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9550 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9551 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9555 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9556 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9558 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9559 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9563 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9564 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
9566 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9567 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9571 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9572 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
9574 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9575 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9579 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
9580 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "managed texture RGB", 0xdeadbeef, TRUE
,
9582 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9583 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9587 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
, 0,
9588 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
9589 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9592 DDSCAPS_ZBUFFER
| DDSCAPS_SYSTEMMEMORY
, 0,
9593 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "sysmem zbuffer", 0, FALSE
,
9594 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9597 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9598 * different afterwards. DX9+ GPUs set one of the two luminance values
9599 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9600 * value they set. r200 (dx8) just sets the entire block to the clear
9602 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9603 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
9605 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9606 {0}, {0}, {0}, {0}, {0}
9610 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9611 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
9613 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9614 {0}, {0}, {0}, {0}, {0}
9618 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9619 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
9621 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9622 {0}, {0}, {0}, {0}, {0}
9626 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9627 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
9629 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9630 {0}, {0}, {0}, {0}, {0}
9634 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9635 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
9637 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9638 {0}, {0}, {0}, {0}, {0}
9642 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9643 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
9645 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9646 {0}, {0}, {0}, {0}, {0}
9650 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9651 * surface works, presumably because it is handled by the runtime instead of
9653 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9654 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
9656 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9657 {8}, {0}, {0}, {0}, {0}
9661 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9662 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
9664 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9665 {8}, {0}, {0}, {0}, {0}
9677 {SRCCOPY
, "SRCCOPY", DD_OK
},
9678 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
9679 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
9680 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
9681 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
9682 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
9683 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
9684 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
9685 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
9686 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
9687 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
9688 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
9689 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
9690 {BLACKNESS
, "BLACKNESS", DD_OK
},
9691 {WHITENESS
, "WHITENESS", DD_OK
},
9692 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
9695 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9696 0, 0, 640, 480, 0, 0, 0, 0);
9698 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9700 skip("Failed to create a 3D device, skipping test.\n");
9701 DestroyWindow(window
);
9705 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
9706 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9707 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
9708 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9710 memset(&z_fmt
, 0, sizeof(z_fmt
));
9711 IDirect3D7_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
9713 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9715 IDirect3DDevice7_EnumTextureFormats(device
, test_block_formats_creation_cb
, &supported_fmts
);
9716 if (!(supported_fmts
& SUPPORT_DXT1
))
9717 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9719 IDirect3D7_Release(d3d
);
9721 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
9722 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9723 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
9724 num_fourcc_codes
* sizeof(*fourcc_codes
));
9727 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
9728 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9729 for (i
= 0; i
< num_fourcc_codes
; i
++)
9731 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9732 supported_fmts
|= SUPPORT_YUY2
;
9733 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9734 supported_fmts
|= SUPPORT_UYVY
;
9736 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
9738 memset(&hal_caps
, 0, sizeof(hal_caps
));
9739 hal_caps
.dwSize
= sizeof(hal_caps
);
9740 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
9741 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9743 if (!(supported_fmts
& (SUPPORT_YUY2
| SUPPORT_UYVY
)) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9744 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9746 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
9748 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9749 memset(&fx
, 0, sizeof(fx
));
9750 fx
.dwSize
= sizeof(fx
);
9751 U5(fx
).dwFillColor
= 0xdeadbeef;
9753 memset(&surface_desc
, 0, sizeof(surface_desc
));
9754 surface_desc
.dwSize
= sizeof(surface_desc
);
9755 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9756 surface_desc
.dwWidth
= 64;
9757 surface_desc
.dwHeight
= 64;
9758 U4(surface_desc
).ddpfPixelFormat
= tests
[i
].format
;
9759 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
9760 surface_desc
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
9762 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('D','X','T','1') && !(supported_fmts
& SUPPORT_DXT1
))
9764 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !(supported_fmts
& SUPPORT_YUY2
))
9766 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !(supported_fmts
& SUPPORT_UYVY
))
9768 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9771 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
9776 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9779 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9780 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9782 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9783 todo_wine_if (tests
[i
].format
.dwFourCC
)
9784 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9785 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9787 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9788 todo_wine_if (tests
[i
].format
.dwFourCC
)
9789 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9790 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9792 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9794 memset(&surface_desc
, 0, sizeof(surface_desc
));
9795 surface_desc
.dwSize
= sizeof(surface_desc
);
9796 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9797 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9798 color
= surface_desc
.lpSurface
;
9799 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9800 *color
, tests
[i
].result
, tests
[i
].name
);
9801 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9802 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9805 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9806 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9807 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9808 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9809 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9810 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9812 U5(fx
).dwFillColor
= 0xdeadbeef;
9813 fx
.dwROP
= BLACKNESS
;
9814 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9815 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9816 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9817 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9818 U5(fx
).dwFillColor
, tests
[i
].name
);
9820 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9822 memset(&surface_desc
, 0, sizeof(surface_desc
));
9823 surface_desc
.dwSize
= sizeof(surface_desc
);
9824 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9825 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9826 color
= surface_desc
.lpSurface
;
9827 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9828 *color
, tests
[i
].name
);
9829 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9830 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9833 fx
.dwROP
= WHITENESS
;
9834 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9835 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9836 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9837 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9838 U5(fx
).dwFillColor
, tests
[i
].name
);
9840 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9842 memset(&surface_desc
, 0, sizeof(surface_desc
));
9843 surface_desc
.dwSize
= sizeof(surface_desc
);
9844 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9845 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9846 color
= surface_desc
.lpSurface
;
9847 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9848 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9849 *color
, tests
[i
].name
);
9850 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9851 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9854 IDirectDrawSurface7_Release(surface
);
9857 memset(&fx
, 0, sizeof(fx
));
9858 fx
.dwSize
= sizeof(fx
);
9859 U5(fx
).dwFillColor
= 0xdeadbeef;
9860 fx
.dwROP
= WHITENESS
;
9862 memset(&surface_desc
, 0, sizeof(surface_desc
));
9863 surface_desc
.dwSize
= sizeof(surface_desc
);
9864 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9865 surface_desc
.dwWidth
= 64;
9866 surface_desc
.dwHeight
= 64;
9867 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9868 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9869 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9870 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9871 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9872 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9873 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
9874 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9875 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9876 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9877 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9880 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
9881 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9882 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
9883 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9885 /* Unused source rectangle. */
9886 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9887 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9888 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9889 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9891 /* Unused source surface. */
9892 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9893 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9894 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9895 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9896 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9897 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9898 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9899 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9901 /* Inverted destination or source rectangle. */
9902 SetRect(&rect
, 5, 7, 7, 5);
9903 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9904 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9905 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9906 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9907 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9908 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9909 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9910 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9911 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9912 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9914 /* Negative rectangle. */
9915 SetRect(&rect
, -1, -1, 5, 5);
9916 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9917 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9918 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9919 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9920 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9921 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9922 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9923 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9924 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9925 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9927 /* Out of bounds rectangle. */
9928 SetRect(&rect
, 0, 0, 65, 65);
9929 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9930 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9931 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9932 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9934 /* Combine multiple flags. */
9935 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9936 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9937 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9938 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9939 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9940 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9942 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
9944 fx
.dwROP
= rops
[i
].rop
;
9945 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9946 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
9949 IDirectDrawSurface7_Release(surface2
);
9950 IDirectDrawSurface7_Release(surface
);
9955 memset(&surface_desc
, 0, sizeof(surface_desc
));
9956 surface_desc
.dwSize
= sizeof(surface_desc
);
9957 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9958 surface_desc
.dwWidth
= 64;
9959 surface_desc
.dwHeight
= 64;
9960 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9961 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
9962 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9963 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9964 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9965 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9968 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
9969 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9971 /* Unused source rectangle. */
9972 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9973 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9975 /* Unused source surface. */
9976 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9977 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9978 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9979 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9981 /* Inverted destination or source rectangle. */
9982 SetRect(&rect
, 5, 7, 7, 5);
9983 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9984 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9985 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9986 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9987 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9988 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9989 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9990 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9992 /* Negative rectangle. */
9993 SetRect(&rect
, -1, -1, 5, 5);
9994 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9995 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9996 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9997 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9998 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9999 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10000 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
10001 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10003 /* Out of bounds rectangle. */
10004 SetRect(&rect
, 0, 0, 65, 65);
10005 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
10006 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
10008 /* Combine multiple flags. */
10009 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
10010 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10012 IDirectDrawSurface7_Release(surface2
);
10013 IDirectDrawSurface7_Release(surface
);
10016 IDirectDraw7_Release(ddraw
);
10017 refcount
= IDirect3DDevice7_Release(device
);
10018 ok(!refcount
, "Device has %u references left.\n", refcount
);
10019 DestroyWindow(window
);
10022 static void test_texcoordindex(void)
10024 static D3DMATRIX mat
=
10026 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10027 0.0f
, 0.0f
, 0.0f
, 0.0f
,
10028 0.0f
, 0.0f
, 0.0f
, 0.0f
,
10029 0.0f
, 0.0f
, 0.0f
, 0.0f
,
10034 struct vec2 texcoord1
;
10035 struct vec2 texcoord2
;
10036 struct vec2 texcoord3
;
10040 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}, {0.0f
, 0.0f
}, {1.0f
, 1.0f
}},
10041 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}, {0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
10042 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
10043 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 0.0f
}},
10045 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_TEX3
;
10046 IDirect3DDevice7
*device
;
10048 IDirectDraw7
*ddraw
;
10049 IDirectDrawSurface7
*rt
;
10052 IDirectDrawSurface7
*texture1
, *texture2
;
10053 DDSURFACEDESC2 surface_desc
;
10058 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10059 0, 0, 640, 480, 0, 0, 0, 0);
10060 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10062 skip("Failed to create a 3D device, skipping test.\n");
10063 DestroyWindow(window
);
10067 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
10068 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
10069 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
10070 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
10071 IDirect3D7_Release(d3d
);
10073 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
10074 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10076 memset(&surface_desc
, 0, sizeof(surface_desc
));
10077 surface_desc
.dwSize
= sizeof(surface_desc
);
10078 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10079 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10080 surface_desc
.dwWidth
= 2;
10081 surface_desc
.dwHeight
= 2;
10082 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
10083 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
10084 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10085 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10086 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10087 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10088 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
10089 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture1
, NULL
);
10090 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10091 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture2
, NULL
);
10092 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10094 memset(&surface_desc
, 0, sizeof(surface_desc
));
10095 surface_desc
.dwSize
= sizeof(surface_desc
);
10096 hr
= IDirectDrawSurface7_Lock(texture1
, 0, &surface_desc
, 0, NULL
);
10097 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10098 ptr
= surface_desc
.lpSurface
;
10099 ptr
[0] = 0xff000000;
10100 ptr
[1] = 0xff00ff00;
10101 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
10102 ptr
[0] = 0xff0000ff;
10103 ptr
[1] = 0xff00ffff;
10104 hr
= IDirectDrawSurface7_Unlock(texture1
, NULL
);
10105 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10107 memset(&surface_desc
, 0, sizeof(surface_desc
));
10108 surface_desc
.dwSize
= sizeof(surface_desc
);
10109 hr
= IDirectDrawSurface7_Lock(texture2
, 0, &surface_desc
, 0, NULL
);
10110 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10111 ptr
= surface_desc
.lpSurface
;
10112 ptr
[0] = 0xff000000;
10113 ptr
[1] = 0xff0000ff;
10114 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
10115 ptr
[0] = 0xffff0000;
10116 ptr
[1] = 0xffff00ff;
10117 hr
= IDirectDrawSurface7_Unlock(texture2
, 0);
10118 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10120 hr
= IDirect3DDevice7_SetTexture(device
, 0, texture1
);
10121 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
10122 hr
= IDirect3DDevice7_SetTexture(device
, 1, texture2
);
10123 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
10124 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10125 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
10126 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
10127 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
10128 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
10129 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10130 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_ADD
);
10131 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
10132 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
10133 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10134 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
10135 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10136 hr
= IDirect3DDevice7_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
10137 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
10139 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_TEXCOORDINDEX
, 1);
10140 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
10141 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 0);
10142 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
10144 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
10145 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
10147 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
10148 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10150 hr
= IDirect3DDevice7_BeginScene(device
);
10151 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10152 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
10153 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10154 hr
= IDirect3DDevice7_EndScene(device
);
10155 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10157 color
= get_surface_color(rt
, 160, 120);
10158 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
10159 color
= get_surface_color(rt
, 480, 120);
10160 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
10161 color
= get_surface_color(rt
, 160, 360);
10162 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
10163 color
= get_surface_color(rt
, 480, 360);
10164 ok(compare_color(color
, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color
);
10166 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
10167 ok(SUCCEEDED(hr
), "Failed to set texture transform flags, hr %#x.\n", hr
);
10168 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_TEXTURE1
, &mat
);
10169 ok(SUCCEEDED(hr
), "Failed to set transformation matrix, hr %#x.\n", hr
);
10171 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
10172 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10174 hr
= IDirect3DDevice7_BeginScene(device
);
10175 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10176 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
10177 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10178 hr
= IDirect3DDevice7_EndScene(device
);
10179 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10181 color
= get_surface_color(rt
, 160, 120);
10182 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
10183 color
= get_surface_color(rt
, 480, 120);
10184 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
10185 color
= get_surface_color(rt
, 160, 360);
10186 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
10187 color
= get_surface_color(rt
, 480, 360);
10188 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
10190 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_DISABLE
);
10191 ok(SUCCEEDED(hr
), "Failed to set texture transform flags, hr %#x.\n", hr
);
10192 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 2);
10193 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
10195 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
10196 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10198 hr
= IDirect3DDevice7_BeginScene(device
);
10199 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10200 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
10201 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10202 hr
= IDirect3DDevice7_EndScene(device
);
10203 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10205 color
= get_surface_color(rt
, 160, 120);
10206 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
10207 color
= get_surface_color(rt
, 480, 120);
10208 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
10209 color
= get_surface_color(rt
, 160, 360);
10210 ok(compare_color(color
, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color
);
10211 color
= get_surface_color(rt
, 480, 360);
10212 ok(compare_color(color
, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color
);
10214 IDirectDrawSurface7_Release(texture1
);
10215 IDirectDrawSurface7_Release(texture2
);
10217 IDirectDrawSurface7_Release(rt
);
10218 IDirectDraw_Release(ddraw
);
10219 refcount
= IDirect3DDevice7_Release(device
);
10220 ok(!refcount
, "Device has %u references left.\n", refcount
);
10221 DestroyWindow(window
);
10224 static BOOL
ddraw_is_nvidia(IDirectDraw7
*ddraw
)
10226 DDDEVICEIDENTIFIER2 identifier
;
10229 if (!strcmp(winetest_platform
, "wine"))
10232 hr
= IDirectDraw7_GetDeviceIdentifier(ddraw
, &identifier
, 0);
10233 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
10234 return identifier
.dwVendorId
== 0x10de;
10237 static void test_colorkey_precision(void)
10242 struct vec2 texcoord
;
10246 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
10247 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
10248 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
10249 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
10251 IDirect3DDevice7
*device
;
10253 IDirectDraw7
*ddraw
;
10254 IDirectDrawSurface7
*rt
;
10257 IDirectDrawSurface7
*src
, *dst
, *texture
;
10258 DDSURFACEDESC2 surface_desc
, lock_desc
;
10264 DWORD data
[4] = {0}, color_mask
;
10265 BOOL is_nvidia
, is_warp
;
10266 static const struct
10268 unsigned int max
, shift
, bpp
, clear
;
10276 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE
,
10278 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
10279 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
10284 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE
,
10286 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
10287 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
10292 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE
,
10294 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
10295 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
10300 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE
,
10302 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
10303 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
10308 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10309 0, 0, 640, 480, 0, 0, 0, 0);
10310 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10312 skip("Failed to create a 3D device, skipping test.\n");
10313 DestroyWindow(window
);
10317 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
10318 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
10319 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
10320 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
10321 IDirect3D7_Release(d3d
);
10322 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
10323 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10325 is_nvidia
= ddraw_is_nvidia(ddraw
);
10326 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
10327 * (color key doesn't match although the values are equal), and a false
10328 * positive when the color key is 0 and the texture contains the value 1.
10329 * I don't want to mark this broken unconditionally since this would
10330 * essentially disable the test on Windows. Also on random occasions
10331 * 254 == 255 and 255 != 255.*/
10332 is_warp
= ddraw_is_warp(ddraw
);
10334 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10335 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
10336 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
10337 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
10338 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
10339 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
10340 /* Multiply the texture read result with 0, that way the result color if the key doesn't
10341 * match is constant. In theory color keying works without reading the texture result
10342 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
10344 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
10345 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
10346 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
10347 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10348 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
10349 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10350 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x00000000);
10351 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
10353 memset(&fx
, 0, sizeof(fx
));
10354 fx
.dwSize
= sizeof(fx
);
10355 memset(&lock_desc
, 0, sizeof(lock_desc
));
10356 lock_desc
.dwSize
= sizeof(lock_desc
);
10358 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
10360 if (is_nvidia
&& tests
[t
].skip_nv
)
10362 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests
[t
].name
);
10366 memset(&surface_desc
, 0, sizeof(surface_desc
));
10367 surface_desc
.dwSize
= sizeof(surface_desc
);
10368 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10369 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10370 surface_desc
.dwWidth
= 4;
10371 surface_desc
.dwHeight
= 1;
10372 U4(surface_desc
).ddpfPixelFormat
= tests
[t
].fmt
;
10373 /* Windows XP (at least with the r200 driver, other drivers untested) produces
10374 * garbage when doing color keyed texture->texture blits. */
10375 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
10376 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10377 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
10378 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10380 fx
.dwFillColor
= tests
[t
].clear
;
10381 /* On the w8 testbot (WARP driver) the blit result has different values in the
10383 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
10384 | U3(tests
[t
].fmt
).dwGBitMask
10385 | U4(tests
[t
].fmt
).dwBBitMask
;
10387 for (c
= 0; c
<= tests
[t
].max
; ++c
)
10389 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
10390 * texture after it has been set once... */
10391 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
10392 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10393 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
10394 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
10395 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
10396 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10397 hr
= IDirect3DDevice7_SetTexture(device
, 0, texture
);
10398 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
10400 hr
= IDirectDrawSurface7_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
10401 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
10403 hr
= IDirectDrawSurface7_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
10404 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10405 switch (tests
[t
].bpp
)
10408 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
10409 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
10410 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
10411 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
10415 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
10416 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
10417 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
10418 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
10421 hr
= IDirectDrawSurface7_Unlock(src
, 0);
10422 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10423 hr
= IDirectDrawSurface7_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
10424 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10426 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
10427 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
10428 hr
= IDirectDrawSurface7_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
10429 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10431 hr
= IDirectDrawSurface7_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
10432 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10434 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
10435 hr
= IDirectDrawSurface7_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
10436 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10437 switch (tests
[t
].bpp
)
10440 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
10441 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
10442 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
10443 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
10447 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
10448 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
10449 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
10450 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
10453 hr
= IDirectDrawSurface7_Unlock(dst
, 0);
10454 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10458 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10459 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
10461 if (data
[3] == tests
[t
].clear
)
10463 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10464 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10465 * even when a different surface is used. The blit itself doesn't draw anything,
10466 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10467 * never be masked out by the key.
10469 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
10470 * test is disabled on Nvidia.
10472 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10473 * terrible on WARP. */
10474 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10475 IDirectDrawSurface7_Release(texture
);
10476 IDirectDrawSurface7_Release(src
);
10477 IDirectDrawSurface7_Release(dst
);
10482 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10483 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
10485 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10486 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
10488 if (c
== tests
[t
].max
)
10489 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10490 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
10492 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10493 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
10495 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 1.0f
, 0);
10496 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10498 hr
= IDirect3DDevice7_BeginScene(device
);
10499 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10500 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
10501 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10502 hr
= IDirect3DDevice7_EndScene(device
);
10503 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10505 color
= get_surface_color(rt
, 80, 240);
10507 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
10508 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10509 color
, tests
[t
].name
, c
);
10511 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
10512 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10513 color
, tests
[t
].name
, c
);
10515 color
= get_surface_color(rt
, 240, 240);
10516 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
10517 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10518 color
, tests
[t
].name
, c
);
10520 color
= get_surface_color(rt
, 400, 240);
10521 if (c
== tests
[t
].max
)
10522 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
10523 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10524 color
, tests
[t
].name
, c
);
10526 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
10527 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10528 color
, tests
[t
].name
, c
);
10530 IDirectDrawSurface7_Release(texture
);
10532 IDirectDrawSurface7_Release(src
);
10533 IDirectDrawSurface7_Release(dst
);
10537 IDirectDrawSurface7_Release(rt
);
10538 IDirectDraw7_Release(ddraw
);
10539 refcount
= IDirect3DDevice7_Release(device
);
10540 ok(!refcount
, "Device has %u references left.\n", refcount
);
10541 DestroyWindow(window
);
10544 static void test_range_colorkey(void)
10546 IDirectDraw7
*ddraw
;
10549 IDirectDrawSurface7
*surface
;
10550 DDSURFACEDESC2 surface_desc
;
10554 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10555 0, 0, 640, 480, 0, 0, 0, 0);
10556 ddraw
= create_ddraw();
10557 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10558 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10559 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10561 memset(&surface_desc
, 0, sizeof(surface_desc
));
10562 surface_desc
.dwSize
= sizeof(surface_desc
);
10563 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
10564 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10565 surface_desc
.dwWidth
= 1;
10566 surface_desc
.dwHeight
= 1;
10567 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10568 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10569 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10570 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10571 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10572 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
10574 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10575 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10576 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10577 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10578 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10580 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10581 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10582 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10583 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10585 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10586 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10587 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10588 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10589 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10590 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10592 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10593 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10594 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10595 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10597 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10598 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10599 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10600 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10602 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10603 ckey
.dwColorSpaceLowValue
= 0x00000000;
10604 ckey
.dwColorSpaceHighValue
= 0x00000001;
10605 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10606 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10608 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10609 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10610 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10611 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10613 ckey
.dwColorSpaceLowValue
= 0x00000001;
10614 ckey
.dwColorSpaceHighValue
= 0x00000000;
10615 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10616 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10618 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10619 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10620 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10621 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10623 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10624 ckey
.dwColorSpaceLowValue
= 0x00000000;
10625 ckey
.dwColorSpaceHighValue
= 0x00000000;
10626 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10627 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10629 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10630 ckey
.dwColorSpaceLowValue
= 0x00000001;
10631 ckey
.dwColorSpaceHighValue
= 0x00000000;
10632 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10633 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10634 ckey
.dwColorSpaceLowValue
= 0x00000000;
10635 ckey
.dwColorSpaceHighValue
= 0x00000001;
10636 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10637 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10638 /* Range destination keys don't work either. */
10639 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
10640 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10642 /* Just to show it's not because of A, R, and G having equal values. */
10643 ckey
.dwColorSpaceLowValue
= 0x00000000;
10644 ckey
.dwColorSpaceHighValue
= 0x01010101;
10645 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10646 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10648 /* None of these operations modified the key. */
10649 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10650 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10651 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10652 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10654 IDirectDrawSurface7_Release(surface
),
10655 refcount
= IDirectDraw7_Release(ddraw
);
10656 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
10657 DestroyWindow(window
);
10660 static void test_shademode(void)
10662 IDirect3DVertexBuffer7
*vb_strip
, *vb_list
, *buffer
;
10663 IDirect3DDevice7
*device
;
10664 D3DVERTEXBUFFERDESC desc
;
10665 IDirectDrawSurface7
*rt
;
10666 DWORD color0
, color1
;
10673 static const struct
10675 struct vec3 position
;
10680 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10681 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10682 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10683 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10687 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10688 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10689 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10691 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10692 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10693 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10695 static const struct
10699 DWORD color0
, color1
;
10703 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
10704 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10705 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10706 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10707 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
10708 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10711 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10712 0, 0, 640, 480, 0, 0, 0, 0);
10714 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10716 skip("Failed to create a 3D device, skipping test.\n");
10717 DestroyWindow(window
);
10721 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
10722 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
10723 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
10724 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10726 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10727 ok(hr
== D3D_OK
, "Failed to disable lighting, hr %#x.\n", hr
);
10728 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10729 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10731 memset(&desc
, 0, sizeof(desc
));
10732 desc
.dwSize
= sizeof(desc
);
10733 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
10734 desc
.dwFVF
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
10735 desc
.dwNumVertices
= sizeof(quad_strip
) / sizeof(*quad_strip
);
10736 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &vb_strip
, 0);
10737 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10738 hr
= IDirect3DVertexBuffer7_Lock(vb_strip
, 0, &data
, NULL
);
10739 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10740 memcpy(data
, quad_strip
, sizeof(quad_strip
));
10741 hr
= IDirect3DVertexBuffer7_Unlock(vb_strip
);
10742 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10744 desc
.dwNumVertices
= sizeof(quad_list
) / sizeof(*quad_list
);
10745 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &vb_list
, 0);
10746 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10747 hr
= IDirect3DVertexBuffer7_Lock(vb_list
, 0, &data
, NULL
);
10748 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10749 memcpy(data
, quad_list
, sizeof(quad_list
));
10750 hr
= IDirect3DVertexBuffer7_Unlock(vb_list
);
10751 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10753 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10754 * the color fixups we have to do for FLAT shading will be dependent on that. */
10756 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
10758 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
10759 ok(hr
== D3D_OK
, "Failed to clear, hr %#x.\n", hr
);
10761 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
10762 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
10764 hr
= IDirect3DDevice7_BeginScene(device
);
10765 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10766 buffer
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? vb_strip
: vb_list
;
10767 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
10768 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, tests
[i
].primtype
, buffer
, 0, count
, 0);
10769 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10770 hr
= IDirect3DDevice7_EndScene(device
);
10771 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10773 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
10774 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
10776 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10777 * each triangle. This requires EXT_provoking_vertex or similar
10778 * functionality being available. */
10779 /* PHONG should be the same as GOURAUD, since no hardware implements
10781 ok(compare_color(color0
, tests
[i
].color0
, 1), "Test %u shading has color0 %08x, expected %08x.\n",
10782 i
, color0
, tests
[i
].color0
);
10783 ok(compare_color(color1
, tests
[i
].color1
, 1), "Test %u shading has color1 %08x, expected %08x.\n",
10784 i
, color1
, tests
[i
].color1
);
10787 IDirect3DVertexBuffer7_Release(vb_strip
);
10788 IDirect3DVertexBuffer7_Release(vb_list
);
10789 IDirectDrawSurface7_Release(rt
);
10790 IDirect3D7_Release(d3d
);
10791 refcount
= IDirect3DDevice7_Release(device
);
10792 ok(!refcount
, "Device has %u references left.\n", refcount
);
10793 DestroyWindow(window
);
10796 static void test_lockrect_invalid(void)
10799 IDirectDraw7
*ddraw
;
10800 IDirectDrawSurface7
*surface
;
10803 DDSURFACEDESC2 surface_desc
;
10804 DDSURFACEDESC2 locked_desc
;
10806 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
10807 static RECT valid
[] =
10812 {120, 60, 128, 68},
10813 {60, 120, 68, 128},
10815 static RECT invalid
[] =
10817 {68, 60, 60, 68}, /* left > right */
10818 {60, 68, 68, 60}, /* top > bottom */
10819 {-8, 60, 0, 68}, /* left < surface */
10820 {60, -8, 68, 0}, /* top < surface */
10821 {-16, 60, -8, 68}, /* right < surface */
10822 {60, -16, 68, -8}, /* bottom < surface */
10823 {60, 60, 136, 68}, /* right > surface */
10824 {60, 60, 68, 136}, /* bottom > surface */
10825 {136, 60, 144, 68}, /* left > surface */
10826 {60, 136, 68, 144}, /* top > surface */
10828 static const struct
10836 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem offscreenplain", DDERR_INVALIDPARAMS
},
10837 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem offscreenplain", DDERR_INVALIDPARAMS
},
10838 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem texture", DD_OK
},
10839 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem texture", DDERR_INVALIDPARAMS
},
10840 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, "managed texture", DD_OK
},
10843 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10844 0, 0, 640, 480, 0, 0, 0, 0);
10845 ddraw
= create_ddraw();
10846 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10847 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10848 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10850 memset(&hal_caps
, 0, sizeof(hal_caps
));
10851 hal_caps
.dwSize
= sizeof(hal_caps
);
10852 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
10853 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
10854 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
10855 || !(hal_caps
.ddsCaps
.dwCaps
& DDSCAPS2_TEXTUREMANAGE
))
10857 skip("Required surface types not supported, skipping test.\n");
10861 for (r
= 0; r
< sizeof(resources
) / sizeof(*resources
); ++r
)
10863 memset(&surface_desc
, 0, sizeof(surface_desc
));
10864 surface_desc
.dwSize
= sizeof(surface_desc
);
10865 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10866 surface_desc
.ddsCaps
.dwCaps
= resources
[r
].caps
;
10867 surface_desc
.ddsCaps
.dwCaps2
= resources
[r
].caps2
;
10868 surface_desc
.dwWidth
= 128;
10869 surface_desc
.dwHeight
= 128;
10870 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
10871 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10872 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10873 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xff0000;
10874 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x00ff00;
10875 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x0000ff;
10877 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10878 if (is_ddraw64
&& (resources
[r
].caps
& DDSCAPS_TEXTURE
))
10880 todo_wine
ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
10882 IDirectDrawSurface7_Release(surface
);
10885 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10887 /* Crashes in ddraw7
10888 hr = IDirectDrawSurface7_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
10889 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
10892 for (i
= 0; i
< sizeof(valid
) / sizeof(*valid
); ++i
)
10894 RECT
*rect
= &valid
[i
];
10896 memset(&locked_desc
, 0, sizeof(locked_desc
));
10897 locked_desc
.dwSize
= sizeof(locked_desc
);
10899 hr
= IDirectDrawSurface7_Lock(surface
, rect
, &locked_desc
, DDLOCK_WAIT
, NULL
);
10900 ok(SUCCEEDED(hr
), "Lock failed (%#x) for rect %s, type %s.\n",
10901 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
10903 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
10904 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10907 for (i
= 0; i
< sizeof(invalid
) / sizeof(*invalid
); ++i
)
10909 RECT
*rect
= &invalid
[i
];
10911 memset(&locked_desc
, 1, sizeof(locked_desc
));
10912 locked_desc
.dwSize
= sizeof(locked_desc
);
10914 hr
= IDirectDrawSurface7_Lock(surface
, rect
, &locked_desc
, DDLOCK_WAIT
, NULL
);
10915 todo_wine_if (SUCCEEDED(resources
[r
].hr
))
10916 ok(hr
== resources
[r
].hr
, "Lock returned %#x for rect %s, type %s.\n",
10917 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
10920 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
10921 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10924 ok(!locked_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", locked_desc
.lpSurface
);
10927 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &locked_desc
, DDLOCK_WAIT
, NULL
);
10928 ok(SUCCEEDED(hr
), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
10929 hr
, resources
[r
].name
);
10930 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &locked_desc
, DDLOCK_WAIT
, NULL
);
10931 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned %#x, type %s.\n",
10932 hr
, resources
[r
].name
);
10933 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
10934 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10936 hr
= IDirectDrawSurface7_Lock(surface
, &valid
[0], &locked_desc
, DDLOCK_WAIT
, NULL
);
10937 ok(SUCCEEDED(hr
), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid
[0]), hr
);
10938 hr
= IDirectDrawSurface7_Lock(surface
, &valid
[0], &locked_desc
, DDLOCK_WAIT
, NULL
);
10939 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = %s) failed (%#x).\n",
10940 wine_dbgstr_rect(&valid
[0]), hr
);
10942 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
10943 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
10945 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
10946 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10948 IDirectDrawSurface7_Release(surface
);
10952 IDirectDraw7_Release(ddraw
);
10953 DestroyWindow(window
);
10956 static void test_yv12_overlay(void)
10958 IDirectDrawSurface7
*src_surface
, *dst_surface
;
10959 RECT rect
= {13, 17, 14, 18};
10960 unsigned int offset
, y
;
10961 DDSURFACEDESC2 desc
;
10962 unsigned char *base
;
10963 IDirectDraw7
*ddraw
;
10967 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10968 0, 0, 640, 480, 0, 0, 0, 0);
10969 ddraw
= create_ddraw();
10970 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10971 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10972 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10974 if (!(src_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
10976 skip("Failed to create a YV12 overlay, skipping test.\n");
10980 memset(&desc
, 0, sizeof(desc
));
10981 desc
.dwSize
= sizeof(desc
);
10982 hr
= IDirectDrawSurface7_Lock(src_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
10983 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10985 ok(desc
.dwFlags
== (DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_PITCH
),
10986 "Got unexpected flags %#x.\n", desc
.dwFlags
);
10987 ok(desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_HWCODEC
)
10988 || desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
10989 "Got unexpected caps %#x.\n", desc
.ddsCaps
.dwCaps
);
10990 ok(desc
.dwWidth
== 256, "Got unexpected width %u.\n", desc
.dwWidth
);
10991 ok(desc
.dwHeight
== 256, "Got unexpected height %u.\n", desc
.dwHeight
);
10992 /* The overlay pitch seems to have 256 byte alignment. */
10993 ok(!(U1(desc
).lPitch
& 0xff), "Got unexpected pitch %u.\n", U1(desc
).lPitch
);
10995 /* Fill the surface with some data for the blit test. */
10996 base
= desc
.lpSurface
;
10998 for (y
= 0; y
< desc
.dwHeight
; ++y
)
11000 memset(base
+ U1(desc
).lPitch
* y
, 0x10, desc
.dwWidth
);
11003 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 4; ++y
)
11005 memset(base
+ U1(desc
).lPitch
* y
, 0x20, desc
.dwWidth
);
11008 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 2; ++y
)
11010 memset(base
+ U1(desc
).lPitch
* y
, 0x30, desc
.dwWidth
);
11013 hr
= IDirectDrawSurface7_Unlock(src_surface
, NULL
);
11014 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11016 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
11017 * other block-based formats like DXT the entire Y channel is stored in
11018 * one big chunk of memory, followed by the chroma channels. So partial
11019 * locks do not really make sense. Show that they are allowed nevertheless
11020 * and the offset points into the luminance data. */
11021 hr
= IDirectDrawSurface7_Lock(src_surface
, &rect
, &desc
, DDLOCK_WAIT
, NULL
);
11022 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11023 offset
= ((const unsigned char *)desc
.lpSurface
- base
);
11024 ok(offset
== rect
.top
* U1(desc
).lPitch
+ rect
.left
, "Got unexpected offset %u, expected %u.\n",
11025 offset
, rect
.top
* U1(desc
).lPitch
+ rect
.left
);
11026 hr
= IDirectDrawSurface7_Unlock(src_surface
, NULL
);
11027 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11029 if (!(dst_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
11031 /* Windows XP with a Radeon X1600 GPU refuses to create a second
11032 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
11033 skip("Failed to create a second YV12 surface, skipping blit test.\n");
11034 IDirectDrawSurface7_Release(src_surface
);
11038 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, src_surface
, NULL
, DDBLT_WAIT
, NULL
);
11039 /* VMware rejects YV12 blits. This behavior has not been seen on real
11040 * hardware yet, so mark it broken. */
11041 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
), "Failed to blit, hr %#x.\n", hr
);
11045 memset(&desc
, 0, sizeof(desc
));
11046 desc
.dwSize
= sizeof(desc
);
11047 hr
= IDirectDrawSurface7_Lock(dst_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
11048 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11050 base
= desc
.lpSurface
;
11051 ok(base
[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base
[0]);
11052 base
+= desc
.dwHeight
* U1(desc
).lPitch
;
11053 todo_wine
ok(base
[0] == 0x20, "Got unexpected V data 0x%02x.\n", base
[0]);
11054 base
+= desc
.dwHeight
/ 4 * U1(desc
).lPitch
;
11055 todo_wine
ok(base
[0] == 0x30, "Got unexpected U data 0x%02x.\n", base
[0]);
11057 hr
= IDirectDrawSurface7_Unlock(dst_surface
, NULL
);
11058 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11061 IDirectDrawSurface7_Release(dst_surface
);
11062 IDirectDrawSurface7_Release(src_surface
);
11064 IDirectDraw7_Release(ddraw
);
11065 DestroyWindow(window
);
11068 static BOOL
dwm_enabled(void)
11072 if (!strcmp(winetest_platform
, "wine"))
11074 if (!pDwmIsCompositionEnabled
)
11076 if (FAILED(pDwmIsCompositionEnabled(&ret
)))
11081 static void test_offscreen_overlay(void)
11083 IDirectDrawSurface7
*overlay
, *offscreen
, *primary
;
11084 DDSURFACEDESC2 surface_desc
;
11085 IDirectDraw7
*ddraw
;
11090 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11091 0, 0, 640, 480, 0, 0, 0, 0);
11092 ddraw
= create_ddraw();
11093 ok(!!ddraw
, "Failed to create a ddraw object.\n");
11094 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
11095 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11097 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
11099 skip("Failed to create a UYVY overlay, skipping test.\n");
11103 memset(&surface_desc
, 0, sizeof(surface_desc
));
11104 surface_desc
.dwSize
= sizeof(surface_desc
);
11105 surface_desc
.dwFlags
= DDSD_CAPS
;
11106 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
11107 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
11108 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
11110 /* On Windows 7, and probably Vista, UpdateOverlay() will return
11111 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
11112 * surface prevents this by disabling the dwm. */
11113 hr
= IDirectDrawSurface7_GetDC(primary
, &dc
);
11114 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
11115 hr
= IDirectDrawSurface7_ReleaseDC(primary
, dc
);
11116 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
11118 /* Try to overlay a NULL surface. */
11119 hr
= IDirectDrawSurface7_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_SHOW
, NULL
);
11120 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
11121 hr
= IDirectDrawSurface7_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_HIDE
, NULL
);
11122 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
11124 /* Try to overlay an offscreen surface. */
11125 memset(&surface_desc
, 0, sizeof(surface_desc
));
11126 surface_desc
.dwSize
= sizeof(surface_desc
);
11127 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
11128 surface_desc
.dwWidth
= 64;
11129 surface_desc
.dwHeight
= 64;
11130 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11131 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
11132 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
11133 U4(surface_desc
).ddpfPixelFormat
.dwFourCC
= 0;
11134 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
11135 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
11136 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
11137 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
11138 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
11139 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
11141 hr
= IDirectDrawSurface7_UpdateOverlay(overlay
, NULL
, offscreen
, NULL
, DDOVER_SHOW
, NULL
);
11142 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_OUTOFCAPS
&& dwm_enabled()),
11143 "Failed to update overlay, hr %#x.\n", hr
);
11145 /* Try to overlay the primary with a non-overlay surface. */
11146 hr
= IDirectDrawSurface7_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
11147 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
11148 hr
= IDirectDrawSurface7_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
11149 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
11151 IDirectDrawSurface7_Release(offscreen
);
11152 IDirectDrawSurface7_Release(primary
);
11153 IDirectDrawSurface7_Release(overlay
);
11155 IDirectDraw7_Release(ddraw
);
11156 DestroyWindow(window
);
11159 static void test_overlay_rect(void)
11161 IDirectDrawSurface7
*overlay
, *primary
= NULL
;
11162 DDSURFACEDESC2 surface_desc
;
11163 RECT rect
= {0, 0, 64, 64};
11164 IDirectDraw7
*ddraw
;
11170 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11171 0, 0, 640, 480, 0, 0, 0, 0);
11172 ddraw
= create_ddraw();
11173 ok(!!ddraw
, "Failed to create a ddraw object.\n");
11174 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
11175 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11177 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
11179 skip("Failed to create a UYVY overlay, skipping test.\n");
11183 memset(&surface_desc
, 0, sizeof(surface_desc
));
11184 surface_desc
.dwSize
= sizeof(surface_desc
);
11185 surface_desc
.dwFlags
= DDSD_CAPS
;
11186 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
11187 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
11188 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
11190 /* On Windows 7, and probably Vista, UpdateOverlay() will return
11191 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
11192 * surface prevents this by disabling the dwm. */
11193 hr
= IDirectDrawSurface7_GetDC(primary
, &dc
);
11194 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
11195 hr
= IDirectDrawSurface7_ReleaseDC(primary
, dc
);
11196 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
11198 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
11201 win_skip("Cannot disable DWM, skipping overlay test.\n");
11205 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
11206 * used. This is not true in Windows Vista and earlier, but changed in
11208 hr
= IDirectDrawSurface7_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
11209 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
11210 hr
= IDirectDrawSurface7_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
11211 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
11212 hr
= IDirectDrawSurface7_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
11213 ok(hr
== DD_OK
|| hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
11215 /* Show that the overlay position is the (top, left) coordinate of the
11216 * destination rectangle. */
11217 OffsetRect(&rect
, 32, 16);
11218 hr
= IDirectDrawSurface7_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
11219 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
11220 pos_x
= -1; pos_y
= -1;
11221 hr
= IDirectDrawSurface7_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
11222 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
11223 ok(pos_x
== rect
.left
, "Got unexpected pos_x %d, expected %d.\n", pos_x
, rect
.left
);
11224 ok(pos_y
== rect
.top
, "Got unexpected pos_y %d, expected %d.\n", pos_y
, rect
.top
);
11226 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
11227 * seen that the overlay overlays the whole primary(==screen). */
11228 hr2
= IDirectDrawSurface7_UpdateOverlay(overlay
, NULL
, primary
, NULL
, 0, NULL
);
11229 ok(hr2
== DD_OK
|| hr2
== DDERR_INVALIDPARAMS
|| hr2
== DDERR_OUTOFCAPS
, "Got unexpected hr %#x.\n", hr2
);
11230 hr
= IDirectDrawSurface7_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
11231 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
11232 if (SUCCEEDED(hr2
))
11234 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
11235 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
11239 ok(pos_x
== 32, "Got unexpected pos_x %d.\n", pos_x
);
11240 ok(pos_y
== 16, "Got unexpected pos_y %d.\n", pos_y
);
11243 /* The position cannot be retrieved when the overlay is not shown. */
11244 hr
= IDirectDrawSurface7_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_HIDE
, NULL
);
11245 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
11246 pos_x
= -1; pos_y
= -1;
11247 hr
= IDirectDrawSurface7_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
11248 ok(hr
== DDERR_OVERLAYNOTVISIBLE
, "Got unexpected hr %#x.\n", hr
);
11249 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
11250 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
11252 IDirectDrawSurface7_Release(overlay
);
11255 IDirectDrawSurface7_Release(primary
);
11256 IDirectDraw7_Release(ddraw
);
11257 DestroyWindow(window
);
11260 static void test_blt(void)
11262 IDirectDrawSurface7
*surface
, *rt
;
11263 DDSURFACEDESC2 surface_desc
;
11264 IDirect3DDevice7
*device
;
11265 IDirectDraw7
*ddraw
;
11280 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit. */
11281 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, flipped source. */
11282 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, mirrored source. */
11283 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched x. */
11284 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched y. */
11285 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK
}, /* Full surface blit. */
11286 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT
}, /* Full surface, flipped destination. */
11287 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored destination. */
11288 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, flipped source. */
11289 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored source. */
11292 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11293 0, 0, 640, 480, 0, 0, 0, 0);
11294 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
11296 skip("Failed to create a 3D device, skipping test.\n");
11297 DestroyWindow(window
);
11301 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
11302 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
11303 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
11304 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
11305 IDirect3D7_Release(d3d
);
11306 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
11307 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
11309 memset(&surface_desc
, 0, sizeof(surface_desc
));
11310 surface_desc
.dwSize
= sizeof(surface_desc
);
11311 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
11312 surface_desc
.dwWidth
= 640;
11313 surface_desc
.dwHeight
= 480;
11314 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11315 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
11316 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
11318 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface
, NULL
, 0, NULL
);
11319 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11321 hr
= IDirectDrawSurface_Blt(surface
, NULL
, rt
, NULL
, 0, NULL
);
11322 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11324 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
11326 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
11327 surface
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
11328 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
11330 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
11331 rt
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
11332 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
11335 IDirectDrawSurface7_Release(surface
);
11336 IDirectDrawSurface7_Release(rt
);
11337 IDirectDraw7_Release(ddraw
);
11338 refcount
= IDirect3DDevice7_Release(device
);
11339 ok(!refcount
, "Device has %u references left.\n", refcount
);
11340 DestroyWindow(window
);
11343 static void test_color_clamping(void)
11345 static D3DMATRIX mat
=
11347 1.0f
, 0.0f
, 0.0f
, 0.0f
,
11348 0.0f
, 1.0f
, 0.0f
, 0.0f
,
11349 0.0f
, 0.0f
, 1.0f
, 0.0f
,
11350 0.0f
, 0.0f
, 0.0f
, 1.0f
,
11352 static struct vec3 quad
[] =
11354 {-1.0f
, -1.0f
, 0.1f
},
11355 {-1.0f
, 1.0f
, 0.1f
},
11356 { 1.0f
, -1.0f
, 0.1f
},
11357 { 1.0f
, 1.0f
, 0.1f
},
11359 IDirect3DDevice7
*device
;
11360 IDirectDrawSurface7
*rt
;
11366 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11367 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
11369 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
11371 skip("Failed to create a 3D device, skipping test.\n");
11372 DestroyWindow(window
);
11376 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
11377 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
11379 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
11380 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11381 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
11382 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
11383 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
11384 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
11385 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
11386 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
11387 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
11388 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
11389 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
11390 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
11391 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
11392 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
11393 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
11394 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
11395 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
11396 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
11398 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0xff404040);
11399 ok(SUCCEEDED(hr
), "Failed to set texture factor, hr %#x.\n", hr
);
11400 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_ADD
);
11401 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
11402 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
);
11403 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
11404 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_SPECULAR
);
11405 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
11406 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
11407 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
11408 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
11409 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
11410 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
11411 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
11413 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
11414 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
11416 hr
= IDirect3DDevice7_BeginScene(device
);
11417 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11419 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, 0);
11420 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11422 hr
= IDirect3DDevice7_EndScene(device
);
11423 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11425 color
= get_surface_color(rt
, 320, 240);
11426 ok(compare_color(color
, 0x00404040, 1), "Got unexpected color 0x%08x.\n", color
);
11428 IDirectDrawSurface7_Release(rt
);
11429 refcount
= IDirect3DDevice7_Release(device
);
11430 ok(!refcount
, "Device has %u references left.\n", refcount
);
11431 DestroyWindow(window
);
11434 static void test_getdc(void)
11436 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, DDSCAPS2_CUBEMAP_NEGATIVEZ
, 0, {0}};
11437 IDirectDrawSurface7
*surface
, *surface2
, *tmp
;
11438 DDSURFACEDESC2 surface_desc
, map_desc
;
11439 IDirectDraw7
*ddraw
;
11445 static const struct
11448 DDPIXELFORMAT format
;
11449 BOOL getdc_supported
;
11450 HRESULT alt_result
;
11454 {"D3DFMT_A8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
11455 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE
},
11456 {"D3DFMT_X8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
11457 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE
},
11458 {"D3DFMT_R5G6B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
11459 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE
},
11460 {"D3DFMT_X1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
11461 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE
},
11462 {"D3DFMT_A1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
11463 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE
},
11464 {"D3DFMT_A4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
11465 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11466 {"D3DFMT_X4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
11467 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11468 {"D3DFMT_A2R10G10B10", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
11469 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE
},
11470 {"D3DFMT_A8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
11471 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11472 {"D3DFMT_X8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
11473 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11474 {"D3DFMT_R3G3B2", {sizeof(test_data
->format
), DDPF_RGB
, 0, {8},
11475 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE
},
11476 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
11477 * This is not implemented in wine yet, so disable the test for now.
11478 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
11479 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
11480 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11482 {"D3DFMT_L8", {sizeof(test_data
->format
), DDPF_LUMINANCE
, 0, {8},
11483 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11484 {"D3DFMT_A8L8", {sizeof(test_data
->format
), DDPF_ALPHAPIXELS
| DDPF_LUMINANCE
, 0, {16},
11485 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE
},
11486 {"D3DFMT_DXT1", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','1'), {0},
11487 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11488 {"D3DFMT_DXT2", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','2'), {0},
11489 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11490 {"D3DFMT_DXT3", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','3'), {0},
11491 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11492 {"D3DFMT_DXT4", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','4'), {0},
11493 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11494 {"D3DFMT_DXT5", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','5'), {0},
11495 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11498 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11499 0, 0, 640, 480, 0, 0, 0, 0);
11500 ddraw
= create_ddraw();
11501 ok(!!ddraw
, "Failed to create a ddraw object.\n");
11502 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
11503 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11505 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
11507 memset(&surface_desc
, 0, sizeof(surface_desc
));
11508 surface_desc
.dwSize
= sizeof(surface_desc
);
11509 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
11510 surface_desc
.dwWidth
= 64;
11511 surface_desc
.dwHeight
= 64;
11512 U4(surface_desc
).ddpfPixelFormat
= test_data
[i
].format
;
11513 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11515 if (FAILED(IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11517 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
11518 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
11519 if (FAILED(hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11521 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data
[i
].name
, hr
);
11526 dc
= (void *)0x1234;
11527 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
11528 if (test_data
[i
].getdc_supported
)
11529 ok(SUCCEEDED(hr
) || (test_data
[i
].alt_result
&& hr
== test_data
[i
].alt_result
),
11530 "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11532 ok(FAILED(hr
), "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11536 unsigned int width_bytes
;
11542 type
= GetObjectType(dc
);
11543 ok(type
== OBJ_MEMDC
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
11544 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
11545 type
= GetObjectType(bitmap
);
11546 ok(type
== OBJ_BITMAP
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
11548 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
11549 ok(size
== sizeof(dib
), "Got unexpected size %d for format %s.\n", size
, test_data
[i
].name
);
11550 ok(!dib
.dsBm
.bmType
, "Got unexpected type %#x for format %s.\n",
11551 dib
.dsBm
.bmType
, test_data
[i
].name
);
11552 ok(dib
.dsBm
.bmWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
11553 dib
.dsBm
.bmWidth
, test_data
[i
].name
);
11554 ok(dib
.dsBm
.bmHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
11555 dib
.dsBm
.bmHeight
, test_data
[i
].name
);
11556 width_bytes
= ((dib
.dsBm
.bmWidth
* U1(test_data
[i
].format
).dwRGBBitCount
+ 31) >> 3) & ~3;
11557 ok(dib
.dsBm
.bmWidthBytes
== width_bytes
, "Got unexpected width bytes %d for format %s.\n",
11558 dib
.dsBm
.bmWidthBytes
, test_data
[i
].name
);
11559 ok(dib
.dsBm
.bmPlanes
== 1, "Got unexpected plane count %d for format %s.\n",
11560 dib
.dsBm
.bmPlanes
, test_data
[i
].name
);
11561 ok(dib
.dsBm
.bmBitsPixel
== U1(test_data
[i
].format
).dwRGBBitCount
,
11562 "Got unexpected bit count %d for format %s.\n",
11563 dib
.dsBm
.bmBitsPixel
, test_data
[i
].name
);
11564 ok(!!dib
.dsBm
.bmBits
, "Got unexpected bits %p for format %s.\n",
11565 dib
.dsBm
.bmBits
, test_data
[i
].name
);
11567 ok(dib
.dsBmih
.biSize
== sizeof(dib
.dsBmih
), "Got unexpected size %u for format %s.\n",
11568 dib
.dsBmih
.biSize
, test_data
[i
].name
);
11569 ok(dib
.dsBmih
.biWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
11570 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
11571 ok(dib
.dsBmih
.biHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
11572 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
11573 ok(dib
.dsBmih
.biPlanes
== 1, "Got unexpected plane count %u for format %s.\n",
11574 dib
.dsBmih
.biPlanes
, test_data
[i
].name
);
11575 ok(dib
.dsBmih
.biBitCount
== U1(test_data
[i
].format
).dwRGBBitCount
,
11576 "Got unexpected bit count %u for format %s.\n",
11577 dib
.dsBmih
.biBitCount
, test_data
[i
].name
);
11578 ok(dib
.dsBmih
.biCompression
== (U1(test_data
[i
].format
).dwRGBBitCount
== 16 ? BI_BITFIELDS
: BI_RGB
)
11579 || broken(U2(test_data
[i
].format
).dwRGBBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_BITFIELDS
),
11580 "Got unexpected compression %#x for format %s.\n",
11581 dib
.dsBmih
.biCompression
, test_data
[i
].name
);
11582 ok(!dib
.dsBmih
.biSizeImage
, "Got unexpected image size %u for format %s.\n",
11583 dib
.dsBmih
.biSizeImage
, test_data
[i
].name
);
11584 ok(!dib
.dsBmih
.biXPelsPerMeter
, "Got unexpected horizontal resolution %d for format %s.\n",
11585 dib
.dsBmih
.biXPelsPerMeter
, test_data
[i
].name
);
11586 ok(!dib
.dsBmih
.biYPelsPerMeter
, "Got unexpected vertical resolution %d for format %s.\n",
11587 dib
.dsBmih
.biYPelsPerMeter
, test_data
[i
].name
);
11588 ok(!dib
.dsBmih
.biClrUsed
, "Got unexpected used colour count %u for format %s.\n",
11589 dib
.dsBmih
.biClrUsed
, test_data
[i
].name
);
11590 ok(!dib
.dsBmih
.biClrImportant
, "Got unexpected important colour count %u for format %s.\n",
11591 dib
.dsBmih
.biClrImportant
, test_data
[i
].name
);
11593 if (dib
.dsBmih
.biCompression
== BI_BITFIELDS
)
11595 ok((dib
.dsBitfields
[0] == U2(test_data
[i
].format
).dwRBitMask
11596 && dib
.dsBitfields
[1] == U3(test_data
[i
].format
).dwGBitMask
11597 && dib
.dsBitfields
[2] == U4(test_data
[i
].format
).dwBBitMask
)
11598 || broken(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2]),
11599 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11600 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
11604 ok(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2],
11605 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11606 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
11608 ok(!dib
.dshSection
, "Got unexpected section %p for format %s.\n", dib
.dshSection
, test_data
[i
].name
);
11609 ok(!dib
.dsOffset
, "Got unexpected offset %u for format %s.\n", dib
.dsOffset
, test_data
[i
].name
);
11611 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11612 ok(hr
== DD_OK
, "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11616 ok(!dc
, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
11619 IDirectDrawSurface7_Release(surface
);
11624 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
11625 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_TEXTUREMANAGE
;
11626 if (FAILED(hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11628 skip("Failed to create cube texture for format %s (hr %#x), skipping tests.\n", test_data
[i
].name
, hr
);
11632 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &surface2
);
11633 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11634 hr
= IDirectDrawSurface7_GetAttachedSurface(surface2
, &caps
, &tmp
);
11635 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11636 IDirectDrawSurface7_Release(surface2
);
11637 hr
= IDirectDrawSurface7_GetAttachedSurface(tmp
, &caps
, &surface2
);
11638 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11639 IDirectDrawSurface7_Release(tmp
);
11641 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
11642 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11643 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11644 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11645 hr
= IDirectDrawSurface7_GetDC(surface2
, &dc
);
11646 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11647 hr
= IDirectDrawSurface7_ReleaseDC(surface2
, dc
);
11648 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11650 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
11651 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11652 dc2
= (void *)0x1234;
11653 hr
= IDirectDrawSurface7_GetDC(surface
, &dc2
);
11654 ok(hr
== DDERR_DCALREADYCREATED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11655 ok(dc2
== (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
11656 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11657 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11658 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11659 ok(hr
== DDERR_NODC
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11661 map_desc
.dwSize
= sizeof(map_desc
);
11662 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11663 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11664 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11665 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11666 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
11667 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11668 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
11669 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11671 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
11672 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11673 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11674 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11675 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11676 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11678 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11679 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11680 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
11681 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11682 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11683 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11684 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
11685 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11687 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
11688 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11689 hr
= IDirectDrawSurface7_GetDC(surface2
, &dc2
);
11690 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11691 hr
= IDirectDrawSurface7_ReleaseDC(surface2
, dc2
);
11692 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11693 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11694 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11696 hr
= IDirectDrawSurface7_GetDC(surface2
, &dc
);
11697 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11698 hr
= IDirectDrawSurface7_GetDC(surface
, &dc2
);
11699 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11700 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc2
);
11701 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11702 hr
= IDirectDrawSurface7_ReleaseDC(surface2
, dc
);
11703 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11705 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11706 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11707 hr
= IDirectDrawSurface7_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11708 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11709 hr
= IDirectDrawSurface7_Unlock(surface2
, NULL
);
11710 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11711 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
11712 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11714 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11715 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11716 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
11717 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11718 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11719 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11720 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
11721 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11723 hr
= IDirectDrawSurface7_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11724 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11725 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
11726 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11727 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11728 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11729 hr
= IDirectDrawSurface7_Unlock(surface2
, NULL
);
11730 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11732 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
11733 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11734 hr
= IDirectDrawSurface7_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11735 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11736 hr
= IDirectDrawSurface7_Unlock(surface2
, NULL
);
11737 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11738 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11739 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11741 hr
= IDirectDrawSurface7_GetDC(surface2
, &dc
);
11742 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11743 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11744 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11745 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
11746 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11747 hr
= IDirectDrawSurface7_ReleaseDC(surface2
, dc
);
11748 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11750 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
11751 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11752 hr
= IDirectDrawSurface7_GetDC(surface2
, &dc
);
11753 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11754 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
11755 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11756 hr
= IDirectDrawSurface7_ReleaseDC(surface2
, dc
);
11757 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11758 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
11759 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11761 hr
= IDirectDrawSurface7_Unlock(surface2
, NULL
);
11762 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11763 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
11764 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11765 hr
= IDirectDrawSurface7_Unlock(surface2
, NULL
);
11766 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11767 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
11768 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11769 hr
= IDirectDrawSurface7_Unlock(surface2
, NULL
);
11770 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11772 IDirectDrawSurface7_Release(surface2
);
11773 IDirectDrawSurface7_Release(surface
);
11776 IDirectDraw7_Release(ddraw
);
11777 DestroyWindow(window
);
11780 static void test_draw_primitive(void)
11782 static WORD indices
[] = {0, 1, 2, 3};
11783 static struct vec3 quad
[] =
11785 {-1.0f
, -1.0f
, 0.0f
},
11786 {-1.0f
, 1.0f
, 0.0f
},
11787 { 1.0f
, -1.0f
, 0.0f
},
11788 { 1.0f
, 1.0f
, 0.0f
},
11790 D3DDRAWPRIMITIVESTRIDEDDATA strided
;
11791 D3DVERTEXBUFFERDESC vb_desc
;
11792 IDirect3DVertexBuffer7
*vb
;
11793 IDirect3DDevice7
*device
;
11800 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11801 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
11803 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
11805 skip("Failed to create a 3D device, skipping test.\n");
11806 DestroyWindow(window
);
11810 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
11811 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
11813 memset(&vb_desc
, 0, sizeof(vb_desc
));
11814 vb_desc
.dwSize
= sizeof(vb_desc
);
11815 vb_desc
.dwFVF
= D3DFVF_XYZ
;
11816 vb_desc
.dwNumVertices
= 4;
11817 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &vb_desc
, &vb
, 0);
11818 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
11820 IDirect3D7_Release(d3d
);
11822 memset(&strided
, 0, sizeof(strided
));
11824 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, NULL
, 0, 0);
11825 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11826 hr
= IDirect3DDevice7_DrawIndexedPrimitiveStrided(device
,
11827 D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, &strided
, 0, NULL
, 0, 0);
11828 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11829 hr
= IDirect3DDevice7_DrawIndexedPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, vb
, 0, 0, NULL
, 0, 0);
11830 todo_wine
ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
11831 hr
= IDirect3DDevice7_DrawIndexedPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, vb
, 0, 0, NULL
, 0, 0);
11832 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11833 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, 0);
11834 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11835 hr
= IDirect3DDevice7_DrawPrimitiveStrided(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, &strided
, 0, 0);
11836 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11837 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, vb
, 0, 0, 0);
11838 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11840 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, indices
, 4, 0);
11841 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11842 hr
= IDirect3DDevice7_DrawIndexedPrimitiveStrided(device
,
11843 D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, &strided
, 0, indices
, 4, 0);
11844 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11845 hr
= IDirect3DDevice7_DrawIndexedPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, vb
, 0, 0, indices
, 4, 0);
11846 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11848 strided
.position
.lpvData
= quad
;
11849 strided
.position
.dwStride
= sizeof(*quad
);
11850 hr
= IDirect3DVertexBuffer7_Lock(vb
, 0, &data
, NULL
);
11851 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
11852 memcpy(data
, quad
, sizeof(quad
));
11853 hr
= IDirect3DVertexBuffer7_Unlock(vb
);
11854 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
11856 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, NULL
, 0, 0);
11857 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11858 hr
= IDirect3DDevice7_DrawIndexedPrimitiveStrided(device
,
11859 D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, &strided
, 4, NULL
, 0, 0);
11860 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11861 hr
= IDirect3DDevice7_DrawIndexedPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, vb
, 0, 4, NULL
, 0, 0);
11862 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11863 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, 0);
11864 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11865 hr
= IDirect3DDevice7_DrawPrimitiveStrided(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, &strided
, 4, 0);
11866 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11867 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, vb
, 0, 4, 0);
11868 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11870 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, indices
, 4, 0);
11871 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11872 hr
= IDirect3DDevice7_DrawIndexedPrimitiveStrided(device
,
11873 D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, &strided
, 4, indices
, 4, 0);
11874 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11875 hr
= IDirect3DDevice7_DrawIndexedPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, vb
, 0, 4, indices
, 4, 0);
11876 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11878 IDirect3DVertexBuffer7_Release(vb
);
11879 refcount
= IDirect3DDevice7_Release(device
);
11880 ok(!refcount
, "Device has %u references left.\n", refcount
);
11881 DestroyWindow(window
);
11884 static void test_edge_antialiasing_blending(void)
11886 IDirectDrawSurface7
*offscreen
;
11887 DDSURFACEDESC2 surface_desc
;
11888 D3DDEVICEDESC7 device_desc
;
11889 IDirect3DDevice7
*device
;
11890 IDirectDraw7
*ddraw
;
11897 static D3DMATRIX mat
=
11899 1.0f
, 0.0f
, 0.0f
, 0.0f
,
11900 0.0f
, 1.0f
, 0.0f
, 0.0f
,
11901 0.0f
, 0.0f
, 1.0f
, 0.0f
,
11902 0.0f
, 0.0f
, 0.0f
, 1.0f
,
11906 struct vec3 position
;
11911 {{-1.0f
, -1.0f
, 0.1f
}, 0x7f00ff00},
11912 {{-1.0f
, 1.0f
, 0.1f
}, 0x7f00ff00},
11913 {{ 1.0f
, -1.0f
, 0.1f
}, 0x7f00ff00},
11914 {{ 1.0f
, 1.0f
, 0.1f
}, 0x7f00ff00},
11918 struct vec3 position
;
11923 {{-1.0f
, -1.0f
, 0.1f
}, 0xccff0000},
11924 {{-1.0f
, 1.0f
, 0.1f
}, 0xccff0000},
11925 {{ 1.0f
, -1.0f
, 0.1f
}, 0xccff0000},
11926 {{ 1.0f
, 1.0f
, 0.1f
}, 0xccff0000},
11929 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11930 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
11931 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
11933 skip("Failed to create a 3D device.\n");
11934 DestroyWindow(window
);
11938 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
11939 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
11940 trace("Line edge antialiasing support: %#x.\n",
11941 device_desc
.dpcLineCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
11942 trace("Triangle edge antialiasing support: %#x.\n",
11943 device_desc
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
11945 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
11946 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
11947 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
11948 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
11949 IDirect3D7_Release(d3d
);
11951 memset(&surface_desc
, 0, sizeof(surface_desc
));
11952 surface_desc
.dwSize
= sizeof(surface_desc
);
11953 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
11954 surface_desc
.dwWidth
= 640;
11955 surface_desc
.dwHeight
= 480;
11956 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
;
11957 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
11958 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
11959 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
11960 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
11961 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
11962 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
11963 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
11964 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr %#x.\n", hr
);
11966 hr
= IDirect3DDevice7_SetRenderTarget(device
, offscreen
, 0);
11967 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
11969 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
11970 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11971 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
11972 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
11973 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
11974 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
11975 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
11976 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
11977 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
11978 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
11979 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
11980 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
11981 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
11982 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
11983 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
11984 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
11985 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
11986 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
11988 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
11989 ok(SUCCEEDED(hr
), "Failed to enable blending, hr %#x.\n", hr
);
11990 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
11991 ok(SUCCEEDED(hr
), "Failed to set src blend, hr %#x.\n", hr
);
11992 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_DESTALPHA
);
11993 ok(SUCCEEDED(hr
), "Failed to set dest blend, hr %#x.\n", hr
);
11995 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
11996 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
11997 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
);
11998 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
11999 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_ALPHAOP
, D3DTOP_SELECTARG1
);
12000 ok(SUCCEEDED(hr
), "Failed to set alpha op, hr %#x.\n", hr
);
12001 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_ALPHAARG1
, D3DTA_DIFFUSE
);
12002 ok(SUCCEEDED(hr
), "Failed to set alpha arg, hr %#x.\n", hr
);
12004 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xccff0000, 0.0f
, 0);
12005 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12006 hr
= IDirect3DDevice7_BeginScene(device
);
12007 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
12008 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
12010 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12011 hr
= IDirect3DDevice7_EndScene(device
);
12012 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12013 color
= get_surface_color(offscreen
, 320, 240);
12014 ok(compare_color(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
12016 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f00ff00, 0.0f
, 0);
12017 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12018 hr
= IDirect3DDevice7_BeginScene(device
);
12019 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
12020 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
12022 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12023 hr
= IDirect3DDevice7_EndScene(device
);
12024 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12025 color
= get_surface_color(offscreen
, 320, 240);
12026 ok(compare_color(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
12028 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
12029 ok(SUCCEEDED(hr
), "Failed to disable blending, hr %#x.\n", hr
);
12031 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xccff0000, 0.0f
, 0);
12032 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12033 hr
= IDirect3DDevice7_BeginScene(device
);
12034 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
12035 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
12037 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12038 hr
= IDirect3DDevice7_EndScene(device
);
12039 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12040 color
= get_surface_color(offscreen
, 320, 240);
12041 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
12043 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f00ff00, 0.0f
, 0);
12044 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12045 hr
= IDirect3DDevice7_BeginScene(device
);
12046 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
12047 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
12049 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12050 hr
= IDirect3DDevice7_EndScene(device
);
12051 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12052 color
= get_surface_color(offscreen
, 320, 240);
12053 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
12055 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_EDGEANTIALIAS
, TRUE
);
12056 ok(SUCCEEDED(hr
), "Failed to enable edge antialiasing, hr %#x.\n", hr
);
12058 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xccff0000, 0.0f
, 0);
12059 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12060 hr
= IDirect3DDevice7_BeginScene(device
);
12061 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
12062 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
12064 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12065 hr
= IDirect3DDevice7_EndScene(device
);
12066 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12067 color
= get_surface_color(offscreen
, 320, 240);
12068 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
12070 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x7f00ff00, 0.0f
, 0);
12071 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12072 hr
= IDirect3DDevice7_BeginScene(device
);
12073 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
12074 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
12076 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12077 hr
= IDirect3DDevice7_EndScene(device
);
12078 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12079 color
= get_surface_color(offscreen
, 320, 240);
12080 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
12082 IDirectDrawSurface7_Release(offscreen
);
12083 IDirectDraw7_Release(ddraw
);
12084 refcount
= IDirect3DDevice7_Release(device
);
12085 ok(!refcount
, "Device has %u references left.\n", refcount
);
12086 DestroyWindow(window
);
12091 HMODULE module
= GetModuleHandleA("ddraw.dll");
12093 IDirectDraw7
*ddraw
;
12094 DEVMODEW current_mode
;
12096 if (!(pDirectDrawCreateEx
= (void *)GetProcAddress(module
, "DirectDrawCreateEx")))
12098 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
12102 if (!(ddraw
= create_ddraw()))
12104 skip("Failed to create a ddraw object, skipping tests.\n");
12107 IDirectDraw7_Release(ddraw
);
12109 memset(¤t_mode
, 0, sizeof(current_mode
));
12110 current_mode
.dmSize
= sizeof(current_mode
);
12111 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
12112 registry_mode
.dmSize
= sizeof(registry_mode
);
12113 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
12114 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
12115 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
12117 skip("Current mode does not match registry mode, skipping test.\n");
12121 if ((dwmapi
= LoadLibraryA("dwmapi.dll")))
12122 pDwmIsCompositionEnabled
= (void *)GetProcAddress(dwmapi
, "DwmIsCompositionEnabled");
12124 test_process_vertices();
12125 test_coop_level_create_device_window();
12126 test_clipper_blt();
12127 test_coop_level_d3d_state();
12128 test_surface_interface_mismatch();
12129 test_coop_level_threaded();
12131 test_texture_load_ckey();
12139 test_window_style();
12140 test_redundant_mode_set();
12141 test_coop_level_mode_set();
12142 test_coop_level_mode_set_multi();
12144 test_coop_level_surf_create();
12146 test_coop_level_multi_window();
12147 test_draw_strided();
12149 test_specular_lighting();
12150 test_clear_rect_count();
12151 test_coop_level_versions();
12152 test_fog_special();
12153 test_lighting_interface_versions();
12154 test_coop_level_activateapp();
12155 test_texturemanage();
12156 test_block_formats_creation();
12157 test_unsupported_formats();
12159 test_primary_caps();
12160 test_surface_lock();
12161 test_surface_discard();
12163 test_set_surface_desc();
12164 test_user_memory_getdc();
12165 test_sysmem_overlay();
12166 test_primary_palette();
12167 test_surface_attachment();
12168 test_private_data();
12169 test_pixel_format();
12170 test_create_surface_pitch();
12172 test_palette_complex();
12175 test_palette_gdi();
12176 test_palette_alpha();
12177 test_vb_writeonly();
12178 test_lost_device();
12179 test_resource_priority();
12180 test_surface_desc_lock();
12181 test_fog_interpolation();
12182 test_negative_fixedfunction_fog();
12183 test_table_fog_zw();
12184 test_signed_formats();
12186 test_texcoordindex();
12187 test_colorkey_precision();
12188 test_range_colorkey();
12190 test_lockrect_invalid();
12191 test_yv12_overlay();
12192 test_offscreen_overlay();
12193 test_overlay_rect();
12195 test_color_clamping();
12197 test_draw_primitive();
12198 test_edge_antialiasing_blending();