2 * Copyright 2011-2012 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/test.h"
23 struct create_window_thread_param
26 HANDLE window_created
;
27 HANDLE destroy_window
;
31 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
33 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
35 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
37 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
39 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
43 static DWORD WINAPI
create_window_thread_proc(void *param
)
45 struct create_window_thread_param
*p
= param
;
49 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
50 0, 0, 640, 480, 0, 0, 0, 0);
51 ret
= SetEvent(p
->window_created
);
52 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
58 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
59 DispatchMessage(&msg
);
60 res
= WaitForSingleObject(p
->destroy_window
, 100);
61 if (res
== WAIT_OBJECT_0
)
63 if (res
!= WAIT_TIMEOUT
)
65 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
70 DestroyWindow(p
->window
);
75 static void create_window_thread(struct create_window_thread_param
*p
)
79 p
->window_created
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
80 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
81 p
->destroy_window
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
82 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
83 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
84 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
85 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
86 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
89 static void destroy_window_thread(struct create_window_thread_param
*p
)
91 SetEvent(p
->destroy_window
);
92 WaitForSingleObject(p
->thread
, INFINITE
);
93 CloseHandle(p
->destroy_window
);
94 CloseHandle(p
->window_created
);
95 CloseHandle(p
->thread
);
98 static D3DCOLOR
get_surface_color(IDirectDrawSurface
*surface
, UINT x
, UINT y
)
100 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
101 DDSURFACEDESC surface_desc
;
105 memset(&surface_desc
, 0, sizeof(surface_desc
));
106 surface_desc
.dwSize
= sizeof(surface_desc
);
108 hr
= IDirectDrawSurface_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
109 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
113 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
115 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
116 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
121 static void emit_process_vertices(void **ptr
, WORD base_idx
, DWORD vertex_count
)
123 D3DINSTRUCTION
*inst
= *ptr
;
124 D3DPROCESSVERTICES
*pv
= (D3DPROCESSVERTICES
*)(inst
+ 1);
126 inst
->bOpcode
= D3DOP_PROCESSVERTICES
;
127 inst
->bSize
= sizeof(*pv
);
130 pv
->dwFlags
= D3DPROCESSVERTICES_COPY
;
131 pv
->wStart
= base_idx
;
133 pv
->dwCount
= vertex_count
;
139 static void emit_set_rs(void **ptr
, D3DRENDERSTATETYPE state
, DWORD value
)
141 D3DINSTRUCTION
*inst
= *ptr
;
142 D3DSTATE
*rs
= (D3DSTATE
*)(inst
+ 1);
144 inst
->bOpcode
= D3DOP_STATERENDER
;
145 inst
->bSize
= sizeof(*rs
);
148 U1(*rs
).drstRenderStateType
= state
;
149 U2(*rs
).dwArg
[0] = value
;
154 static void emit_tquad(void **ptr
, WORD base_idx
)
156 D3DINSTRUCTION
*inst
= *ptr
;
157 D3DTRIANGLE
*tri
= (D3DTRIANGLE
*)(inst
+ 1);
159 inst
->bOpcode
= D3DOP_TRIANGLE
;
160 inst
->bSize
= sizeof(*tri
);
163 U1(*tri
).v1
= base_idx
;
164 U2(*tri
).v2
= base_idx
+ 1;
165 U3(*tri
).v3
= base_idx
+ 2;
166 tri
->wFlags
= D3DTRIFLAG_START
;
169 U1(*tri
).v1
= base_idx
+ 2;
170 U2(*tri
).v2
= base_idx
+ 1;
171 U3(*tri
).v3
= base_idx
+ 3;
172 tri
->wFlags
= D3DTRIFLAG_ODD
;
178 static void emit_end(void **ptr
)
180 D3DINSTRUCTION
*inst
= *ptr
;
182 inst
->bOpcode
= D3DOP_EXIT
;
189 static HRESULT CALLBACK
enum_z_fmt(GUID
*guid
, char *description
, char *name
,
190 D3DDEVICEDESC
*hal_desc
, D3DDEVICEDESC
*hel_desc
, void *ctx
)
192 DWORD
*z_depth
= ctx
;
194 if (!IsEqualGUID(&IID_IDirect3DHALDevice
, guid
))
195 return D3DENUMRET_OK
;
197 if (hal_desc
->dwDeviceZBufferBitDepth
& DDBD_32
)
199 else if (hal_desc
->dwDeviceZBufferBitDepth
& DDBD_24
)
201 else if (hal_desc
->dwDeviceZBufferBitDepth
& DDBD_16
)
207 static IDirectDraw
*create_ddraw(void)
211 if (FAILED(DirectDrawCreate(NULL
, &ddraw
, NULL
)))
217 static IDirect3DDevice
*create_device(IDirectDraw
*ddraw
, HWND window
, DWORD coop_level
)
219 IDirectDrawSurface
*surface
, *ds
;
220 IDirect3DDevice
*device
= NULL
;
221 DDSURFACEDESC surface_desc
;
226 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, coop_level
);
227 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
229 memset(&surface_desc
, 0, sizeof(surface_desc
));
230 surface_desc
.dwSize
= sizeof(surface_desc
);
231 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
232 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
233 surface_desc
.dwWidth
= 640;
234 surface_desc
.dwHeight
= 480;
236 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
237 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
239 if (coop_level
& DDSCL_NORMAL
)
241 IDirectDrawClipper
*clipper
;
243 hr
= IDirectDraw_CreateClipper(ddraw
, 0, &clipper
, NULL
);
244 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
245 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
246 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
247 hr
= IDirectDrawSurface_SetClipper(surface
, clipper
);
248 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
249 IDirectDrawClipper_Release(clipper
);
252 hr
= IDirectDraw_QueryInterface(ddraw
, &IID_IDirect3D
, (void **)&d3d
);
255 IDirectDrawSurface_Release(surface
);
259 hr
= IDirect3D_EnumDevices(d3d
, enum_z_fmt
, &z_depth
);
260 ok(SUCCEEDED(hr
), "Failed to enumerate z-formats, hr %#x.\n", hr
);
261 IDirect3D_Release(d3d
);
262 if (FAILED(hr
) || !z_depth
)
264 IDirectDrawSurface_Release(surface
);
268 memset(&surface_desc
, 0, sizeof(surface_desc
));
269 surface_desc
.dwSize
= sizeof(surface_desc
);
270 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
271 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
272 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
273 surface_desc
.dwWidth
= 640;
274 surface_desc
.dwHeight
= 480;
275 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
276 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
279 IDirectDrawSurface_Release(surface
);
283 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
284 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
285 IDirectDrawSurface_Release(ds
);
288 IDirectDrawSurface_Release(surface
);
292 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DHALDevice
, (void **)&device
);
293 IDirectDrawSurface_Release(surface
);
300 static IDirect3DViewport
*create_viewport(IDirect3DDevice
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
302 IDirect3DViewport
*viewport
;
307 hr
= IDirect3DDevice_GetDirect3D(device
, &d3d
);
308 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
309 hr
= IDirect3D_CreateViewport(d3d
, &viewport
, NULL
);
310 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
311 hr
= IDirect3DDevice_AddViewport(device
, viewport
);
312 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
313 memset(&vp
, 0, sizeof(vp
));
314 vp
.dwSize
= sizeof(vp
);
319 vp
.dvScaleX
= (float)w
/ 2.0f
;
320 vp
.dvScaleY
= (float)h
/ 2.0f
;
325 hr
= IDirect3DViewport_SetViewport(viewport
, &vp
);
326 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
327 IDirect3D_Release(d3d
);
332 static void destroy_viewport(IDirect3DDevice
*device
, IDirect3DViewport
*viewport
)
336 hr
= IDirect3DDevice_DeleteViewport(device
, viewport
);
337 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
338 IDirect3DViewport_Release(viewport
);
341 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
343 HRESULT hr
= IDirectDrawSurface_Restore(surface
);
344 ok(SUCCEEDED(hr
), "Failed to restore surface, hr %#x.\n", hr
);
345 IDirectDrawSurface_Release(surface
);
350 static HRESULT
restore_surfaces(IDirectDraw
*ddraw
)
352 return IDirectDraw_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
353 NULL
, NULL
, restore_callback
);
356 static void test_coop_level_create_device_window(void)
358 HWND focus_window
, device_window
;
362 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
363 0, 0, 640, 480, 0, 0, 0, 0);
364 if (!(ddraw
= create_ddraw()))
366 skip("Failed to create a ddraw object, skipping test.\n");
367 DestroyWindow(focus_window
);
371 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
372 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
373 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
374 ok(!device_window
, "Unexpected device window found.\n");
375 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
376 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
377 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
378 ok(!device_window
, "Unexpected device window found.\n");
379 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
380 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
381 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
382 ok(!device_window
, "Unexpected device window found.\n");
383 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
384 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
385 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
386 ok(!device_window
, "Unexpected device window found.\n");
387 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
388 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
389 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
390 ok(!device_window
, "Unexpected device window found.\n");
392 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
393 if (broken(hr
== DDERR_INVALIDPARAMS
))
395 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
396 IDirectDraw_Release(ddraw
);
397 DestroyWindow(focus_window
);
401 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
402 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
403 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
404 ok(!device_window
, "Unexpected device window found.\n");
405 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
406 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
407 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
408 ok(!device_window
, "Unexpected device window found.\n");
410 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
411 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
412 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
413 ok(!device_window
, "Unexpected device window found.\n");
414 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
415 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
416 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
417 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
418 ok(!!device_window
, "Device window not found.\n");
420 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
421 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
422 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
423 ok(!device_window
, "Unexpected device window found.\n");
424 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
425 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
426 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
427 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
428 ok(!!device_window
, "Device window not found.\n");
430 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
431 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
432 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
433 ok(!device_window
, "Unexpected device window found.\n");
434 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
435 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
436 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
437 ok(!device_window
, "Unexpected device window found.\n");
438 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
439 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
440 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
441 ok(!device_window
, "Unexpected device window found.\n");
442 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
443 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
444 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
445 ok(!!device_window
, "Device window not found.\n");
447 IDirectDraw_Release(ddraw
);
448 DestroyWindow(focus_window
);
451 static void test_clipper_blt(void)
453 IDirectDrawSurface
*src_surface
, *dst_surface
;
454 RECT client_rect
, src_rect
, *rect
;
455 IDirectDrawClipper
*clipper
;
456 DDSURFACEDESC surface_desc
;
457 unsigned int i
, j
, x
, y
;
468 static const DWORD src_data
[] =
470 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
471 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
472 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
474 static const D3DCOLOR expected1
[] =
476 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
477 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
478 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
479 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
481 static const D3DCOLOR expected2
[] =
483 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
484 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
485 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
486 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
489 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
490 10, 10, 640, 480, 0, 0, 0, 0);
491 ShowWindow(window
, SW_SHOW
);
492 if (!(ddraw
= create_ddraw()))
494 skip("Failed to create a ddraw object, skipping test.\n");
495 DestroyWindow(window
);
499 ret
= GetClientRect(window
, &client_rect
);
500 ok(ret
, "Failed to get client rect.\n");
501 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
502 ok(ret
, "Failed to map client rect.\n");
504 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
505 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
507 hr
= IDirectDraw_CreateClipper(ddraw
, 0, &clipper
, NULL
);
508 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
509 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
510 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
511 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
512 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
513 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
514 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
515 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
516 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
517 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
518 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
519 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
520 ok(rgn_data
->rdh
.nCount
== 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
521 ok(rgn_data
->rdh
.nRgnSize
== 16 || broken(rgn_data
->rdh
.nRgnSize
== 168 /* NT4 */),
522 "Got unexpected region size %u.\n", rgn_data
->rdh
.nRgnSize
);
523 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
524 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
525 rgn_data
->rdh
.rcBound
.left
, rgn_data
->rdh
.rcBound
.top
,
526 rgn_data
->rdh
.rcBound
.right
, rgn_data
->rdh
.rcBound
.bottom
,
527 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
528 rect
= (RECT
*)&rgn_data
->Buffer
[0];
529 ok(EqualRect(rect
, &client_rect
),
530 "Got unexpected clip rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
531 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
,
532 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
533 HeapFree(GetProcessHeap(), 0, rgn_data
);
535 r1
= CreateRectRgn(0, 0, 320, 240);
536 ok(!!r1
, "Failed to create region.\n");
537 r2
= CreateRectRgn(320, 240, 640, 480);
538 ok(!!r2
, "Failed to create region.\n");
539 CombineRgn(r1
, r1
, r2
, RGN_OR
);
540 ret
= GetRegionData(r1
, 0, NULL
);
541 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
542 ret
= GetRegionData(r1
, ret
, rgn_data
);
543 ok(!!ret
, "Failed to get region data.\n");
548 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
549 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
550 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
551 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
552 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
553 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
555 HeapFree(GetProcessHeap(), 0, rgn_data
);
557 memset(&surface_desc
, 0, sizeof(surface_desc
));
558 surface_desc
.dwSize
= sizeof(surface_desc
);
559 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
560 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
561 surface_desc
.dwWidth
= 640;
562 surface_desc
.dwHeight
= 480;
563 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
564 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
565 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
566 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
567 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
568 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
570 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
571 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
572 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
573 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
575 memset(&fx
, 0, sizeof(fx
));
576 fx
.dwSize
= sizeof(fx
);
577 hr
= IDirectDrawSurface_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
578 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
579 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
580 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
582 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
583 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
584 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
585 ptr
= surface_desc
.lpSurface
;
586 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
587 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
588 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
589 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
590 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
592 hr
= IDirectDrawSurface_SetClipper(dst_surface
, clipper
);
593 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
595 SetRect(&src_rect
, 1, 1, 5, 2);
596 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
597 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
598 for (i
= 0; i
< 4; ++i
)
600 for (j
= 0; j
< 4; ++j
)
602 x
= 80 * ((2 * j
) + 1);
603 y
= 60 * ((2 * i
) + 1);
604 color
= get_surface_color(dst_surface
, x
, y
);
605 ok(compare_color(color
, expected1
[i
* 4 + j
], 1),
606 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
610 U5(fx
).dwFillColor
= 0xff0000ff;
611 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
612 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
613 for (i
= 0; i
< 4; ++i
)
615 for (j
= 0; j
< 4; ++j
)
617 x
= 80 * ((2 * j
) + 1);
618 y
= 60 * ((2 * i
) + 1);
619 color
= get_surface_color(dst_surface
, x
, y
);
620 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
621 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
625 hr
= IDirectDrawSurface_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
626 ok(hr
== DDERR_BLTFASTCANTCLIP
|| broken(hr
== E_NOTIMPL
/* NT4 */), "Got unexpected hr %#x.\n", hr
);
628 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
629 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
630 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
631 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
632 DestroyWindow(window
);
633 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
634 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
635 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
636 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
637 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
638 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
639 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
640 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
641 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
642 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
643 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
644 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
646 IDirectDrawSurface_Release(dst_surface
);
647 IDirectDrawSurface_Release(src_surface
);
648 IDirectDrawClipper_Release(clipper
);
649 IDirectDraw_Release(ddraw
);
652 static void test_coop_level_d3d_state(void)
654 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
655 D3DMATERIALHANDLE background_handle
;
656 IDirectDrawSurface
*rt
, *surface
;
657 IDirect3DMaterial
*background
;
658 IDirect3DViewport
*viewport
;
659 IDirect3DDevice
*device
;
660 D3DMATERIAL material
;
667 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
668 0, 0, 640, 480, 0, 0, 0, 0);
669 if (!(ddraw
= create_ddraw()))
671 skip("Failed to create ddraw object, skipping test.\n");
672 DestroyWindow(window
);
675 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
677 skip("Failed to create D3D device, skipping test.\n");
678 IDirectDraw_Release(ddraw
);
679 DestroyWindow(window
);
683 hr
= IDirect3DDevice_GetDirect3D(device
, &d3d
);
684 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
685 hr
= IDirect3D_CreateMaterial(d3d
, &background
, NULL
);
686 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
687 IDirect3D_Release(d3d
);
689 viewport
= create_viewport(device
, 0, 0, 640, 480);
691 memset(&material
, 0, sizeof(material
));
692 material
.dwSize
= sizeof(material
);
693 U1(U(material
).diffuse
).r
= 1.0f
;
694 U2(U(material
).diffuse
).g
= 0.0f
;
695 U3(U(material
).diffuse
).b
= 0.0f
;
696 U4(U(material
).diffuse
).a
= 1.0f
;
697 hr
= IDirect3DMaterial_SetMaterial(background
, &material
);
698 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
699 hr
= IDirect3DMaterial_GetHandle(background
, device
, &background_handle
);
700 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
701 hr
= IDirect3DViewport_SetBackground(viewport
, background_handle
);
702 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
704 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
705 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
706 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
707 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
708 color
= get_surface_color(rt
, 320, 240);
709 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
711 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
712 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
713 hr
= IDirectDrawSurface_IsLost(rt
);
714 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
715 hr
= restore_surfaces(ddraw
);
716 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
718 memset(&material
, 0, sizeof(material
));
719 material
.dwSize
= sizeof(material
);
720 U1(U(material
).diffuse
).r
= 0.0f
;
721 U2(U(material
).diffuse
).g
= 1.0f
;
722 U3(U(material
).diffuse
).b
= 0.0f
;
723 U4(U(material
).diffuse
).a
= 1.0f
;
724 hr
= IDirect3DMaterial_SetMaterial(background
, &material
);
725 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
727 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&surface
);
728 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
729 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
730 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
731 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
732 color
= get_surface_color(rt
, 320, 240);
733 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
735 destroy_viewport(device
, viewport
);
736 IDirect3DMaterial_Release(background
);
737 IDirectDrawSurface_Release(surface
);
738 IDirectDrawSurface_Release(rt
);
739 IDirect3DDevice_Release(device
);
740 IDirectDraw_Release(ddraw
);
741 DestroyWindow(window
);
744 static void test_surface_interface_mismatch(void)
746 IDirectDraw
*ddraw
= NULL
;
747 IDirect3D
*d3d
= NULL
;
748 IDirectDrawSurface
*surface
= NULL
, *ds
;
749 IDirectDrawSurface3
*surface3
= NULL
;
750 IDirect3DDevice
*device
= NULL
;
751 IDirect3DViewport
*viewport
= NULL
;
752 IDirect3DMaterial
*background
= NULL
;
753 DDSURFACEDESC surface_desc
;
759 D3DMATERIAL material
;
760 D3DMATERIALHANDLE background_handle
;
761 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
763 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
764 0, 0, 640, 480, 0, 0, 0, 0);
766 if (!(ddraw
= create_ddraw()))
768 skip("Failed to create a ddraw object, skipping test.\n");
772 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
773 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
775 memset(&surface_desc
, 0, sizeof(surface_desc
));
776 surface_desc
.dwSize
= sizeof(surface_desc
);
777 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
778 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
779 surface_desc
.dwWidth
= 640;
780 surface_desc
.dwHeight
= 480;
782 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
783 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
785 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
788 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
792 hr
= IDirectDraw_QueryInterface(ddraw
, &IID_IDirect3D
, (void **)&d3d
);
795 skip("Failed to get the IDirect3D interface, skipping test.\n");
799 hr
= IDirect3D_EnumDevices(d3d
, enum_z_fmt
, &z_depth
);
800 if (FAILED(hr
) || !z_depth
)
802 skip("No depth buffer formats available, skipping test.\n");
806 memset(&surface_desc
, 0, sizeof(surface_desc
));
807 surface_desc
.dwSize
= sizeof(surface_desc
);
808 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
809 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
810 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
811 surface_desc
.dwWidth
= 640;
812 surface_desc
.dwHeight
= 480;
813 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
814 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
818 /* Using a different surface interface version still works */
819 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
820 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
821 refcount
= IDirectDrawSurface_Release(ds
);
822 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
827 hr
= IDirectDrawSurface3_QueryInterface(surface3
, &IID_IDirect3DHALDevice
, (void **)&device
);
828 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
832 hr
= IDirect3D_CreateMaterial(d3d
, &background
, NULL
);
833 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
835 viewport
= create_viewport(device
, 0, 0, 640, 480);
837 memset(&material
, 0, sizeof(material
));
838 material
.dwSize
= sizeof(material
);
839 U1(U(material
).diffuse
).r
= 1.0f
;
840 U2(U(material
).diffuse
).g
= 0.0f
;
841 U3(U(material
).diffuse
).b
= 0.0f
;
842 U4(U(material
).diffuse
).a
= 1.0f
;
843 hr
= IDirect3DMaterial_SetMaterial(background
, &material
);
844 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
845 hr
= IDirect3DMaterial_GetHandle(background
, device
, &background_handle
);
846 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
847 hr
= IDirect3DViewport_SetBackground(viewport
, background_handle
);
848 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
850 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
851 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
852 color
= get_surface_color(surface
, 320, 240);
853 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
857 destroy_viewport(device
, viewport
);
858 if (background
) IDirect3DMaterial_Release(background
);
859 if (surface3
) IDirectDrawSurface3_Release(surface3
);
860 if (surface
) IDirectDrawSurface_Release(surface
);
861 if (device
) IDirect3DDevice_Release(device
);
862 if (d3d
) IDirect3D_Release(d3d
);
863 if (ddraw
) IDirectDraw_Release(ddraw
);
864 DestroyWindow(window
);
867 static void test_coop_level_threaded(void)
869 struct create_window_thread_param p
;
873 if (!(ddraw
= create_ddraw()))
875 skip("Failed to create a ddraw object, skipping test.\n");
878 create_window_thread(&p
);
880 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
881 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
883 IDirectDraw_Release(ddraw
);
884 destroy_window_thread(&p
);
887 static ULONG
get_refcount(IUnknown
*test_iface
)
889 IUnknown_AddRef(test_iface
);
890 return IUnknown_Release(test_iface
);
893 static void test_viewport_interfaces(void)
899 IDirect3DViewport
*viewport
;
900 IDirect3DViewport2
*viewport2
;
901 IDirect3DViewport3
*viewport3
;
902 IDirectDrawGammaControl
*gamma
;
905 if (!(ddraw
= create_ddraw()))
907 skip("Failed to create ddraw object, skipping test.\n");
910 hr
= IDirectDraw_QueryInterface(ddraw
, &IID_IDirect3D
, (void **)&d3d
);
911 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get d3d interface, hr %#x.\n", hr
);
914 skip("Direct3D not available, skipping tests\n");
915 IDirectDraw_Release(ddraw
);
918 ref
= get_refcount((IUnknown
*)d3d
);
919 ok(ref
== 2, "IDirect3D refcount is %d\n", ref
);
921 hr
= IDirect3D_CreateViewport(d3d
, &viewport
, NULL
);
922 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
923 ref
= get_refcount((IUnknown
*)viewport
);
924 ok(ref
== 1, "Initial IDirect3DViewport refcount is %u\n", ref
);
925 ref
= get_refcount((IUnknown
*)d3d
);
926 ok(ref
== 2, "IDirect3D refcount is %u\n", ref
);
928 /* E_FAIL return values are returned by Winetestbot Windows NT machines. While not supporting
929 * newer interfaces is legitimate for old ddraw versions, E_FAIL violates Microsoft's rules
930 * for QueryInterface, hence the broken() */
931 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
932 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
933 ok(hr
== E_NOINTERFACE
|| broken(hr
== E_FAIL
), "Got unexpected hr %#x.\n", hr
);
934 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
935 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
936 /* NULL iid: Segfaults */
938 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IDirect3DViewport2
, (void **)&viewport2
);
939 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
|| broken(hr
== E_FAIL
),
940 "Failed to QI IDirect3DViewport2, hr %#x.\n", hr
);
943 ref
= get_refcount((IUnknown
*)viewport
);
944 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
945 ref
= get_refcount((IUnknown
*)viewport2
);
946 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
947 IDirect3DViewport2_Release(viewport2
);
951 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IDirect3DViewport3
, (void **)&viewport3
);
952 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
|| broken(hr
== E_FAIL
),
953 "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
956 ref
= get_refcount((IUnknown
*)viewport
);
957 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
958 ref
= get_refcount((IUnknown
*)viewport3
);
959 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
960 IDirect3DViewport3_Release(viewport3
);
963 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IUnknown
, (void **)&unknown
);
964 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
967 ref
= get_refcount((IUnknown
*)viewport
);
968 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
969 ref
= get_refcount(unknown
);
970 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
971 IUnknown_Release(unknown
);
974 IDirect3DViewport_Release(viewport
);
975 IDirect3D_Release(d3d
);
976 IDirectDraw_Release(ddraw
);
979 static void test_zenable(void)
981 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
982 static D3DTLVERTEX tquad
[] =
984 {{ 0.0f
}, {480.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
985 {{ 0.0f
}, { 0.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
986 {{640.0f
}, {480.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
987 {{640.0f
}, { 0.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
989 IDirect3DExecuteBuffer
*execute_buffer
;
990 D3DMATERIALHANDLE background_handle
;
991 D3DEXECUTEBUFFERDESC exec_desc
;
992 IDirect3DMaterial
*background
;
993 IDirect3DViewport
*viewport
;
994 D3DEXECUTEDATA exec_data
;
995 IDirect3DDevice
*device
;
996 IDirectDrawSurface
*rt
;
997 D3DMATERIAL material
;
1008 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1009 0, 0, 640, 480, 0, 0, 0, 0);
1010 if (!(ddraw
= create_ddraw()))
1012 skip("Failed to create ddraw object, skipping test.\n");
1013 DestroyWindow(window
);
1016 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1018 skip("Failed to create D3D device, skipping test.\n");
1019 IDirectDraw_Release(ddraw
);
1020 DestroyWindow(window
);
1024 hr
= IDirect3DDevice_GetDirect3D(device
, &d3d
);
1025 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1026 hr
= IDirect3D_CreateMaterial(d3d
, &background
, NULL
);
1027 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
1029 viewport
= create_viewport(device
, 0, 0, 640, 480);
1031 memset(&material
, 0, sizeof(material
));
1032 material
.dwSize
= sizeof(material
);
1033 U1(U(material
).diffuse
).r
= 1.0f
;
1034 U2(U(material
).diffuse
).g
= 0.0f
;
1035 U3(U(material
).diffuse
).b
= 0.0f
;
1036 U4(U(material
).diffuse
).a
= 1.0f
;
1037 hr
= IDirect3DMaterial_SetMaterial(background
, &material
);
1038 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
1039 hr
= IDirect3DMaterial_GetHandle(background
, device
, &background_handle
);
1040 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
1041 hr
= IDirect3DViewport_SetBackground(viewport
, background_handle
);
1042 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
1044 memset(&exec_desc
, 0, sizeof(exec_desc
));
1045 exec_desc
.dwSize
= sizeof(exec_desc
);
1046 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1047 exec_desc
.dwBufferSize
= 1024;
1048 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1050 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
1051 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
1052 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
1053 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
1054 memcpy(exec_desc
.lpData
, tquad
, sizeof(tquad
));
1055 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(tquad
);
1056 emit_process_vertices(&ptr
, 0, 4);
1057 emit_set_rs(&ptr
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1058 emit_tquad(&ptr
, 0);
1060 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
1061 inst_length
-= sizeof(tquad
);
1062 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
1063 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
1065 memset(&exec_data
, 0, sizeof(exec_data
));
1066 exec_data
.dwSize
= sizeof(exec_data
);
1067 exec_data
.dwVertexCount
= 4;
1068 exec_data
.dwInstructionOffset
= sizeof(tquad
);
1069 exec_data
.dwInstructionLength
= inst_length
;
1070 hr
= IDirect3DExecuteBuffer_SetExecuteData(execute_buffer
, &exec_data
);
1071 ok(SUCCEEDED(hr
), "Failed to set execute data, hr %#x.\n", hr
);
1073 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1074 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1075 hr
= IDirect3DDevice_BeginScene(device
);
1076 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1077 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1078 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1079 hr
= IDirect3DDevice_EndScene(device
);
1080 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1082 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
1083 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1084 for (i
= 0; i
< 4; ++i
)
1086 for (j
= 0; j
< 4; ++j
)
1088 x
= 80 * ((2 * j
) + 1);
1089 y
= 60 * ((2 * i
) + 1);
1090 color
= get_surface_color(rt
, x
, y
);
1091 ok(compare_color(color
, 0x0000ff00, 1),
1092 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1095 IDirectDrawSurface_Release(rt
);
1097 destroy_viewport(device
, viewport
);
1098 IDirect3DExecuteBuffer_Release(execute_buffer
);
1099 IDirect3DMaterial_Release(background
);
1100 IDirect3D_Release(d3d
);
1101 IDirect3DDevice_Release(device
);
1102 IDirectDraw_Release(ddraw
);
1103 DestroyWindow(window
);
1106 static void test_ck_rgba(void)
1108 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1109 static D3DTLVERTEX tquad
[] =
1111 {{ 0.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1112 {{ 0.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1113 {{640.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1114 {{640.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1115 {{ 0.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1116 {{ 0.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1117 {{640.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1118 {{640.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1122 D3DCOLOR fill_color
;
1130 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x000000ff},
1131 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x000000ff},
1132 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00},
1133 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00},
1134 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00807f00},
1135 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x0000ff00},
1136 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00},
1137 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00},
1140 IDirect3DExecuteBuffer
*execute_buffer
;
1141 D3DMATERIALHANDLE background_handle
;
1142 D3DTEXTUREHANDLE texture_handle
;
1143 D3DEXECUTEBUFFERDESC exec_desc
;
1144 IDirect3DMaterial
*background
;
1145 IDirectDrawSurface
*surface
;
1146 IDirect3DViewport
*viewport
;
1147 DDSURFACEDESC surface_desc
;
1148 IDirect3DTexture
*texture
;
1149 IDirect3DDevice
*device
;
1150 IDirectDrawSurface
*rt
;
1151 D3DMATERIAL material
;
1160 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1161 0, 0, 640, 480, 0, 0, 0, 0);
1162 if (!(ddraw
= create_ddraw()))
1164 skip("Failed to create ddraw object, skipping test.\n");
1165 DestroyWindow(window
);
1168 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1170 skip("Failed to create D3D device, skipping test.\n");
1171 DestroyWindow(window
);
1175 hr
= IDirect3DDevice_GetDirect3D(device
, &d3d
);
1176 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1178 viewport
= create_viewport(device
, 0, 0, 640, 480);
1180 hr
= IDirect3D_CreateMaterial(d3d
, &background
, NULL
);
1181 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
1182 memset(&material
, 0, sizeof(material
));
1183 material
.dwSize
= sizeof(material
);
1184 U1(U(material
).diffuse
).r
= 1.0f
;
1185 U2(U(material
).diffuse
).g
= 0.0f
;
1186 U3(U(material
).diffuse
).b
= 0.0f
;
1187 U4(U(material
).diffuse
).a
= 1.0f
;
1188 hr
= IDirect3DMaterial_SetMaterial(background
, &material
);
1189 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
1190 hr
= IDirect3DMaterial_GetHandle(background
, device
, &background_handle
);
1191 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
1192 hr
= IDirect3DViewport_SetBackground(viewport
, background_handle
);
1193 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
1195 IDirect3D_Release(d3d
);
1197 memset(&surface_desc
, 0, sizeof(surface_desc
));
1198 surface_desc
.dwSize
= sizeof(surface_desc
);
1199 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1200 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1201 surface_desc
.dwWidth
= 256;
1202 surface_desc
.dwHeight
= 256;
1203 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1204 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1205 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1206 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1207 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1208 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1209 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1210 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1211 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1212 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1213 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1214 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
1215 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1216 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
1217 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1218 IDirect3DTexture_Release(texture
);
1220 memset(&exec_desc
, 0, sizeof(exec_desc
));
1221 exec_desc
.dwSize
= sizeof(exec_desc
);
1222 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1223 exec_desc
.dwBufferSize
= 1024;
1224 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1225 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
1226 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
1228 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
1229 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1231 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1233 UINT draw1_len
, draw2_len
;
1234 D3DEXECUTEDATA exec_data
;
1237 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
1238 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
1239 memcpy(exec_desc
.lpData
, tquad
, sizeof(tquad
));
1240 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(tquad
);
1241 emit_process_vertices(&ptr
, 0, 4);
1242 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1243 emit_set_rs(&ptr
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1244 emit_set_rs(&ptr
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1245 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1246 emit_set_rs(&ptr
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1247 emit_tquad(&ptr
, 0);
1249 draw1_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- sizeof(tquad
);
1250 emit_process_vertices(&ptr
, 4, 4);
1251 emit_tquad(&ptr
, 0);
1252 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1254 draw2_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw1_len
;
1255 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
1256 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
1258 memset(&fx
, 0, sizeof(fx
));
1259 fx
.dwSize
= sizeof(fx
);
1260 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1261 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1262 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1264 memset(&exec_data
, 0, sizeof(exec_data
));
1265 exec_data
.dwSize
= sizeof(exec_data
);
1266 exec_data
.dwVertexCount
= 8;
1267 exec_data
.dwInstructionOffset
= sizeof(tquad
);
1268 exec_data
.dwInstructionLength
= draw1_len
;
1269 hr
= IDirect3DExecuteBuffer_SetExecuteData(execute_buffer
, &exec_data
);
1270 ok(SUCCEEDED(hr
), "Failed to set execute data, hr %#x.\n", hr
);
1272 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
1273 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1274 hr
= IDirect3DDevice_BeginScene(device
);
1275 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1276 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1277 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1278 hr
= IDirect3DDevice_EndScene(device
);
1279 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1281 color
= get_surface_color(rt
, 320, 240);
1282 if (i
== 2 || i
== 3)
1283 todo_wine
ok(compare_color(color
, tests
[i
].result1
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1284 tests
[i
].result1
, i
, color
);
1286 ok(compare_color(color
, tests
[i
].result1
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1287 tests
[i
].result1
, i
, color
);
1289 U5(fx
).dwFillColor
= 0xff0000ff;
1290 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1291 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1293 exec_data
.dwInstructionOffset
= sizeof(tquad
) + draw1_len
;
1294 exec_data
.dwInstructionLength
= draw2_len
;
1295 hr
= IDirect3DExecuteBuffer_SetExecuteData(execute_buffer
, &exec_data
);
1296 ok(SUCCEEDED(hr
), "Failed to set execute data, hr %#x.\n", hr
);
1298 hr
= IDirect3DDevice_BeginScene(device
);
1299 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1300 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1301 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1302 hr
= IDirect3DDevice_EndScene(device
);
1303 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1305 /* This tests that fragments that are masked out by the color key are
1306 * discarded, instead of just fully transparent. */
1307 color
= get_surface_color(rt
, 320, 240);
1308 if (i
== 2 || i
== 3)
1309 todo_wine
ok(compare_color(color
, tests
[i
].result2
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1310 tests
[i
].result2
, i
, color
);
1312 ok(compare_color(color
, tests
[i
].result2
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1313 tests
[i
].result2
, i
, color
);
1316 IDirectDrawSurface_Release(rt
);
1317 IDirect3DExecuteBuffer_Release(execute_buffer
);
1318 IDirectDrawSurface_Release(surface
);
1319 destroy_viewport(device
, viewport
);
1320 IDirect3DMaterial_Release(background
);
1321 IDirect3DDevice_Release(device
);
1322 IDirectDraw_Release(ddraw
);
1323 DestroyWindow(window
);
1329 REFIID refcount_iid
;
1333 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
1334 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
1336 ULONG refcount
, expected_refcount
;
1337 IUnknown
*iface1
, *iface2
;
1341 for (i
= 0; i
< entry_count
; ++i
)
1343 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
1344 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
1347 for (j
= 0; j
< entry_count
; ++j
)
1349 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
1350 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
1353 expected_refcount
= 0;
1354 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
1355 ++expected_refcount
;
1356 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
1357 ++expected_refcount
;
1358 refcount
= IUnknown_Release(iface2
);
1359 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1360 refcount
, test_name
, i
, j
, expected_refcount
);
1364 expected_refcount
= 0;
1365 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
1366 ++expected_refcount
;
1367 refcount
= IUnknown_Release(iface1
);
1368 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1369 refcount
, test_name
, i
, expected_refcount
);
1374 static void test_surface_qi(void)
1376 static const struct qi_test tests
[] =
1378 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface
, S_OK
},
1379 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface
, S_OK
},
1380 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1381 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1382 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1383 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1384 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1385 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1386 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1387 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
1388 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
1389 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
1390 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
1391 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
1392 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
1393 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
1394 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
1395 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
1396 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
1397 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
1398 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
1399 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
1400 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
1401 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
1402 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
1403 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
1404 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
1405 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
1406 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
1407 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
1408 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
1409 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
1410 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
1411 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
1412 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1415 IDirectDrawSurface
*surface
;
1416 DDSURFACEDESC surface_desc
;
1417 IDirect3DDevice
*device
;
1422 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1424 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1428 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1429 0, 0, 640, 480, 0, 0, 0, 0);
1430 if (!(ddraw
= create_ddraw()))
1432 skip("Failed to create a ddraw object, skipping test.\n");
1435 /* Try to create a D3D device to see if the ddraw implementation supports
1436 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1437 * doesn't support e.g. the IDirect3DTexture interfaces. */
1438 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1440 skip("Failed to create D3D device, skipping test.\n");
1441 DestroyWindow(window
);
1444 IDirect3DDevice_Release(device
);
1446 memset(&surface_desc
, 0, sizeof(surface_desc
));
1447 surface_desc
.dwSize
= sizeof(surface_desc
);
1448 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1449 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1450 surface_desc
.dwWidth
= 512;
1451 surface_desc
.dwHeight
= 512;
1452 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1453 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1455 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface
, tests
, sizeof(tests
) / sizeof(*tests
));
1457 IDirectDrawSurface_Release(surface
);
1458 IDirectDraw_Release(ddraw
);
1459 DestroyWindow(window
);
1464 test_coop_level_create_device_window();
1466 test_coop_level_d3d_state();
1467 test_surface_interface_mismatch();
1468 test_coop_level_threaded();
1469 test_viewport_interfaces();