2 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
3 * Copyright 2012-2013 Stefan Dösinger for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
24 static DEVMODEW registry_mode
;
26 struct create_window_thread_param
29 HANDLE window_created
;
30 HANDLE destroy_window
;
34 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
36 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
38 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
40 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
42 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
46 static DWORD WINAPI
create_window_thread_proc(void *param
)
48 struct create_window_thread_param
*p
= param
;
52 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
53 0, 0, 640, 480, 0, 0, 0, 0);
54 ret
= SetEvent(p
->window_created
);
55 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
61 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
62 DispatchMessageA(&msg
);
63 res
= WaitForSingleObject(p
->destroy_window
, 100);
64 if (res
== WAIT_OBJECT_0
)
66 if (res
!= WAIT_TIMEOUT
)
68 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
73 DestroyWindow(p
->window
);
78 static void create_window_thread(struct create_window_thread_param
*p
)
82 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
83 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
84 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
85 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
86 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
87 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
88 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
89 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
92 static void destroy_window_thread(struct create_window_thread_param
*p
)
94 SetEvent(p
->destroy_window
);
95 WaitForSingleObject(p
->thread
, INFINITE
);
96 CloseHandle(p
->destroy_window
);
97 CloseHandle(p
->window_created
);
98 CloseHandle(p
->thread
);
101 static HRESULT
set_display_mode(IDirectDraw
*ddraw
, DWORD width
, DWORD height
)
103 if (SUCCEEDED(IDirectDraw_SetDisplayMode(ddraw
, width
, height
, 32)))
105 return IDirectDraw_SetDisplayMode(ddraw
, width
, height
, 24);
108 static D3DCOLOR
get_surface_color(IDirectDrawSurface
*surface
, UINT x
, UINT y
)
110 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
111 DDSURFACEDESC surface_desc
;
115 memset(&surface_desc
, 0, sizeof(surface_desc
));
116 surface_desc
.dwSize
= sizeof(surface_desc
);
118 hr
= IDirectDrawSurface_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
119 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
123 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
125 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
126 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
131 static void emit_process_vertices(void **ptr
, DWORD flags
, WORD base_idx
, DWORD vertex_count
)
133 D3DINSTRUCTION
*inst
= *ptr
;
134 D3DPROCESSVERTICES
*pv
= (D3DPROCESSVERTICES
*)(inst
+ 1);
136 inst
->bOpcode
= D3DOP_PROCESSVERTICES
;
137 inst
->bSize
= sizeof(*pv
);
141 pv
->wStart
= base_idx
;
143 pv
->dwCount
= vertex_count
;
149 static void emit_set_ts(void **ptr
, D3DTRANSFORMSTATETYPE state
, DWORD value
)
151 D3DINSTRUCTION
*inst
= *ptr
;
152 D3DSTATE
*ts
= (D3DSTATE
*)(inst
+ 1);
154 inst
->bOpcode
= D3DOP_STATETRANSFORM
;
155 inst
->bSize
= sizeof(*ts
);
158 U1(*ts
).dtstTransformStateType
= state
;
159 U2(*ts
).dwArg
[0] = value
;
164 static void emit_set_ls(void **ptr
, D3DLIGHTSTATETYPE state
, DWORD value
)
166 D3DINSTRUCTION
*inst
= *ptr
;
167 D3DSTATE
*ls
= (D3DSTATE
*)(inst
+ 1);
169 inst
->bOpcode
= D3DOP_STATELIGHT
;
170 inst
->bSize
= sizeof(*ls
);
173 U1(*ls
).dlstLightStateType
= state
;
174 U2(*ls
).dwArg
[0] = value
;
179 static void emit_set_rs(void **ptr
, D3DRENDERSTATETYPE state
, DWORD value
)
181 D3DINSTRUCTION
*inst
= *ptr
;
182 D3DSTATE
*rs
= (D3DSTATE
*)(inst
+ 1);
184 inst
->bOpcode
= D3DOP_STATERENDER
;
185 inst
->bSize
= sizeof(*rs
);
188 U1(*rs
).drstRenderStateType
= state
;
189 U2(*rs
).dwArg
[0] = value
;
194 static void emit_tquad(void **ptr
, WORD base_idx
)
196 D3DINSTRUCTION
*inst
= *ptr
;
197 D3DTRIANGLE
*tri
= (D3DTRIANGLE
*)(inst
+ 1);
199 inst
->bOpcode
= D3DOP_TRIANGLE
;
200 inst
->bSize
= sizeof(*tri
);
203 U1(*tri
).v1
= base_idx
;
204 U2(*tri
).v2
= base_idx
+ 1;
205 U3(*tri
).v3
= base_idx
+ 2;
206 tri
->wFlags
= D3DTRIFLAG_START
;
209 U1(*tri
).v1
= base_idx
+ 2;
210 U2(*tri
).v2
= base_idx
+ 1;
211 U3(*tri
).v3
= base_idx
+ 3;
212 tri
->wFlags
= D3DTRIFLAG_ODD
;
218 static void emit_tquad_tlist(void **ptr
, WORD base_idx
)
220 D3DINSTRUCTION
*inst
= *ptr
;
221 D3DTRIANGLE
*tri
= (D3DTRIANGLE
*)(inst
+ 1);
223 inst
->bOpcode
= D3DOP_TRIANGLE
;
224 inst
->bSize
= sizeof(*tri
);
227 U1(*tri
).v1
= base_idx
;
228 U2(*tri
).v2
= base_idx
+ 1;
229 U3(*tri
).v3
= base_idx
+ 2;
230 tri
->wFlags
= D3DTRIFLAG_START
;
233 U1(*tri
).v1
= base_idx
+ 2;
234 U2(*tri
).v2
= base_idx
+ 3;
235 U3(*tri
).v3
= base_idx
;
236 tri
->wFlags
= D3DTRIFLAG_START
;
242 static void emit_end(void **ptr
)
244 D3DINSTRUCTION
*inst
= *ptr
;
246 inst
->bOpcode
= D3DOP_EXIT
;
253 static void set_execute_data(IDirect3DExecuteBuffer
*execute_buffer
, UINT vertex_count
, UINT offset
, UINT len
)
255 D3DEXECUTEDATA exec_data
;
258 memset(&exec_data
, 0, sizeof(exec_data
));
259 exec_data
.dwSize
= sizeof(exec_data
);
260 exec_data
.dwVertexCount
= vertex_count
;
261 exec_data
.dwInstructionOffset
= offset
;
262 exec_data
.dwInstructionLength
= len
;
263 hr
= IDirect3DExecuteBuffer_SetExecuteData(execute_buffer
, &exec_data
);
264 ok(SUCCEEDED(hr
), "Failed to set execute data, hr %#x.\n", hr
);
267 static DWORD
get_device_z_depth(IDirect3DDevice
*device
)
269 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
270 IDirectDrawSurface
*ds
, *rt
;
274 if (FAILED(IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
)))
277 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ds
);
278 IDirectDrawSurface_Release(rt
);
282 desc
.dwSize
= sizeof(desc
);
283 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
284 IDirectDrawSurface_Release(ds
);
288 return U2(desc
).dwZBufferBitDepth
;
291 static IDirectDraw
*create_ddraw(void)
295 if (FAILED(DirectDrawCreate(NULL
, &ddraw
, NULL
)))
301 static IDirect3DDevice
*create_device(IDirectDraw
*ddraw
, HWND window
, DWORD coop_level
)
303 static const DWORD z_depths
[] = {32, 24, 16};
304 IDirectDrawSurface
*surface
, *ds
;
305 IDirect3DDevice
*device
= NULL
;
306 DDSURFACEDESC surface_desc
;
310 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, coop_level
);
311 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
313 memset(&surface_desc
, 0, sizeof(surface_desc
));
314 surface_desc
.dwSize
= sizeof(surface_desc
);
315 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
316 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
317 surface_desc
.dwWidth
= 640;
318 surface_desc
.dwHeight
= 480;
320 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
321 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
323 if (coop_level
& DDSCL_NORMAL
)
325 IDirectDrawClipper
*clipper
;
327 hr
= IDirectDraw_CreateClipper(ddraw
, 0, &clipper
, NULL
);
328 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
329 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
330 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
331 hr
= IDirectDrawSurface_SetClipper(surface
, clipper
);
332 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
333 IDirectDrawClipper_Release(clipper
);
336 /* We used to use EnumDevices() for this, but it seems
337 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
338 * relationship with reality. */
339 for (i
= 0; i
< sizeof(z_depths
) / sizeof(*z_depths
); ++i
)
341 memset(&surface_desc
, 0, sizeof(surface_desc
));
342 surface_desc
.dwSize
= sizeof(surface_desc
);
343 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
344 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
345 U2(surface_desc
).dwZBufferBitDepth
= z_depths
[i
];
346 surface_desc
.dwWidth
= 640;
347 surface_desc
.dwHeight
= 480;
348 if (FAILED(IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
)))
351 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
352 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
353 IDirectDrawSurface_Release(ds
);
357 if (SUCCEEDED(IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DHALDevice
, (void **)&device
)))
360 IDirectDrawSurface_DeleteAttachedSurface(surface
, 0, ds
);
363 IDirectDrawSurface_Release(surface
);
367 static IDirect3DViewport
*create_viewport(IDirect3DDevice
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
369 IDirect3DViewport
*viewport
;
374 hr
= IDirect3DDevice_GetDirect3D(device
, &d3d
);
375 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
376 hr
= IDirect3D_CreateViewport(d3d
, &viewport
, NULL
);
377 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
378 hr
= IDirect3DDevice_AddViewport(device
, viewport
);
379 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
380 memset(&vp
, 0, sizeof(vp
));
381 vp
.dwSize
= sizeof(vp
);
386 vp
.dvScaleX
= (float)w
/ 2.0f
;
387 vp
.dvScaleY
= (float)h
/ 2.0f
;
392 hr
= IDirect3DViewport_SetViewport(viewport
, &vp
);
393 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
394 IDirect3D_Release(d3d
);
399 static void viewport_set_background(IDirect3DDevice
*device
, IDirect3DViewport
*viewport
,
400 IDirect3DMaterial
*material
)
402 D3DMATERIALHANDLE material_handle
;
405 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &material_handle
);
406 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
407 hr
= IDirect3DViewport2_SetBackground(viewport
, material_handle
);
408 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
411 static void destroy_viewport(IDirect3DDevice
*device
, IDirect3DViewport
*viewport
)
415 hr
= IDirect3DDevice_DeleteViewport(device
, viewport
);
416 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
417 IDirect3DViewport_Release(viewport
);
420 static IDirect3DMaterial
*create_material(IDirect3DDevice
*device
, D3DMATERIAL
*mat
)
422 IDirect3DMaterial
*material
;
426 hr
= IDirect3DDevice_GetDirect3D(device
, &d3d
);
427 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
428 hr
= IDirect3D_CreateMaterial(d3d
, &material
, NULL
);
429 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
430 hr
= IDirect3DMaterial_SetMaterial(material
, mat
);
431 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
432 IDirect3D_Release(d3d
);
437 static IDirect3DMaterial
*create_diffuse_material(IDirect3DDevice
*device
, float r
, float g
, float b
, float a
)
441 memset(&mat
, 0, sizeof(mat
));
442 mat
.dwSize
= sizeof(mat
);
443 U1(U(mat
).diffuse
).r
= r
;
444 U2(U(mat
).diffuse
).g
= g
;
445 U3(U(mat
).diffuse
).b
= b
;
446 U4(U(mat
).diffuse
).a
= a
;
448 return create_material(device
, &mat
);
451 static IDirect3DMaterial
*create_emissive_material(IDirect3DDevice
*device
, float r
, float g
, float b
, float a
)
455 memset(&mat
, 0, sizeof(mat
));
456 mat
.dwSize
= sizeof(mat
);
457 U1(U3(mat
).emissive
).r
= r
;
458 U2(U3(mat
).emissive
).g
= g
;
459 U3(U3(mat
).emissive
).b
= b
;
460 U4(U3(mat
).emissive
).a
= a
;
462 return create_material(device
, &mat
);
465 static void destroy_material(IDirect3DMaterial
*material
)
467 IDirect3DMaterial_Release(material
);
474 WPARAM expect_wparam
;
477 static const struct message
*expect_messages
;
479 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
481 if (expect_messages
&& message
== expect_messages
->message
)
483 if (expect_messages
->check_wparam
)
484 ok (wparam
== expect_messages
->expect_wparam
,
485 "Got unexpected wparam %lx for message %x, expected %lx.\n",
486 wparam
, message
, expect_messages
->expect_wparam
);
491 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
494 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
495 * interface. This prevents subsequent SetCooperativeLevel() calls on a
496 * different window from failing with DDERR_HWNDALREADYSET. */
497 static void fix_wndproc(HWND window
, LONG_PTR proc
)
502 if (!(ddraw
= create_ddraw()))
505 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
506 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
507 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
508 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
509 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
511 IDirectDraw_Release(ddraw
);
514 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
516 HRESULT hr
= IDirectDrawSurface_Restore(surface
);
517 ok(SUCCEEDED(hr
) || hr
== DDERR_IMPLICITLYCREATED
, "Failed to restore surface, hr %#x.\n", hr
);
518 IDirectDrawSurface_Release(surface
);
523 static HRESULT
restore_surfaces(IDirectDraw
*ddraw
)
525 return IDirectDraw_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
526 NULL
, NULL
, restore_callback
);
529 static void test_coop_level_create_device_window(void)
531 HWND focus_window
, device_window
;
535 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
536 0, 0, 640, 480, 0, 0, 0, 0);
537 ddraw
= create_ddraw();
538 ok(!!ddraw
, "Failed to create a ddraw object.\n");
540 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
541 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
542 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
543 ok(!device_window
, "Unexpected device window found.\n");
544 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
545 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
546 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
547 ok(!device_window
, "Unexpected device window found.\n");
548 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
549 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
550 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
551 ok(!device_window
, "Unexpected device window found.\n");
552 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
553 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
554 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
555 ok(!device_window
, "Unexpected device window found.\n");
556 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
557 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
558 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
559 ok(!device_window
, "Unexpected device window found.\n");
561 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
562 if (broken(hr
== DDERR_INVALIDPARAMS
))
564 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
565 IDirectDraw_Release(ddraw
);
566 DestroyWindow(focus_window
);
570 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
571 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
572 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
573 ok(!device_window
, "Unexpected device window found.\n");
574 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
575 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
576 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
577 ok(!device_window
, "Unexpected device window found.\n");
579 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
580 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
581 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
582 ok(!device_window
, "Unexpected device window found.\n");
583 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
584 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
585 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
586 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
587 ok(!!device_window
, "Device window not found.\n");
589 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
590 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
591 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
592 ok(!device_window
, "Unexpected device window found.\n");
593 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
594 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
595 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
596 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
597 ok(!!device_window
, "Device window not found.\n");
599 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
600 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
601 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
602 ok(!device_window
, "Unexpected device window found.\n");
603 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
604 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
605 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
606 ok(!device_window
, "Unexpected device window found.\n");
607 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
608 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
609 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
610 ok(!device_window
, "Unexpected device window found.\n");
611 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
612 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
613 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
614 ok(!!device_window
, "Device window not found.\n");
616 IDirectDraw_Release(ddraw
);
617 DestroyWindow(focus_window
);
620 static void test_clipper_blt(void)
622 IDirectDrawSurface
*src_surface
, *dst_surface
;
623 RECT client_rect
, src_rect
;
624 IDirectDrawClipper
*clipper
;
625 DDSURFACEDESC surface_desc
;
626 unsigned int i
, j
, x
, y
;
638 static const DWORD src_data
[] =
640 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
641 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
642 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
644 static const D3DCOLOR expected1
[] =
646 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
647 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
648 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
649 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
651 /* Nvidia on Windows seems to have an off-by-one error
652 * when processing source rectangles. Our left = 1 and
653 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
654 * read as well, but only for the edge pixels on the
655 * output image. The bug happens on the y axis as well,
656 * but we only read one row there, and all source rows
657 * contain the same data. This bug is not dependent on
658 * the presence of a clipper. */
659 static const D3DCOLOR expected1_broken
[] =
661 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
662 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
663 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
664 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
666 static const D3DCOLOR expected2
[] =
668 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
669 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
670 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
671 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
674 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
675 10, 10, 640, 480, 0, 0, 0, 0);
676 ShowWindow(window
, SW_SHOW
);
677 ddraw
= create_ddraw();
678 ok(!!ddraw
, "Failed to create a ddraw object.\n");
680 ret
= GetClientRect(window
, &client_rect
);
681 ok(ret
, "Failed to get client rect.\n");
682 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
683 ok(ret
, "Failed to map client rect.\n");
685 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
686 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
688 hr
= IDirectDraw_CreateClipper(ddraw
, 0, &clipper
, NULL
);
689 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
690 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
691 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
692 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
693 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
694 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
695 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
696 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
697 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
698 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
699 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
700 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
701 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
702 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
703 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
704 rgn_data
->rdh
.rcBound
.left
, rgn_data
->rdh
.rcBound
.top
,
705 rgn_data
->rdh
.rcBound
.right
, rgn_data
->rdh
.rcBound
.bottom
,
706 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
707 HeapFree(GetProcessHeap(), 0, rgn_data
);
709 r1
= CreateRectRgn(0, 0, 320, 240);
710 ok(!!r1
, "Failed to create region.\n");
711 r2
= CreateRectRgn(320, 240, 640, 480);
712 ok(!!r2
, "Failed to create region.\n");
713 CombineRgn(r1
, r1
, r2
, RGN_OR
);
714 ret
= GetRegionData(r1
, 0, NULL
);
715 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
716 ret
= GetRegionData(r1
, ret
, rgn_data
);
717 ok(!!ret
, "Failed to get region data.\n");
722 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
723 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
724 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
725 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
726 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
727 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
729 HeapFree(GetProcessHeap(), 0, rgn_data
);
731 memset(&surface_desc
, 0, sizeof(surface_desc
));
732 surface_desc
.dwSize
= sizeof(surface_desc
);
733 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
734 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
735 surface_desc
.dwWidth
= 640;
736 surface_desc
.dwHeight
= 480;
737 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
738 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
739 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
740 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
741 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
742 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
744 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
745 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
746 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
747 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
749 memset(&fx
, 0, sizeof(fx
));
750 fx
.dwSize
= sizeof(fx
);
751 hr
= IDirectDrawSurface_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
752 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
753 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
754 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
756 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
757 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
758 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
759 ptr
= surface_desc
.lpSurface
;
760 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
761 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
762 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
763 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
764 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
766 hr
= IDirectDrawSurface_SetClipper(dst_surface
, clipper
);
767 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
769 SetRect(&src_rect
, 1, 1, 5, 2);
770 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
771 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
772 for (i
= 0; i
< 4; ++i
)
774 for (j
= 0; j
< 4; ++j
)
776 x
= 80 * ((2 * j
) + 1);
777 y
= 60 * ((2 * i
) + 1);
778 color
= get_surface_color(dst_surface
, x
, y
);
779 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
780 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
781 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
785 U5(fx
).dwFillColor
= 0xff0000ff;
786 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
787 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
788 for (i
= 0; i
< 4; ++i
)
790 for (j
= 0; j
< 4; ++j
)
792 x
= 80 * ((2 * j
) + 1);
793 y
= 60 * ((2 * i
) + 1);
794 color
= get_surface_color(dst_surface
, x
, y
);
795 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
796 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
800 hr
= IDirectDrawSurface_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
801 ok(hr
== DDERR_BLTFASTCANTCLIP
|| broken(hr
== E_NOTIMPL
/* NT4 */), "Got unexpected hr %#x.\n", hr
);
803 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
804 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
805 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
806 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
807 DestroyWindow(window
);
808 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
809 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
810 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
811 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
812 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
813 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
814 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
815 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
816 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
817 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
818 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
819 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
821 IDirectDrawSurface_Release(dst_surface
);
822 IDirectDrawSurface_Release(src_surface
);
823 refcount
= IDirectDrawClipper_Release(clipper
);
824 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
825 IDirectDraw_Release(ddraw
);
828 static void test_coop_level_d3d_state(void)
830 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
831 IDirectDrawSurface
*rt
, *surface
;
832 IDirect3DMaterial
*background
;
833 IDirect3DViewport
*viewport
;
834 IDirect3DDevice
*device
;
835 D3DMATERIAL material
;
841 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
842 0, 0, 640, 480, 0, 0, 0, 0);
843 ddraw
= create_ddraw();
844 ok(!!ddraw
, "Failed to create a ddraw object.\n");
845 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
847 skip("Failed to create a 3D device, skipping test.\n");
848 IDirectDraw_Release(ddraw
);
849 DestroyWindow(window
);
853 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
854 viewport
= create_viewport(device
, 0, 0, 640, 480);
855 viewport_set_background(device
, viewport
, background
);
857 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
858 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
859 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
860 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
861 color
= get_surface_color(rt
, 320, 240);
862 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
864 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
865 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
866 hr
= IDirectDrawSurface_IsLost(rt
);
867 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
868 hr
= restore_surfaces(ddraw
);
869 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
871 memset(&material
, 0, sizeof(material
));
872 material
.dwSize
= sizeof(material
);
873 U1(U(material
).diffuse
).r
= 0.0f
;
874 U2(U(material
).diffuse
).g
= 1.0f
;
875 U3(U(material
).diffuse
).b
= 0.0f
;
876 U4(U(material
).diffuse
).a
= 1.0f
;
877 hr
= IDirect3DMaterial_SetMaterial(background
, &material
);
878 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
880 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&surface
);
881 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
882 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
883 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
884 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
885 color
= get_surface_color(rt
, 320, 240);
886 ok(compare_color(color
, 0x0000ff00, 1) || broken(compare_color(color
, 0x00000000, 1)),
887 "Got unexpected color 0x%08x.\n", color
);
889 destroy_viewport(device
, viewport
);
890 destroy_material(background
);
891 IDirectDrawSurface_Release(surface
);
892 IDirectDrawSurface_Release(rt
);
893 IDirect3DDevice_Release(device
);
894 IDirectDraw_Release(ddraw
);
895 DestroyWindow(window
);
898 static void test_surface_interface_mismatch(void)
900 IDirectDraw
*ddraw
= NULL
;
901 IDirectDrawSurface
*surface
= NULL
, *ds
;
902 IDirectDrawSurface3
*surface3
= NULL
;
903 IDirect3DDevice
*device
= NULL
;
904 IDirect3DViewport
*viewport
= NULL
;
905 IDirect3DMaterial
*background
= NULL
;
906 DDSURFACEDESC surface_desc
;
912 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
914 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
915 0, 0, 640, 480, 0, 0, 0, 0);
916 ddraw
= create_ddraw();
917 ok(!!ddraw
, "Failed to create a ddraw object.\n");
918 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
920 skip("Failed to create a 3D device, skipping test.\n");
921 IDirectDraw_Release(ddraw
);
922 DestroyWindow(window
);
925 z_depth
= get_device_z_depth(device
);
926 ok(!!z_depth
, "Failed to get device z depth.\n");
927 IDirect3DDevice_Release(device
);
930 memset(&surface_desc
, 0, sizeof(surface_desc
));
931 surface_desc
.dwSize
= sizeof(surface_desc
);
932 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
933 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
934 surface_desc
.dwWidth
= 640;
935 surface_desc
.dwHeight
= 480;
937 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
938 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
940 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
943 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
947 memset(&surface_desc
, 0, sizeof(surface_desc
));
948 surface_desc
.dwSize
= sizeof(surface_desc
);
949 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
950 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
951 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
952 surface_desc
.dwWidth
= 640;
953 surface_desc
.dwHeight
= 480;
954 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
955 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
959 /* Using a different surface interface version still works */
960 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
961 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
962 refcount
= IDirectDrawSurface_Release(ds
);
963 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
968 hr
= IDirectDrawSurface3_QueryInterface(surface3
, &IID_IDirect3DHALDevice
, (void **)&device
);
969 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
973 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
974 viewport
= create_viewport(device
, 0, 0, 640, 480);
975 viewport_set_background(device
, viewport
, background
);
977 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
978 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
979 color
= get_surface_color(surface
, 320, 240);
980 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
984 destroy_viewport(device
, viewport
);
986 destroy_material(background
);
987 if (surface3
) IDirectDrawSurface3_Release(surface3
);
988 if (surface
) IDirectDrawSurface_Release(surface
);
989 if (device
) IDirect3DDevice_Release(device
);
990 if (ddraw
) IDirectDraw_Release(ddraw
);
991 DestroyWindow(window
);
994 static void test_coop_level_threaded(void)
996 struct create_window_thread_param p
;
1000 ddraw
= create_ddraw();
1001 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1002 create_window_thread(&p
);
1004 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1005 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1007 IDirectDraw_Release(ddraw
);
1008 destroy_window_thread(&p
);
1011 static ULONG
get_refcount(IUnknown
*test_iface
)
1013 IUnknown_AddRef(test_iface
);
1014 return IUnknown_Release(test_iface
);
1017 static void test_viewport(void)
1023 IDirect3DViewport
*viewport
, *another_vp
;
1024 IDirect3DViewport2
*viewport2
;
1025 IDirect3DViewport3
*viewport3
;
1026 IDirectDrawGammaControl
*gamma
;
1028 IDirect3DDevice
*device
;
1031 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1032 0, 0, 640, 480, 0, 0, 0, 0);
1033 ddraw
= create_ddraw();
1034 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1035 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1037 skip("Failed to create a 3D device, skipping test.\n");
1038 IDirectDraw_Release(ddraw
);
1039 DestroyWindow(window
);
1043 hr
= IDirectDraw_QueryInterface(ddraw
, &IID_IDirect3D
, (void **)&d3d
);
1044 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1045 ref
= get_refcount((IUnknown
*) d3d
);
1046 ok(ref
== 2, "IDirect3D refcount is %d\n", ref
);
1048 hr
= IDirect3D_CreateViewport(d3d
, &viewport
, NULL
);
1049 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1050 ref
= get_refcount((IUnknown
*)viewport
);
1051 ok(ref
== 1, "Initial IDirect3DViewport refcount is %u\n", ref
);
1052 ref
= get_refcount((IUnknown
*)d3d
);
1053 ok(ref
== 2, "IDirect3D refcount is %u\n", ref
);
1055 /* E_FAIL return values are returned by Winetestbot Windows NT machines. While not supporting
1056 * newer interfaces is legitimate for old ddraw versions, E_FAIL violates Microsoft's rules
1057 * for QueryInterface, hence the broken() */
1058 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1059 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1060 ok(hr
== E_NOINTERFACE
|| broken(hr
== E_FAIL
), "Got unexpected hr %#x.\n", hr
);
1061 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1062 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1063 /* NULL iid: Segfaults */
1065 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IDirect3DViewport2
, (void **)&viewport2
);
1066 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
|| broken(hr
== E_FAIL
),
1067 "Failed to QI IDirect3DViewport2, hr %#x.\n", hr
);
1070 ref
= get_refcount((IUnknown
*)viewport
);
1071 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1072 ref
= get_refcount((IUnknown
*)viewport2
);
1073 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1074 IDirect3DViewport2_Release(viewport2
);
1078 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IDirect3DViewport3
, (void **)&viewport3
);
1079 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
|| broken(hr
== E_FAIL
),
1080 "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1083 ref
= get_refcount((IUnknown
*)viewport
);
1084 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1085 ref
= get_refcount((IUnknown
*)viewport3
);
1086 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1087 IDirect3DViewport3_Release(viewport3
);
1090 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IUnknown
, (void **)&unknown
);
1091 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1094 ref
= get_refcount((IUnknown
*)viewport
);
1095 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1096 ref
= get_refcount(unknown
);
1097 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1098 IUnknown_Release(unknown
);
1101 /* AddViewport(NULL): Segfault */
1102 hr
= IDirect3DDevice_DeleteViewport(device
, NULL
);
1103 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1105 hr
= IDirect3D_CreateViewport(d3d
, &another_vp
, NULL
);
1106 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1108 hr
= IDirect3DDevice_AddViewport(device
, viewport
);
1109 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1110 ref
= get_refcount((IUnknown
*) viewport
);
1111 ok(ref
== 2, "IDirect3DViewport refcount is %d\n", ref
);
1112 hr
= IDirect3DDevice_AddViewport(device
, another_vp
);
1113 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1114 ref
= get_refcount((IUnknown
*) another_vp
);
1115 ok(ref
== 2, "IDirect3DViewport refcount is %d\n", ref
);
1117 hr
= IDirect3DDevice_DeleteViewport(device
, another_vp
);
1118 ok(SUCCEEDED(hr
), "Failed to delete viewport from device, hr %#x.\n", hr
);
1119 ref
= get_refcount((IUnknown
*) another_vp
);
1120 ok(ref
== 1, "IDirect3DViewport refcount is %d\n", ref
);
1122 IDirect3DDevice_Release(device
);
1123 ref
= get_refcount((IUnknown
*) viewport
);
1124 ok(ref
== 1, "IDirect3DViewport refcount is %d\n", ref
);
1126 IDirect3DViewport_Release(another_vp
);
1127 IDirect3D_Release(d3d
);
1128 IDirect3DViewport_Release(viewport
);
1129 DestroyWindow(window
);
1130 IDirectDraw_Release(ddraw
);
1133 static void test_zenable(void)
1135 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1136 static D3DTLVERTEX tquad
[] =
1138 {{ 0.0f
}, {480.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1139 {{ 0.0f
}, { 0.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1140 {{640.0f
}, {480.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1141 {{640.0f
}, { 0.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1143 IDirect3DExecuteBuffer
*execute_buffer
;
1144 D3DEXECUTEBUFFERDESC exec_desc
;
1145 IDirect3DMaterial
*background
;
1146 IDirect3DViewport
*viewport
;
1147 IDirect3DDevice
*device
;
1148 IDirectDrawSurface
*rt
;
1158 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1159 0, 0, 640, 480, 0, 0, 0, 0);
1160 ddraw
= create_ddraw();
1161 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1162 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1164 skip("Failed to create a 3D device, skipping test.\n");
1165 IDirectDraw_Release(ddraw
);
1166 DestroyWindow(window
);
1170 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1171 viewport
= create_viewport(device
, 0, 0, 640, 480);
1172 viewport_set_background(device
, viewport
, background
);
1174 memset(&exec_desc
, 0, sizeof(exec_desc
));
1175 exec_desc
.dwSize
= sizeof(exec_desc
);
1176 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1177 exec_desc
.dwBufferSize
= 1024;
1178 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1180 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
1181 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
1182 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
1183 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
1184 memcpy(exec_desc
.lpData
, tquad
, sizeof(tquad
));
1185 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(tquad
);
1186 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1187 emit_set_rs(&ptr
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1188 emit_tquad(&ptr
, 0);
1190 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
1191 inst_length
-= sizeof(tquad
);
1192 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
1193 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
1195 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1196 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1197 hr
= IDirect3DDevice_BeginScene(device
);
1198 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1199 set_execute_data(execute_buffer
, 4, sizeof(tquad
), inst_length
);
1200 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1201 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1202 hr
= IDirect3DDevice_EndScene(device
);
1203 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1205 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
1206 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1207 for (i
= 0; i
< 4; ++i
)
1209 for (j
= 0; j
< 4; ++j
)
1211 x
= 80 * ((2 * j
) + 1);
1212 y
= 60 * ((2 * i
) + 1);
1213 color
= get_surface_color(rt
, x
, y
);
1214 ok(compare_color(color
, 0x0000ff00, 1),
1215 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1218 IDirectDrawSurface_Release(rt
);
1220 destroy_viewport(device
, viewport
);
1221 IDirect3DExecuteBuffer_Release(execute_buffer
);
1222 destroy_material(background
);
1223 IDirect3DDevice_Release(device
);
1224 IDirectDraw_Release(ddraw
);
1225 DestroyWindow(window
);
1228 static void test_ck_rgba(void)
1230 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1231 static D3DTLVERTEX tquad
[] =
1233 {{ 0.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1234 {{ 0.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1235 {{640.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1236 {{640.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1237 {{ 0.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1238 {{ 0.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1239 {{640.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1240 {{640.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1242 /* Supposedly there was no D3DRENDERSTATE_COLORKEYENABLE in D3D < 5.
1243 * Maybe the WARP driver on Windows 8 ignores setting it via the older
1244 * device interface but it's buggy in that the internal state is not
1245 * initialized, or possibly toggling D3DRENDERSTATE_COLORKEYENABLE /
1246 * D3DRENDERSTATE_ALPHABLENDENABLE has unintended side effects.
1247 * Checking the W8 test results it seems like test 1 fails most of the time
1248 * and test 0 fails very rarely. */
1251 D3DCOLOR fill_color
;
1254 D3DCOLOR result1
, result1_r200
, result1_warp
;
1255 D3DCOLOR result2
, result2_r200
, result2_warp
;
1259 /* r200 on Windows doesn't check the alpha component when applying the color
1260 * key, so the key matches on every texel. */
1261 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x0000ff00,
1262 0x000000ff, 0x000000ff, 0x0000ff00},
1263 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x0000ff00,
1264 0x000000ff, 0x000000ff, 0x0000ff00},
1265 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1266 0x0000ff00, 0x0000ff00, 0x0000ff00},
1267 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1268 0x0000ff00, 0x0000ff00, 0x0000ff00},
1269 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00,
1270 0x00807f00, 0x000000ff, 0x00807f00},
1271 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00,
1272 0x0000ff00, 0x000000ff, 0x0000ff00},
1273 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00,
1274 0x00807f00, 0x00807f00, 0x00807f00},
1275 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1276 0x0000ff00, 0x0000ff00, 0x0000ff00},
1279 IDirect3DExecuteBuffer
*execute_buffer
;
1280 D3DTEXTUREHANDLE texture_handle
;
1281 D3DEXECUTEBUFFERDESC exec_desc
;
1282 IDirect3DMaterial
*background
;
1283 IDirectDrawSurface
*surface
;
1284 IDirect3DViewport
*viewport
;
1285 DDSURFACEDESC surface_desc
;
1286 IDirect3DTexture
*texture
;
1287 IDirect3DDevice
*device
;
1288 IDirectDrawSurface
*rt
;
1296 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1297 0, 0, 640, 480, 0, 0, 0, 0);
1298 ddraw
= create_ddraw();
1299 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1300 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1302 skip("Failed to create a 3D device, skipping test.\n");
1303 IDirectDraw_Release(ddraw
);
1304 DestroyWindow(window
);
1308 background
= create_diffuse_material(device
, 1.0, 0.0f
, 0.0f
, 1.0f
);
1309 viewport
= create_viewport(device
, 0, 0, 640, 480);
1310 viewport_set_background(device
, viewport
, background
);
1312 memset(&surface_desc
, 0, sizeof(surface_desc
));
1313 surface_desc
.dwSize
= sizeof(surface_desc
);
1314 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1315 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1316 surface_desc
.dwWidth
= 256;
1317 surface_desc
.dwHeight
= 256;
1318 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1319 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1320 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1321 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1322 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1323 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1324 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1325 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1326 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1327 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1328 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1329 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
1330 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1331 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
1332 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1333 IDirect3DTexture_Release(texture
);
1335 memset(&exec_desc
, 0, sizeof(exec_desc
));
1336 exec_desc
.dwSize
= sizeof(exec_desc
);
1337 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1338 exec_desc
.dwBufferSize
= 1024;
1339 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1340 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
1341 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
1343 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
1344 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1346 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1348 UINT draw1_len
, draw2_len
;
1351 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
1352 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
1353 memcpy(exec_desc
.lpData
, tquad
, sizeof(tquad
));
1354 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(tquad
);
1355 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1356 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1357 emit_set_rs(&ptr
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1358 emit_set_rs(&ptr
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1359 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1360 emit_set_rs(&ptr
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1361 emit_tquad(&ptr
, 0);
1363 draw1_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- sizeof(tquad
);
1364 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 4, 4);
1365 emit_tquad(&ptr
, 0);
1366 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1368 draw2_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw1_len
;
1369 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
1370 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
1372 memset(&fx
, 0, sizeof(fx
));
1373 fx
.dwSize
= sizeof(fx
);
1374 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1375 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1376 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1378 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
1379 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1380 hr
= IDirect3DDevice_BeginScene(device
);
1381 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1382 set_execute_data(execute_buffer
, 8, sizeof(tquad
), draw1_len
);
1383 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1384 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1385 hr
= IDirect3DDevice_EndScene(device
);
1386 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1388 color
= get_surface_color(rt
, 320, 240);
1389 ok(compare_color(color
, tests
[i
].result1
, 1)
1390 || broken(compare_color(color
, tests
[i
].result1_r200
, 1))
1391 || broken(compare_color(color
, tests
[i
].result1_warp
, 1)),
1392 "Got unexpected color 0x%08x for test %u.\n", color
, i
);
1394 U5(fx
).dwFillColor
= 0xff0000ff;
1395 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1396 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1398 hr
= IDirect3DDevice_BeginScene(device
);
1399 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1400 set_execute_data(execute_buffer
, 8, sizeof(tquad
) + draw1_len
, draw2_len
);
1401 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1402 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1403 hr
= IDirect3DDevice_EndScene(device
);
1404 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1406 /* This tests that fragments that are masked out by the color key are
1407 * discarded, instead of just fully transparent. */
1408 color
= get_surface_color(rt
, 320, 240);
1409 ok(compare_color(color
, tests
[i
].result2
, 1)
1410 || broken(compare_color(color
, tests
[i
].result2_r200
, 1))
1411 || broken(compare_color(color
, tests
[i
].result2_warp
, 1)),
1412 "Got unexpected color 0x%08x for test %u.\n", color
, i
);
1415 IDirectDrawSurface_Release(rt
);
1416 IDirect3DExecuteBuffer_Release(execute_buffer
);
1417 IDirectDrawSurface_Release(surface
);
1418 destroy_viewport(device
, viewport
);
1419 destroy_material(background
);
1420 IDirect3DDevice_Release(device
);
1421 IDirectDraw_Release(ddraw
);
1422 DestroyWindow(window
);
1425 static void test_ck_default(void)
1427 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1428 static D3DTLVERTEX tquad
[] =
1430 {{ 0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1431 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1432 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1433 {{640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1435 IDirect3DExecuteBuffer
*execute_buffer
;
1436 IDirectDrawSurface
*surface
, *rt
;
1437 D3DTEXTUREHANDLE texture_handle
;
1438 D3DEXECUTEBUFFERDESC exec_desc
;
1439 IDirect3DMaterial
*background
;
1440 UINT draw1_offset
, draw1_len
;
1441 UINT draw2_offset
, draw2_len
;
1442 UINT draw3_offset
, draw3_len
;
1443 UINT draw4_offset
, draw4_len
;
1444 IDirect3DViewport
*viewport
;
1445 DDSURFACEDESC surface_desc
;
1446 IDirect3DTexture
*texture
;
1447 IDirect3DDevice
*device
;
1455 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1456 0, 0, 640, 480, 0, 0, 0, 0);
1457 ddraw
= create_ddraw();
1458 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1459 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1461 skip("Failed to create a 3D device, skipping test.\n");
1462 IDirectDraw_Release(ddraw
);
1463 DestroyWindow(window
);
1467 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
1468 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1470 background
= create_diffuse_material(device
, 0.0, 1.0f
, 0.0f
, 1.0f
);
1471 viewport
= create_viewport(device
, 0, 0, 640, 480);
1472 viewport_set_background(device
, viewport
, background
);
1474 memset(&surface_desc
, 0, sizeof(surface_desc
));
1475 surface_desc
.dwSize
= sizeof(surface_desc
);
1476 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1477 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1478 surface_desc
.dwWidth
= 256;
1479 surface_desc
.dwHeight
= 256;
1480 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1481 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1482 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1483 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1484 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1485 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1486 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1487 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1488 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1489 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1490 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
1491 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1492 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
1493 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1494 IDirect3DTexture_Release(texture
);
1496 memset(&fx
, 0, sizeof(fx
));
1497 fx
.dwSize
= sizeof(fx
);
1498 U5(fx
).dwFillColor
= 0x000000ff;
1499 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1500 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1502 memset(&exec_desc
, 0, sizeof(exec_desc
));
1503 exec_desc
.dwSize
= sizeof(exec_desc
);
1504 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1505 exec_desc
.dwBufferSize
= 1024;
1506 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1507 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
1508 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
1510 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
1511 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
1512 memcpy(exec_desc
.lpData
, tquad
, sizeof(tquad
));
1513 ptr
= (BYTE
*)exec_desc
.lpData
+ sizeof(tquad
);
1514 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1515 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1516 emit_tquad(&ptr
, 0);
1518 draw1_offset
= sizeof(tquad
);
1519 draw1_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw1_offset
;
1520 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1521 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, FALSE
);
1522 emit_tquad(&ptr
, 0);
1524 draw2_offset
= draw1_offset
+ draw1_len
;
1525 draw2_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw2_offset
;
1526 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1527 emit_tquad(&ptr
, 0);
1529 draw3_offset
= draw2_offset
+ draw2_len
;
1530 draw3_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw3_offset
;
1531 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1532 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1533 emit_tquad(&ptr
, 0);
1534 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1536 draw4_offset
= draw3_offset
+ draw3_len
;
1537 draw4_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw4_offset
;
1538 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
1539 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
1541 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1542 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1543 hr
= IDirect3DDevice_BeginScene(device
);
1544 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1545 set_execute_data(execute_buffer
, 4, draw1_offset
, draw1_len
);
1546 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1547 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1548 hr
= IDirect3DDevice_EndScene(device
);
1549 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1550 color
= get_surface_color(rt
, 320, 240);
1551 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1553 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1554 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1555 hr
= IDirect3DDevice_BeginScene(device
);
1556 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1557 set_execute_data(execute_buffer
, 4, draw2_offset
, draw2_len
);
1558 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1559 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1560 hr
= IDirect3DDevice_EndScene(device
);
1561 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1562 color
= get_surface_color(rt
, 320, 240);
1563 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1565 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1566 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1567 hr
= IDirect3DDevice_BeginScene(device
);
1568 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1569 set_execute_data(execute_buffer
, 4, draw3_offset
, draw3_len
);
1570 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1571 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1572 hr
= IDirect3DDevice_EndScene(device
);
1573 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1574 color
= get_surface_color(rt
, 320, 240);
1575 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1577 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1578 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1579 hr
= IDirect3DDevice_BeginScene(device
);
1580 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1581 set_execute_data(execute_buffer
, 4, draw4_offset
, draw4_len
);
1582 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1583 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1584 hr
= IDirect3DDevice_EndScene(device
);
1585 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1586 color
= get_surface_color(rt
, 320, 240);
1587 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1589 IDirect3DExecuteBuffer_Release(execute_buffer
);
1590 IDirectDrawSurface_Release(surface
);
1591 destroy_viewport(device
, viewport
);
1592 destroy_material(background
);
1593 IDirectDrawSurface_Release(rt
);
1594 IDirect3DDevice_Release(device
);
1595 IDirectDraw_Release(ddraw
);
1596 DestroyWindow(window
);
1599 static void test_ck_complex(void)
1601 IDirectDrawSurface
*surface
, *mipmap
, *tmp
;
1602 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
1603 DDSURFACEDESC surface_desc
;
1604 IDirect3DDevice
*device
;
1605 DDCOLORKEY color_key
;
1612 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1613 0, 0, 640, 480, 0, 0, 0, 0);
1614 ddraw
= create_ddraw();
1615 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1616 if (!(device
= create_device(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1618 skip("Failed to create a 3D device, skipping test.\n");
1619 DestroyWindow(window
);
1620 IDirectDraw2_Release(ddraw
);
1623 IDirect3DDevice_Release(device
);
1625 memset(&surface_desc
, 0, sizeof(surface_desc
));
1626 surface_desc
.dwSize
= sizeof(surface_desc
);
1627 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1628 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1629 surface_desc
.dwWidth
= 128;
1630 surface_desc
.dwHeight
= 128;
1631 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1632 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1634 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1635 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1636 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1637 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1638 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1639 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1640 memset(&color_key
, 0, sizeof(color_key
));
1641 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1642 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1643 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1644 color_key
.dwColorSpaceLowValue
);
1645 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1646 color_key
.dwColorSpaceHighValue
);
1649 IDirectDrawSurface_AddRef(mipmap
);
1650 for (i
= 0; i
< 7; ++i
)
1652 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1653 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1655 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1656 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1657 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1658 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1659 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1660 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x, i %u.\n", hr
, i
);
1661 memset(&color_key
, 0, sizeof(color_key
));
1662 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1663 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x, i %u.\n", hr
, i
);
1664 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1665 color_key
.dwColorSpaceLowValue
, i
);
1666 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1667 color_key
.dwColorSpaceHighValue
, i
);
1669 IDirectDrawSurface_Release(mipmap
);
1673 memset(&color_key
, 0, sizeof(color_key
));
1674 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1675 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1676 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1677 color_key
.dwColorSpaceLowValue
);
1678 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1679 color_key
.dwColorSpaceHighValue
);
1681 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1682 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1683 IDirectDrawSurface_Release(mipmap
);
1684 refcount
= IDirectDrawSurface_Release(surface
);
1685 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1687 memset(&surface_desc
, 0, sizeof(surface_desc
));
1688 surface_desc
.dwSize
= sizeof(surface_desc
);
1689 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1690 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1691 surface_desc
.dwBackBufferCount
= 1;
1692 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1693 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1695 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1696 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1697 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1698 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1699 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1700 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1701 memset(&color_key
, 0, sizeof(color_key
));
1702 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1703 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1704 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1705 color_key
.dwColorSpaceLowValue
);
1706 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1707 color_key
.dwColorSpaceHighValue
);
1709 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
1710 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
1712 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1713 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1714 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1715 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1716 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1717 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1718 memset(&color_key
, 0, sizeof(color_key
));
1719 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1720 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1721 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1722 color_key
.dwColorSpaceLowValue
);
1723 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1724 color_key
.dwColorSpaceHighValue
);
1726 IDirectDrawSurface_Release(tmp
);
1728 refcount
= IDirectDrawSurface_Release(surface
);
1729 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1730 refcount
= IDirectDraw_Release(ddraw
);
1731 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1732 DestroyWindow(window
);
1738 REFIID refcount_iid
;
1742 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
1743 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
1745 ULONG refcount
, expected_refcount
;
1746 IUnknown
*iface1
, *iface2
;
1750 for (i
= 0; i
< entry_count
; ++i
)
1752 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
1753 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
1756 for (j
= 0; j
< entry_count
; ++j
)
1758 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
1759 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
1762 expected_refcount
= 0;
1763 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
1764 ++expected_refcount
;
1765 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
1766 ++expected_refcount
;
1767 refcount
= IUnknown_Release(iface2
);
1768 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1769 refcount
, test_name
, i
, j
, expected_refcount
);
1773 expected_refcount
= 0;
1774 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
1775 ++expected_refcount
;
1776 refcount
= IUnknown_Release(iface1
);
1777 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1778 refcount
, test_name
, i
, expected_refcount
);
1783 static void test_surface_qi(void)
1785 static const struct qi_test tests
[] =
1787 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface
, S_OK
},
1788 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface
, S_OK
},
1789 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1790 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1791 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1792 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1793 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1794 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1795 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1796 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
1797 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
1798 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
1799 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
1800 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
1801 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
1802 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
1803 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
1804 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
1805 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
1806 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
1807 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
1808 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
1809 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
1810 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
1811 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
1812 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
1813 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
1814 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
1815 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
1816 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
1817 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
1818 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
1819 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
1820 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
1821 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1824 IDirectDrawSurface
*surface
;
1825 DDSURFACEDESC surface_desc
;
1826 IDirect3DDevice
*device
;
1831 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1833 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1837 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1838 0, 0, 640, 480, 0, 0, 0, 0);
1839 ddraw
= create_ddraw();
1840 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1841 /* Try to create a D3D device to see if the ddraw implementation supports
1842 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1843 * doesn't support e.g. the IDirect3DTexture interfaces. */
1844 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1846 skip("Failed to create a 3D device, skipping test.\n");
1847 IDirectDraw_Release(ddraw
);
1848 DestroyWindow(window
);
1851 IDirect3DDevice_Release(device
);
1853 memset(&surface_desc
, 0, sizeof(surface_desc
));
1854 surface_desc
.dwSize
= sizeof(surface_desc
);
1855 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1856 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1857 surface_desc
.dwWidth
= 512;
1858 surface_desc
.dwHeight
= 512;
1859 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1860 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1862 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface
, tests
, sizeof(tests
) / sizeof(*tests
));
1864 IDirectDrawSurface_Release(surface
);
1865 IDirectDraw_Release(ddraw
);
1866 DestroyWindow(window
);
1869 static void test_device_qi(void)
1871 static const struct qi_test tests
[] =
1873 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface
, S_OK
},
1874 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface
, S_OK
},
1875 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1876 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1877 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1878 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1879 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1880 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1881 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1882 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
1883 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
1884 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
1885 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
1886 {&IID_IDirect3DHALDevice
, &IID_IDirectDrawSurface
, S_OK
},
1887 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
1888 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
1889 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
1890 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
1891 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
1892 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
1893 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
1894 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
1895 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
1896 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
1897 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
1898 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
1899 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
1900 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
1901 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
1902 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
1903 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
1904 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
1905 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
1906 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
1907 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
1908 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1912 IDirect3DDevice
*device
;
1916 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1918 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1922 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1923 0, 0, 640, 480, 0, 0, 0, 0);
1924 ddraw
= create_ddraw();
1925 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1926 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1928 skip("Failed to create a 3D device, skipping test.\n");
1929 IDirectDraw_Release(ddraw
);
1930 DestroyWindow(window
);
1934 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirectDrawSurface
, tests
, sizeof(tests
) / sizeof(*tests
));
1936 IDirect3DDevice_Release(device
);
1937 IDirectDraw_Release(ddraw
);
1938 DestroyWindow(window
);
1941 static void test_wndproc(void)
1943 LONG_PTR proc
, ddraw_proc
;
1950 static struct message messages
[] =
1952 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
1953 {WM_MOVE
, FALSE
, 0},
1954 {WM_SIZE
, FALSE
, 0},
1955 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
1956 {WM_ACTIVATE
, FALSE
, 0},
1957 {WM_SETFOCUS
, FALSE
, 0},
1961 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
1962 ddraw
= create_ddraw();
1963 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1965 wc
.lpfnWndProc
= test_proc
;
1966 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
1967 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
1969 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
1970 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
1972 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1973 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
1974 (LONG_PTR
)test_proc
, proc
);
1975 expect_messages
= messages
;
1976 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1977 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
1978 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
1979 expect_messages
= NULL
;
1980 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1981 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
1982 (LONG_PTR
)test_proc
, proc
);
1983 ref
= IDirectDraw_Release(ddraw
);
1984 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
1985 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1986 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
1987 (LONG_PTR
)test_proc
, proc
);
1989 /* DDSCL_NORMAL doesn't. */
1990 ddraw
= create_ddraw();
1991 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1992 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
1993 (LONG_PTR
)test_proc
, proc
);
1994 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
1995 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
1996 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1997 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
1998 (LONG_PTR
)test_proc
, proc
);
1999 ref
= IDirectDraw_Release(ddraw
);
2000 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2001 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2002 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2003 (LONG_PTR
)test_proc
, proc
);
2005 /* The original window proc is only restored by ddraw if the current
2006 * window proc matches the one ddraw set. This also affects switching
2007 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2008 ddraw
= create_ddraw();
2009 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2010 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2011 (LONG_PTR
)test_proc
, proc
);
2012 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2013 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2014 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2015 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2016 (LONG_PTR
)test_proc
, proc
);
2018 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2019 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2020 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2021 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2022 (LONG_PTR
)test_proc
, proc
);
2023 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2024 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2025 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2026 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2027 (LONG_PTR
)test_proc
, proc
);
2028 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2029 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2030 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2031 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2032 (LONG_PTR
)DefWindowProcA
, proc
);
2033 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2034 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2035 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2036 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2037 (LONG_PTR
)DefWindowProcA
, proc
);
2038 ref
= IDirectDraw_Release(ddraw
);
2039 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2040 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2041 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2042 (LONG_PTR
)test_proc
, proc
);
2044 ddraw
= create_ddraw();
2045 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2046 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2047 (LONG_PTR
)test_proc
, proc
);
2048 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2049 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2050 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2051 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2052 (LONG_PTR
)test_proc
, proc
);
2053 ref
= IDirectDraw_Release(ddraw
);
2054 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2055 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2056 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2057 (LONG_PTR
)DefWindowProcA
, proc
);
2059 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2060 expect_messages
= NULL
;
2061 DestroyWindow(window
);
2062 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2065 static void test_window_style(void)
2067 LONG style
, exstyle
, tmp
, expected_style
;
2068 RECT fullscreen_rect
, r
;
2075 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2076 0, 0, 100, 100, 0, 0, 0, 0);
2077 ddraw
= create_ddraw();
2078 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2080 style
= GetWindowLongA(window
, GWL_STYLE
);
2081 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2082 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2084 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2085 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2087 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2088 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2089 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2090 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2092 GetWindowRect(window
, &r
);
2093 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2094 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2095 r
.left
, r
.top
, r
.right
, r
.bottom
);
2096 GetClientRect(window
, &r
);
2097 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2099 ret
= SetForegroundWindow(GetDesktopWindow());
2100 ok(ret
, "Failed to set foreground window.\n");
2102 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2103 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2104 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2105 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2107 ret
= SetForegroundWindow(window
);
2108 ok(ret
, "Failed to set foreground window.\n");
2109 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2110 * the next tests expect this. */
2111 ShowWindow(window
, SW_HIDE
);
2113 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2114 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2116 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2117 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2118 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2119 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2121 ShowWindow(window
, SW_SHOW
);
2122 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2123 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2125 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2126 expected_style
= style
| WS_VISIBLE
;
2127 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2128 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2129 expected_style
= exstyle
| WS_EX_TOPMOST
;
2130 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2132 ret
= SetForegroundWindow(GetDesktopWindow());
2133 ok(ret
, "Failed to set foreground window.\n");
2134 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2135 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2136 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2137 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2138 expected_style
= exstyle
| WS_EX_TOPMOST
;
2139 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2141 ref
= IDirectDraw_Release(ddraw
);
2142 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2144 DestroyWindow(window
);
2147 static void test_redundant_mode_set(void)
2149 DDSURFACEDESC surface_desc
= {0};
2156 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2157 0, 0, 100, 100, 0, 0, 0, 0);
2158 ddraw
= create_ddraw();
2159 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2161 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2162 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2164 surface_desc
.dwSize
= sizeof(surface_desc
);
2165 hr
= IDirectDraw_GetDisplayMode(ddraw
, &surface_desc
);
2166 ok(SUCCEEDED(hr
), "GetDipslayMode failed, hr %#x.\n", hr
);
2168 hr
= IDirectDraw_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2169 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
2170 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2172 GetWindowRect(window
, &r
);
2175 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2176 GetWindowRect(window
, &s
);
2177 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2178 r
.left
, r
.top
, r
.right
, r
.bottom
,
2179 s
.left
, s
.top
, s
.right
, s
.bottom
);
2181 hr
= IDirectDraw_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2182 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
2183 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2185 GetWindowRect(window
, &s
);
2186 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2187 r
.left
, r
.top
, r
.right
, r
.bottom
,
2188 s
.left
, s
.top
, s
.right
, s
.bottom
);
2190 ref
= IDirectDraw_Release(ddraw
);
2191 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2193 DestroyWindow(window
);
2196 static SIZE screen_size
;
2198 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2200 if (message
== WM_SIZE
)
2202 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2203 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2206 return test_proc(hwnd
, message
, wparam
, lparam
);
2209 struct test_coop_level_mode_set_enum_param
2211 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2214 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC
*surface_desc
, void *context
)
2216 struct test_coop_level_mode_set_enum_param
*param
= context
;
2218 if (U1(surface_desc
->ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2219 return DDENUMRET_OK
;
2220 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2221 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2222 return DDENUMRET_OK
;
2224 if (!param
->ddraw_width
)
2226 param
->ddraw_width
= surface_desc
->dwWidth
;
2227 param
->ddraw_height
= surface_desc
->dwHeight
;
2228 return DDENUMRET_OK
;
2230 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2231 return DDENUMRET_OK
;
2233 param
->user32_width
= surface_desc
->dwWidth
;
2234 param
->user32_height
= surface_desc
->dwHeight
;
2235 return DDENUMRET_CANCEL
;
2238 static void test_coop_level_mode_set(void)
2240 IDirectDrawSurface
*primary
;
2241 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2249 struct test_coop_level_mode_set_enum_param param
;
2254 static const struct message exclusive_messages
[] =
2256 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2257 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2258 {WM_SIZE
, FALSE
, 0},
2259 {WM_DISPLAYCHANGE
, FALSE
, 0},
2262 static const struct message exclusive_focus_loss_messages
[] =
2264 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2265 {WM_DISPLAYCHANGE
, FALSE
, 0},
2266 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2267 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2268 * SW_MINIMIZED, causing a recursive window activation that does not
2269 * produce the same result in Wine yet. Ignore the difference for now.
2270 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2271 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2272 {WM_MOVE
, FALSE
, 0},
2273 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2274 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2277 static const struct message exclusive_focus_restore_messages
[] =
2279 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2280 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2281 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2282 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2283 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2284 /* Native redundantly sets the window size here. */
2285 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2286 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2287 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2288 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2291 static const struct message sc_restore_messages
[] =
2293 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2294 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2295 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2296 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2299 static const struct message sc_minimize_messages
[] =
2301 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2302 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2303 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2304 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2307 static const struct message sc_maximize_messages
[] =
2309 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2310 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2311 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2312 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2316 static const struct message normal_messages
[] =
2318 {WM_DISPLAYCHANGE
, FALSE
, 0},
2322 ddraw
= create_ddraw();
2323 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2325 memset(¶m
, 0, sizeof(param
));
2326 hr
= IDirectDraw_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2327 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2328 ref
= IDirectDraw_Release(ddraw
);
2329 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2331 if (!param
.user32_height
)
2333 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2337 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2338 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2339 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2341 memset(&devmode
, 0, sizeof(devmode
));
2342 devmode
.dmSize
= sizeof(devmode
);
2343 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2344 devmode
.dmPelsWidth
= param
.user32_width
;
2345 devmode
.dmPelsHeight
= param
.user32_height
;
2346 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2347 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2349 ddraw
= create_ddraw();
2350 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2352 wc
.lpfnWndProc
= mode_set_proc
;
2353 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2354 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2356 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2357 0, 0, 100, 100, 0, 0, 0, 0);
2359 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2360 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2362 GetWindowRect(window
, &r
);
2363 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2364 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2365 r
.left
, r
.top
, r
.right
, r
.bottom
);
2367 memset(&ddsd
, 0, sizeof(ddsd
));
2368 ddsd
.dwSize
= sizeof(ddsd
);
2369 ddsd
.dwFlags
= DDSD_CAPS
;
2370 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2372 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2373 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2374 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2375 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2376 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2377 param
.user32_width
, ddsd
.dwWidth
);
2378 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2379 param
.user32_height
, ddsd
.dwHeight
);
2381 GetWindowRect(window
, &r
);
2382 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2383 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2384 r
.left
, r
.top
, r
.right
, r
.bottom
);
2386 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2387 expect_messages
= exclusive_messages
;
2391 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2392 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2394 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2395 expect_messages
= NULL
;
2396 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2397 "Expected screen size %ux%u, got %ux%u.\n",
2398 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2400 GetWindowRect(window
, &r
);
2401 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2402 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2403 r
.left
, r
.top
, r
.right
, r
.bottom
);
2405 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2406 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2407 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2408 param
.user32_width
, ddsd
.dwWidth
);
2409 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2410 param
.user32_height
, ddsd
.dwHeight
);
2411 IDirectDrawSurface_Release(primary
);
2413 memset(&ddsd
, 0, sizeof(ddsd
));
2414 ddsd
.dwSize
= sizeof(ddsd
);
2415 ddsd
.dwFlags
= DDSD_CAPS
;
2416 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2418 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2419 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2420 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2421 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2422 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2423 param
.ddraw_width
, ddsd
.dwWidth
);
2424 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2425 param
.ddraw_height
, ddsd
.dwHeight
);
2427 GetWindowRect(window
, &r
);
2428 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2429 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2430 r
.left
, r
.top
, r
.right
, r
.bottom
);
2432 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2433 expect_messages
= exclusive_messages
;
2437 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2438 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2440 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2441 expect_messages
= NULL
;
2442 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2443 "Expected screen size %ux%u, got %ux%u.\n",
2444 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2446 GetWindowRect(window
, &r
);
2447 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2448 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2449 r
.left
, r
.top
, r
.right
, r
.bottom
);
2451 expect_messages
= exclusive_focus_loss_messages
;
2452 ret
= SetForegroundWindow(GetDesktopWindow());
2453 ok(ret
, "Failed to set foreground window.\n");
2454 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2455 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2456 ok(ret
, "Failed to get display mode.\n");
2457 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2458 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2459 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2461 expect_messages
= exclusive_focus_restore_messages
;
2462 ShowWindow(window
, SW_RESTORE
);
2463 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2465 GetWindowRect(window
, &r
);
2466 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2467 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2468 r
.left
, r
.top
, r
.right
, r
.bottom
);
2469 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2470 ok(ret
, "Failed to get display mode.\n");
2471 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2472 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2473 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2475 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2476 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2477 /* Normally the primary should be restored here. Unfortunately this causes the
2478 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2479 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2480 * the point of the GetSurfaceDesc call. */
2482 expect_messages
= sc_minimize_messages
;
2483 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2484 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2485 expect_messages
= NULL
;
2487 expect_messages
= sc_restore_messages
;
2488 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2489 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2490 expect_messages
= NULL
;
2492 expect_messages
= sc_maximize_messages
;
2493 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2494 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2495 expect_messages
= NULL
;
2497 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2498 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2500 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2501 expect_messages
= exclusive_messages
;
2505 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2506 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2508 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2509 expect_messages
= NULL
;
2510 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2511 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2512 "Expected screen size %ux%u, got %ux%u.\n",
2513 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2515 GetWindowRect(window
, &r
);
2516 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2517 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2518 r
.left
, r
.top
, r
.right
, r
.bottom
);
2520 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2521 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2522 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2523 param
.ddraw_width
, ddsd
.dwWidth
);
2524 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2525 param
.ddraw_height
, ddsd
.dwHeight
);
2526 IDirectDrawSurface_Release(primary
);
2529 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2530 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2532 memset(&ddsd
, 0, sizeof(ddsd
));
2533 ddsd
.dwSize
= sizeof(ddsd
);
2534 ddsd
.dwFlags
= DDSD_CAPS
;
2535 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2537 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2538 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2539 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2540 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2541 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2542 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2543 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2544 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2546 GetWindowRect(window
, &r
);
2547 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2548 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2549 r
.left
, r
.top
, r
.right
, r
.bottom
);
2551 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2552 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2554 GetWindowRect(window
, &r
);
2555 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2556 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2557 r
.left
, r
.top
, r
.right
, r
.bottom
);
2559 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2560 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2561 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2562 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2563 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2564 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2565 IDirectDrawSurface_Release(primary
);
2567 memset(&ddsd
, 0, sizeof(ddsd
));
2568 ddsd
.dwSize
= sizeof(ddsd
);
2569 ddsd
.dwFlags
= DDSD_CAPS
;
2570 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2572 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2573 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2574 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2575 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2576 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2577 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2578 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2579 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2581 GetWindowRect(window
, &r
);
2582 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2583 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2584 r
.left
, r
.top
, r
.right
, r
.bottom
);
2586 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2587 expect_messages
= normal_messages
;
2591 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2592 devmode
.dmPelsWidth
= param
.user32_width
;
2593 devmode
.dmPelsHeight
= param
.user32_height
;
2594 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2595 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2597 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2598 expect_messages
= NULL
;
2599 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2601 GetWindowRect(window
, &r
);
2602 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2603 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2604 r
.left
, r
.top
, r
.right
, r
.bottom
);
2606 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2607 expect_messages
= normal_messages
;
2611 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2612 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
2614 win_skip("Broken SetDisplayMode(), skipping remaining tests.\n");
2615 IDirectDrawSurface_Release(primary
);
2616 IDirectDraw_Release(ddraw
);
2619 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2621 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2622 expect_messages
= NULL
;
2623 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2625 GetWindowRect(window
, &r
);
2626 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2627 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2628 r
.left
, r
.top
, r
.right
, r
.bottom
);
2630 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2631 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2632 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2633 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2634 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2635 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2636 IDirectDrawSurface_Release(primary
);
2638 memset(&ddsd
, 0, sizeof(ddsd
));
2639 ddsd
.dwSize
= sizeof(ddsd
);
2640 ddsd
.dwFlags
= DDSD_CAPS
;
2641 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2643 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2644 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2645 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2646 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2647 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2648 param
.ddraw_width
, ddsd
.dwWidth
);
2649 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2650 param
.ddraw_height
, ddsd
.dwHeight
);
2652 GetWindowRect(window
, &r
);
2653 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2654 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2655 r
.left
, r
.top
, r
.right
, r
.bottom
);
2657 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2658 expect_messages
= normal_messages
;
2662 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2663 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2665 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2666 expect_messages
= NULL
;
2667 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2669 GetWindowRect(window
, &r
);
2670 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2671 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2672 r
.left
, r
.top
, r
.right
, r
.bottom
);
2674 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2675 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2676 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2677 param
.ddraw_width
, ddsd
.dwWidth
);
2678 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2679 param
.ddraw_height
, ddsd
.dwHeight
);
2680 IDirectDrawSurface_Release(primary
);
2682 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2683 ok(ret
, "Failed to get display mode.\n");
2684 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2685 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2686 "Expected resolution %ux%u, got %ux%u.\n",
2687 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2688 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2689 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2690 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2692 memset(&ddsd
, 0, sizeof(ddsd
));
2693 ddsd
.dwSize
= sizeof(ddsd
);
2694 ddsd
.dwFlags
= DDSD_CAPS
;
2695 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2697 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2698 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2699 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2700 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2701 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2702 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2703 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2704 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2706 GetWindowRect(window
, &r
);
2707 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2708 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2709 r
.left
, r
.top
, r
.right
, r
.bottom
);
2711 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2712 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2713 * not DDSCL_FULLSCREEN. */
2714 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2715 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2717 GetWindowRect(window
, &r
);
2718 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2719 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2720 r
.left
, r
.top
, r
.right
, r
.bottom
);
2722 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2723 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2724 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2725 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2726 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2727 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2728 IDirectDrawSurface_Release(primary
);
2730 memset(&ddsd
, 0, sizeof(ddsd
));
2731 ddsd
.dwSize
= sizeof(ddsd
);
2732 ddsd
.dwFlags
= DDSD_CAPS
;
2733 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2735 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2736 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2737 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2738 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2739 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2740 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2741 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2742 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2744 GetWindowRect(window
, &r
);
2745 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2746 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2747 r
.left
, r
.top
, r
.right
, r
.bottom
);
2749 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2750 expect_messages
= normal_messages
;
2754 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2755 devmode
.dmPelsWidth
= param
.user32_width
;
2756 devmode
.dmPelsHeight
= param
.user32_height
;
2757 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2758 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2760 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2761 expect_messages
= NULL
;
2762 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2764 GetWindowRect(window
, &r
);
2765 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2766 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2767 r
.left
, r
.top
, r
.right
, r
.bottom
);
2769 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2770 expect_messages
= normal_messages
;
2774 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2775 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2777 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2778 expect_messages
= NULL
;
2779 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2781 GetWindowRect(window
, &r
);
2782 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2783 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2784 r
.left
, r
.top
, r
.right
, r
.bottom
);
2786 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2787 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2788 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2789 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2790 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2791 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2792 IDirectDrawSurface_Release(primary
);
2794 memset(&ddsd
, 0, sizeof(ddsd
));
2795 ddsd
.dwSize
= sizeof(ddsd
);
2796 ddsd
.dwFlags
= DDSD_CAPS
;
2797 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2799 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2800 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2801 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2802 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2803 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2804 param
.ddraw_width
, ddsd
.dwWidth
);
2805 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2806 param
.ddraw_height
, ddsd
.dwHeight
);
2808 GetWindowRect(window
, &r
);
2809 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2810 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2811 r
.left
, r
.top
, r
.right
, r
.bottom
);
2813 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2814 expect_messages
= normal_messages
;
2818 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2819 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2821 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2822 expect_messages
= NULL
;
2823 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2825 GetWindowRect(window
, &r
);
2826 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2827 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2828 r
.left
, r
.top
, r
.right
, r
.bottom
);
2830 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2831 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2832 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2833 param
.ddraw_width
, ddsd
.dwWidth
);
2834 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2835 param
.ddraw_height
, ddsd
.dwHeight
);
2836 IDirectDrawSurface_Release(primary
);
2838 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2839 ok(ret
, "Failed to get display mode.\n");
2840 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2841 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2842 "Expected resolution %ux%u, got %ux%u.\n",
2843 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2844 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2845 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2846 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2848 memset(&ddsd
, 0, sizeof(ddsd
));
2849 ddsd
.dwSize
= sizeof(ddsd
);
2850 ddsd
.dwFlags
= DDSD_CAPS
;
2851 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2853 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2854 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2855 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2856 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2857 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2858 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2859 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2860 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2861 IDirectDrawSurface_Release(primary
);
2863 GetWindowRect(window
, &r
);
2864 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2865 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2866 r
.left
, r
.top
, r
.right
, r
.bottom
);
2868 /* Unlike ddraw2-7, changing from EXCLUSIVE to NORMAL does not restore the resolution */
2869 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2870 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2871 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2872 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2874 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2875 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2877 memset(&ddsd
, 0, sizeof(ddsd
));
2878 ddsd
.dwSize
= sizeof(ddsd
);
2879 ddsd
.dwFlags
= DDSD_CAPS
;
2880 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2882 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2883 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2884 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2885 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2886 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2887 param
.ddraw_width
, ddsd
.dwWidth
);
2888 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2889 param
.ddraw_height
, ddsd
.dwHeight
);
2890 IDirectDrawSurface_Release(primary
);
2891 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2892 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2894 ref
= IDirectDraw_Release(ddraw
);
2895 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2897 GetWindowRect(window
, &r
);
2898 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2899 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2900 r
.left
, r
.top
, r
.right
, r
.bottom
);
2903 expect_messages
= NULL
;
2904 DestroyWindow(window
);
2905 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2908 static void test_coop_level_mode_set_multi(void)
2910 IDirectDraw
*ddraw1
, *ddraw2
;
2916 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2917 0, 0, 100, 100, 0, 0, 0, 0);
2918 ddraw1
= create_ddraw();
2919 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
2921 /* With just a single ddraw object, the display mode is restored on
2923 hr
= set_display_mode(ddraw1
, 800, 600);
2924 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
2926 win_skip("Broken SetDisplayMode(), skipping test.\n");
2927 IDirectDraw_Release(ddraw1
);
2928 DestroyWindow(window
);
2931 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2932 w
= GetSystemMetrics(SM_CXSCREEN
);
2933 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
2934 h
= GetSystemMetrics(SM_CYSCREEN
);
2935 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
2937 ref
= IDirectDraw_Release(ddraw1
);
2938 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2939 w
= GetSystemMetrics(SM_CXSCREEN
);
2940 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
2941 h
= GetSystemMetrics(SM_CYSCREEN
);
2942 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
2944 /* When there are multiple ddraw objects, the display mode is restored to
2945 * the initial mode, before the first SetDisplayMode() call. */
2946 ddraw1
= create_ddraw();
2947 hr
= set_display_mode(ddraw1
, 800, 600);
2948 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2949 w
= GetSystemMetrics(SM_CXSCREEN
);
2950 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
2951 h
= GetSystemMetrics(SM_CYSCREEN
);
2952 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
2954 ddraw2
= create_ddraw();
2955 hr
= set_display_mode(ddraw2
, 640, 480);
2956 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2957 w
= GetSystemMetrics(SM_CXSCREEN
);
2958 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
2959 h
= GetSystemMetrics(SM_CYSCREEN
);
2960 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
2962 ref
= IDirectDraw_Release(ddraw2
);
2963 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2964 w
= GetSystemMetrics(SM_CXSCREEN
);
2965 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
2966 h
= GetSystemMetrics(SM_CYSCREEN
);
2967 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
2969 ref
= IDirectDraw_Release(ddraw1
);
2970 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2971 w
= GetSystemMetrics(SM_CXSCREEN
);
2972 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
2973 h
= GetSystemMetrics(SM_CYSCREEN
);
2974 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
2976 /* Regardless of release ordering. */
2977 ddraw1
= create_ddraw();
2978 hr
= set_display_mode(ddraw1
, 800, 600);
2979 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2980 w
= GetSystemMetrics(SM_CXSCREEN
);
2981 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
2982 h
= GetSystemMetrics(SM_CYSCREEN
);
2983 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
2985 ddraw2
= create_ddraw();
2986 hr
= set_display_mode(ddraw2
, 640, 480);
2987 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2988 w
= GetSystemMetrics(SM_CXSCREEN
);
2989 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
2990 h
= GetSystemMetrics(SM_CYSCREEN
);
2991 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
2993 ref
= IDirectDraw_Release(ddraw1
);
2994 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2995 w
= GetSystemMetrics(SM_CXSCREEN
);
2996 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
2997 h
= GetSystemMetrics(SM_CYSCREEN
);
2998 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3000 ref
= IDirectDraw_Release(ddraw2
);
3001 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3002 w
= GetSystemMetrics(SM_CXSCREEN
);
3003 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3004 h
= GetSystemMetrics(SM_CYSCREEN
);
3005 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3007 /* But only for ddraw objects that called SetDisplayMode(). */
3008 ddraw1
= create_ddraw();
3009 ddraw2
= create_ddraw();
3010 hr
= set_display_mode(ddraw2
, 640, 480);
3011 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3012 w
= GetSystemMetrics(SM_CXSCREEN
);
3013 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3014 h
= GetSystemMetrics(SM_CYSCREEN
);
3015 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3017 ref
= IDirectDraw_Release(ddraw1
);
3018 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3019 w
= GetSystemMetrics(SM_CXSCREEN
);
3020 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3021 h
= GetSystemMetrics(SM_CYSCREEN
);
3022 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3024 ref
= IDirectDraw_Release(ddraw2
);
3025 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3026 w
= GetSystemMetrics(SM_CXSCREEN
);
3027 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3028 h
= GetSystemMetrics(SM_CYSCREEN
);
3029 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3031 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3032 * restoring the display mode. */
3033 ddraw1
= create_ddraw();
3034 hr
= set_display_mode(ddraw1
, 800, 600);
3035 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3036 w
= GetSystemMetrics(SM_CXSCREEN
);
3037 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3038 h
= GetSystemMetrics(SM_CYSCREEN
);
3039 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3041 ddraw2
= create_ddraw();
3042 hr
= set_display_mode(ddraw2
, 640, 480);
3043 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3044 w
= GetSystemMetrics(SM_CXSCREEN
);
3045 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3046 h
= GetSystemMetrics(SM_CYSCREEN
);
3047 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3049 hr
= IDirectDraw_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3050 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3052 ref
= IDirectDraw_Release(ddraw1
);
3053 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3054 w
= GetSystemMetrics(SM_CXSCREEN
);
3055 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3056 h
= GetSystemMetrics(SM_CYSCREEN
);
3057 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3059 ref
= IDirectDraw_Release(ddraw2
);
3060 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3061 w
= GetSystemMetrics(SM_CXSCREEN
);
3062 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3063 h
= GetSystemMetrics(SM_CYSCREEN
);
3064 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3066 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3067 ddraw1
= create_ddraw();
3068 hr
= set_display_mode(ddraw1
, 800, 600);
3069 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3070 w
= GetSystemMetrics(SM_CXSCREEN
);
3071 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3072 h
= GetSystemMetrics(SM_CYSCREEN
);
3073 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3075 hr
= IDirectDraw_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3076 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3078 ddraw2
= create_ddraw();
3079 hr
= set_display_mode(ddraw2
, 640, 480);
3080 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3082 ref
= IDirectDraw_Release(ddraw1
);
3083 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3084 w
= GetSystemMetrics(SM_CXSCREEN
);
3085 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3086 h
= GetSystemMetrics(SM_CYSCREEN
);
3087 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3089 ref
= IDirectDraw_Release(ddraw2
);
3090 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3091 w
= GetSystemMetrics(SM_CXSCREEN
);
3092 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3093 h
= GetSystemMetrics(SM_CYSCREEN
);
3094 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3096 DestroyWindow(window
);
3099 static void test_initialize(void)
3105 ddraw
= create_ddraw();
3106 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3108 hr
= IDirectDraw_Initialize(ddraw
, NULL
);
3109 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3110 IDirectDraw_Release(ddraw
);
3113 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw
, (void **)&ddraw
);
3114 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw instance, hr %#x.\n", hr
);
3115 hr
= IDirectDraw_QueryInterface(ddraw
, &IID_IDirect3D
, (void **)&d3d
);
3118 /* IDirect3D_Initialize() just returns DDERR_ALREADYINITIALIZED. */
3119 hr
= IDirect3D_Initialize(d3d
, NULL
);
3120 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3121 IDirect3D_Release(d3d
);
3124 skip("D3D interface is not available, skipping test.\n");
3125 hr
= IDirectDraw_Initialize(ddraw
, NULL
);
3126 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3127 hr
= IDirectDraw_Initialize(ddraw
, NULL
);
3128 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3129 IDirectDraw_Release(ddraw
);
3132 if (0) /* This crashes on the W2KPROSP4 testbot. */
3135 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirect3D
, (void **)&d3d
);
3136 ok(hr
== E_NOINTERFACE
, "CoCreateInstance returned hr %#x, expected E_NOINTERFACE.\n", hr
);
3141 static void test_coop_level_surf_create(void)
3143 IDirectDrawSurface
*surface
;
3148 ddraw
= create_ddraw();
3149 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3151 memset(&ddsd
, 0, sizeof(ddsd
));
3152 ddsd
.dwSize
= sizeof(ddsd
);
3153 ddsd
.dwFlags
= DDSD_CAPS
;
3154 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3155 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3156 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3158 IDirectDraw_Release(ddraw
);
3161 static void test_coop_level_multi_window(void)
3163 HWND window1
, window2
;
3167 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3168 0, 0, 640, 480, 0, 0, 0, 0);
3169 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3170 0, 0, 640, 480, 0, 0, 0, 0);
3171 ddraw
= create_ddraw();
3172 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3174 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3175 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3176 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3177 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3178 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3179 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3181 IDirectDraw_Release(ddraw
);
3182 DestroyWindow(window2
);
3183 DestroyWindow(window1
);
3186 static void test_clear_rect_count(void)
3188 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3189 IDirect3DMaterial
*white
, *red
, *green
, *blue
;
3190 IDirect3DViewport
*viewport
;
3191 IDirect3DDevice
*device
;
3192 IDirectDrawSurface
*rt
;
3198 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3199 0, 0, 640, 480, 0, 0, 0, 0);
3200 ddraw
= create_ddraw();
3201 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3202 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3204 skip("Failed to create a 3D device, skipping test.\n");
3205 IDirectDraw_Release(ddraw
);
3206 DestroyWindow(window
);
3210 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
3211 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3213 white
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
3214 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
3215 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
3216 blue
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
3217 viewport
= create_viewport(device
, 0, 0, 640, 480);
3219 viewport_set_background(device
, viewport
, white
);
3220 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3221 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3222 viewport_set_background(device
, viewport
, red
);
3223 hr
= IDirect3DViewport_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3224 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3225 viewport_set_background(device
, viewport
, green
);
3226 hr
= IDirect3DViewport_Clear(viewport
, 0, NULL
, D3DCLEAR_TARGET
);
3227 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3228 viewport_set_background(device
, viewport
, blue
);
3229 hr
= IDirect3DViewport_Clear(viewport
, 1, NULL
, D3DCLEAR_TARGET
);
3230 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3232 color
= get_surface_color(rt
, 320, 240);
3233 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x000000ff, 1)),
3234 "Got unexpected color 0x%08x.\n", color
);
3236 IDirectDrawSurface_Release(rt
);
3237 destroy_viewport(device
, viewport
);
3238 destroy_material(white
);
3239 destroy_material(red
);
3240 destroy_material(green
);
3241 destroy_material(blue
);
3242 IDirect3DDevice_Release(device
);
3243 IDirectDraw_Release(ddraw
);
3244 DestroyWindow(window
);
3253 } activateapp_testdata
;
3255 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
3257 if (message
== WM_ACTIVATEAPP
)
3259 if (activateapp_testdata
.ddraw
)
3262 activateapp_testdata
.received
= FALSE
;
3263 hr
= IDirectDraw_SetCooperativeLevel(activateapp_testdata
.ddraw
,
3264 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
3265 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
3266 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3268 activateapp_testdata
.received
= TRUE
;
3271 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
3274 static void test_coop_level_activateapp(void)
3281 IDirectDrawSurface
*surface
;
3283 ddraw
= create_ddraw();
3284 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3286 wc
.lpfnWndProc
= activateapp_test_proc
;
3287 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
3288 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3290 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3291 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3293 /* Exclusive with window already active. */
3294 SetForegroundWindow(window
);
3295 activateapp_testdata
.received
= FALSE
;
3296 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3297 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3298 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
3299 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3300 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3302 /* Exclusive with window not active. */
3303 SetForegroundWindow(GetDesktopWindow());
3304 activateapp_testdata
.received
= FALSE
;
3305 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3306 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3307 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3308 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3309 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3311 /* Normal with window not active, then exclusive with the same window. */
3312 SetForegroundWindow(GetDesktopWindow());
3313 activateapp_testdata
.received
= FALSE
;
3314 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3315 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3316 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3317 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3318 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3319 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3320 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3321 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3323 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3324 SetForegroundWindow(GetDesktopWindow());
3325 activateapp_testdata
.received
= FALSE
;
3326 activateapp_testdata
.ddraw
= ddraw
;
3327 activateapp_testdata
.window
= window
;
3328 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
3329 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3330 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3331 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3332 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3333 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3335 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3336 * succeeding. Another switch to exclusive and back to normal is needed to release the
3337 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3338 * WM_ACTIVATEAPP messages. */
3339 activateapp_testdata
.ddraw
= NULL
;
3340 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3341 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3342 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3343 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3345 /* Setting DDSCL_NORMAL with recursive invocation. */
3346 SetForegroundWindow(GetDesktopWindow());
3347 activateapp_testdata
.received
= FALSE
;
3348 activateapp_testdata
.ddraw
= ddraw
;
3349 activateapp_testdata
.window
= window
;
3350 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
3351 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3352 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3353 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3355 /* DDraw is in exlusive mode now. */
3356 memset(&ddsd
, 0, sizeof(ddsd
));
3357 ddsd
.dwSize
= sizeof(ddsd
);
3358 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
3359 ddsd
.dwBackBufferCount
= 1;
3360 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
3361 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3362 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3363 IDirectDrawSurface_Release(surface
);
3365 /* Recover again, just to be sure. */
3366 activateapp_testdata
.ddraw
= NULL
;
3367 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3368 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3369 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3370 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3372 DestroyWindow(window
);
3373 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3374 IDirectDraw_Release(ddraw
);
3377 struct format_support_check
3379 const DDPIXELFORMAT
*format
;
3383 static HRESULT WINAPI
test_unsupported_formats_cb(DDSURFACEDESC
*desc
, void *ctx
)
3385 struct format_support_check
*format
= ctx
;
3387 if (!memcmp(format
->format
, &desc
->ddpfPixelFormat
, sizeof(*format
->format
)))
3389 format
->supported
= TRUE
;
3390 return DDENUMRET_CANCEL
;
3393 return DDENUMRET_OK
;
3396 static void test_unsupported_formats(void)
3399 BOOL expect_success
;
3402 IDirect3DDevice
*device
;
3403 IDirectDrawSurface
*surface
;
3406 DWORD expected_caps
;
3417 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
3418 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
3424 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
3425 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3429 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
3431 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3432 0, 0, 640, 480, 0, 0, 0, 0);
3433 ddraw
= create_ddraw();
3434 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3435 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3437 skip("Failed to create a 3D device, skipping test.\n");
3438 IDirectDraw_Release(ddraw
);
3439 DestroyWindow(window
);
3443 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
3445 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
3446 hr
= IDirect3DDevice_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
3447 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
3449 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
3451 memset(&ddsd
, 0, sizeof(ddsd
));
3452 ddsd
.dwSize
= sizeof(ddsd
);
3453 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
3454 ddsd
.ddpfPixelFormat
= formats
[i
].fmt
;
3457 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
3459 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
3460 expect_success
= FALSE
;
3462 expect_success
= TRUE
;
3464 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3465 ok(SUCCEEDED(hr
) == expect_success
,
3466 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
3467 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
3471 memset(&ddsd
, 0, sizeof(ddsd
));
3472 ddsd
.dwSize
= sizeof(ddsd
);
3473 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &ddsd
);
3474 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3476 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
3477 expected_caps
= DDSCAPS_VIDEOMEMORY
;
3478 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
3479 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
3480 else if (check
.supported
)
3481 expected_caps
= DDSCAPS_VIDEOMEMORY
;
3483 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
3485 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
3486 "Expected capability %#x, format %s, input cap %#x.\n",
3487 expected_caps
, formats
[i
].name
, caps
[j
]);
3489 IDirectDrawSurface_Release(surface
);
3493 IDirect3DDevice_Release(device
);
3494 IDirectDraw_Release(ddraw
);
3495 DestroyWindow(window
);
3498 static void test_rt_caps(void)
3500 PALETTEENTRY palette_entries
[256];
3501 IDirectDrawPalette
*palette
;
3502 IDirect3DDevice
*device
;
3510 static const DDPIXELFORMAT p8_fmt
=
3512 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
3513 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
3518 const DDPIXELFORMAT
*pf
;
3521 HRESULT create_device_hr
;
3522 BOOL create_may_fail
;
3528 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
3529 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3535 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
3536 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3542 DDSCAPS_OFFSCREENPLAIN
,
3543 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3549 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3550 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3551 D3DERR_SURFACENOTINVIDMEM
,
3556 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
3557 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
3563 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
3564 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3571 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3578 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3584 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3585 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3586 D3DERR_SURFACENOTINVIDMEM
,
3591 DDSCAPS_SYSTEMMEMORY
,
3592 DDSCAPS_SYSTEMMEMORY
,
3599 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3605 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
3606 ~0U /* AMD r200 */ ,
3607 DDERR_NOPALETTEATTACHED
,
3612 DDSCAPS_OFFSCREENPLAIN
,
3613 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3619 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3620 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3621 DDERR_NOPALETTEATTACHED
,
3626 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
3627 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
3633 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
3634 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
3636 TRUE
/* AMD Evergreen */,
3640 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
3641 ~0U /* AMD Evergreen */,
3648 ~0U /* AMD Evergreen */,
3654 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
3655 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
3657 TRUE
/* Nvidia Kepler */,
3661 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
3662 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
3664 TRUE
/* Nvidia Kepler */,
3668 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3669 0, 0, 640, 480, 0, 0, 0, 0);
3670 ddraw
= create_ddraw();
3671 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3672 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3674 skip("Failed to create a 3D device, skipping test.\n");
3675 IDirectDraw_Release(ddraw
);
3676 DestroyWindow(window
);
3679 z_depth
= get_device_z_depth(device
);
3680 ok(!!z_depth
, "Failed to get device z depth.\n");
3681 IDirect3DDevice_Release(device
);
3683 memset(palette_entries
, 0, sizeof(palette_entries
));
3684 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
3685 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
3687 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
3689 IDirectDrawSurface
*surface
;
3690 DDSURFACEDESC surface_desc
;
3691 IDirect3DDevice
*device
;
3693 memset(&surface_desc
, 0, sizeof(surface_desc
));
3694 surface_desc
.dwSize
= sizeof(surface_desc
);
3695 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3696 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
3697 if (test_data
[i
].pf
)
3699 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
3700 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
3702 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
3704 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
3705 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
3707 surface_desc
.dwWidth
= 640;
3708 surface_desc
.dwHeight
= 480;
3709 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
3710 ok(SUCCEEDED(hr
) || broken(test_data
[i
].create_may_fail
),
3711 "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
3712 i
, test_data
[i
].caps_in
, hr
);
3716 memset(&surface_desc
, 0, sizeof(surface_desc
));
3717 surface_desc
.dwSize
= sizeof(surface_desc
);
3718 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
3719 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
3720 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
3721 "Test %u: Got unexpected caps %#x, expected %#x.\n",
3722 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
3724 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DHALDevice
, (void **)&device
);
3725 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
3726 i
, hr
, test_data
[i
].create_device_hr
);
3727 if (hr
== DDERR_NOPALETTEATTACHED
)
3729 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
3730 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
3731 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DHALDevice
, (void **)&device
);
3732 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
3733 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
3735 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
3739 refcount
= IDirect3DDevice_Release(device
);
3740 ok(refcount
== 1, "Test %u: Got unexpected refcount %u.\n", i
, refcount
);
3743 refcount
= IDirectDrawSurface_Release(surface
);
3744 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
3747 IDirectDrawPalette_Release(palette
);
3748 refcount
= IDirectDraw_Release(ddraw
);
3749 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
3750 DestroyWindow(window
);
3753 static void test_primary_caps(void)
3755 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
3756 IDirectDrawSurface
*surface
;
3757 DDSURFACEDESC surface_desc
;
3768 DWORD back_buffer_count
;
3776 DDSCAPS_PRIMARYSURFACE
,
3779 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
3783 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
3790 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
3793 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
3797 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
3804 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
3811 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
3818 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
3825 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
3832 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
3834 DDERR_NOEXCLUSIVEMODE
,
3838 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
3839 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
3845 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
3846 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
3849 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
3852 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
3853 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
3859 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
3860 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
3867 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3868 0, 0, 640, 480, 0, 0, 0, 0);
3869 ddraw
= create_ddraw();
3870 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3872 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
3874 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
3875 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3877 memset(&surface_desc
, 0, sizeof(surface_desc
));
3878 surface_desc
.dwSize
= sizeof(surface_desc
);
3879 surface_desc
.dwFlags
= DDSD_CAPS
;
3880 if (test_data
[i
].back_buffer_count
!= ~0u)
3881 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
3882 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
3883 surface_desc
.dwBackBufferCount
= test_data
[i
].back_buffer_count
;
3884 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
3885 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
3889 memset(&surface_desc
, 0, sizeof(surface_desc
));
3890 surface_desc
.dwSize
= sizeof(surface_desc
);
3891 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
3892 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
3893 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
3894 "Test %u: Got unexpected caps %#x, expected %#x.\n",
3895 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
3897 IDirectDrawSurface_Release(surface
);
3900 refcount
= IDirectDraw_Release(ddraw
);
3901 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
3902 DestroyWindow(window
);
3905 static void test_surface_lock(void)
3908 IDirectDrawSurface
*surface
;
3909 IDirect3DDevice
*device
;
3924 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
3925 "videomemory offscreenplain"
3928 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
3929 "systemmemory offscreenplain"
3932 DDSCAPS_PRIMARYSURFACE
,
3936 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
3937 "videomemory texture"
3940 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
3941 "systemmemory texture"
3944 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
3953 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3954 0, 0, 640, 480, 0, 0, 0, 0);
3955 ddraw
= create_ddraw();
3956 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3957 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3959 skip("Failed to create a 3D device, skipping test.\n");
3960 IDirectDraw_Release(ddraw
);
3961 DestroyWindow(window
);
3964 z_depth
= get_device_z_depth(device
);
3965 ok(!!z_depth
, "Failed to get device z depth.\n");
3966 IDirect3DDevice_Release(device
);
3968 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
3970 memset(&ddsd
, 0, sizeof(ddsd
));
3971 ddsd
.dwSize
= sizeof(ddsd
);
3972 ddsd
.dwFlags
= DDSD_CAPS
;
3973 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
3975 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
3979 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
3981 ddsd
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
3982 U2(ddsd
).dwZBufferBitDepth
= z_depth
;
3984 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
3986 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3987 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
3989 memset(&ddsd
, 0, sizeof(ddsd
));
3990 ddsd
.dwSize
= sizeof(ddsd
);
3991 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
3992 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
3995 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
3996 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
3999 IDirectDrawSurface_Release(surface
);
4002 refcount
= IDirectDraw_Release(ddraw
);
4003 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4004 DestroyWindow(window
);
4007 static void test_surface_discard(void)
4010 IDirect3DDevice
*device
;
4014 IDirectDrawSurface
*surface
, *target
;
4023 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4024 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4025 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4026 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4030 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4031 0, 0, 640, 480, 0, 0, 0, 0);
4032 ddraw
= create_ddraw();
4033 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4034 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4036 skip("Failed to create a 3D device, skipping test.\n");
4037 IDirectDraw_Release(ddraw
);
4038 DestroyWindow(window
);
4042 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&target
);
4043 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4045 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4049 memset(&ddsd
, 0, sizeof(ddsd
));
4050 ddsd
.dwSize
= sizeof(ddsd
);
4051 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4052 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4055 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4058 skip("Failed to create surface, skipping.\n");
4062 memset(&ddsd
, 0, sizeof(ddsd
));
4063 ddsd
.dwSize
= sizeof(ddsd
);
4064 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4065 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4066 addr
= ddsd
.lpSurface
;
4067 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4068 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4070 memset(&ddsd
, 0, sizeof(ddsd
));
4071 ddsd
.dwSize
= sizeof(ddsd
);
4072 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4073 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4074 discarded
= ddsd
.lpSurface
!= addr
;
4075 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4076 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4078 hr
= IDirectDrawSurface_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
4079 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
4081 memset(&ddsd
, 0, sizeof(ddsd
));
4082 ddsd
.dwSize
= sizeof(ddsd
);
4083 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4084 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4085 discarded
|= ddsd
.lpSurface
!= addr
;
4086 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4087 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4089 IDirectDrawSurface_Release(surface
);
4091 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4092 * AMD r500, evergreen). Windows XP, at least on AMD r200, never changes the pointer. */
4093 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
4096 IDirectDrawSurface_Release(target
);
4097 IDirect3DDevice_Release(device
);
4098 IDirectDraw_Release(ddraw
);
4099 DestroyWindow(window
);
4102 static void test_flip(void)
4104 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4105 IDirectDrawSurface
*primary
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
4106 DDSCAPS caps
= {DDSCAPS_FLIP
};
4107 DDSURFACEDESC surface_desc
;
4108 BOOL sysmem_primary
;
4116 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4117 0, 0, 640, 480, 0, 0, 0, 0);
4118 ddraw
= create_ddraw();
4119 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4121 hr
= set_display_mode(ddraw
, 640, 480);
4122 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
4123 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4124 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4126 memset(&surface_desc
, 0, sizeof(surface_desc
));
4127 surface_desc
.dwSize
= sizeof(surface_desc
);
4128 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4129 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4130 surface_desc
.dwBackBufferCount
= 3;
4131 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
4132 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4134 memset(&surface_desc
, 0, sizeof(surface_desc
));
4135 surface_desc
.dwSize
= sizeof(surface_desc
);
4136 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
4137 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4138 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
)
4139 == (DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
4140 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
4141 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
4143 hr
= IDirectDrawSurface_GetAttachedSurface(primary
, &caps
, &backbuffer1
);
4144 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4145 memset(&surface_desc
, 0, sizeof(surface_desc
));
4146 surface_desc
.dwSize
= sizeof(surface_desc
);
4147 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer1
, &surface_desc
);
4148 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4149 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
4150 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
| DDSCAPS_BACKBUFFER
),
4151 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
4153 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
4154 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4155 memset(&surface_desc
, 0, sizeof(surface_desc
));
4156 surface_desc
.dwSize
= sizeof(surface_desc
);
4157 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer2
, &surface_desc
);
4158 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4159 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
4160 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
4161 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
4163 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
4164 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4165 memset(&surface_desc
, 0, sizeof(surface_desc
));
4166 surface_desc
.dwSize
= sizeof(surface_desc
);
4167 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer3
, &surface_desc
);
4168 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4169 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
4170 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
4171 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
4173 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
4174 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4175 ok(surface
== primary
, "Got unexpected surface %p, expected %p.\n", surface
, primary
);
4176 IDirectDrawSurface_Release(surface
);
4178 memset(&surface_desc
, 0, sizeof(surface_desc
));
4179 surface_desc
.dwSize
= sizeof(surface_desc
);
4180 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4181 surface_desc
.ddsCaps
.dwCaps
= 0;
4182 surface_desc
.dwWidth
= 640;
4183 surface_desc
.dwHeight
= 480;
4184 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4185 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4186 hr
= IDirectDrawSurface_Flip(primary
, surface
, DDFLIP_WAIT
);
4187 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
4188 IDirectDrawSurface_Release(surface
);
4190 hr
= IDirectDrawSurface_Flip(primary
, primary
, DDFLIP_WAIT
);
4191 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
4192 hr
= IDirectDrawSurface_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
4193 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
4194 hr
= IDirectDrawSurface_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
4195 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
4196 hr
= IDirectDrawSurface_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
4197 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
4199 memset(&fx
, 0, sizeof(fx
));
4200 fx
.dwSize
= sizeof(fx
);
4201 U5(fx
).dwFillColor
= 0xffff0000;
4202 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4203 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4204 U5(fx
).dwFillColor
= 0xff00ff00;
4205 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4206 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4207 U5(fx
).dwFillColor
= 0xff0000ff;
4208 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4209 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4211 hr
= IDirectDrawSurface_Flip(primary
, NULL
, DDFLIP_WAIT
);
4212 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4213 color
= get_surface_color(backbuffer1
, 320, 240);
4214 /* The testbot seems to just copy the contents of one surface to all the
4215 * others, instead of properly flipping. */
4216 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
4217 "Got unexpected color 0x%08x.\n", color
);
4218 color
= get_surface_color(backbuffer2
, 320, 240);
4219 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
4220 U5(fx
).dwFillColor
= 0xffff0000;
4221 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4222 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4224 hr
= IDirectDrawSurface_Flip(primary
, NULL
, DDFLIP_WAIT
);
4225 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4226 color
= get_surface_color(backbuffer1
, 320, 240);
4227 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
4228 "Got unexpected color 0x%08x.\n", color
);
4229 color
= get_surface_color(backbuffer2
, 320, 240);
4230 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
4231 U5(fx
).dwFillColor
= 0xff00ff00;
4232 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4233 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4235 hr
= IDirectDrawSurface_Flip(primary
, NULL
, DDFLIP_WAIT
);
4236 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4237 color
= get_surface_color(backbuffer1
, 320, 240);
4238 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
4239 "Got unexpected color 0x%08x.\n", color
);
4240 color
= get_surface_color(backbuffer2
, 320, 240);
4241 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
4242 U5(fx
).dwFillColor
= 0xff0000ff;
4243 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4244 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4246 hr
= IDirectDrawSurface_Flip(primary
, backbuffer1
, DDFLIP_WAIT
);
4247 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4248 color
= get_surface_color(backbuffer2
, 320, 240);
4249 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
4250 "Got unexpected color 0x%08x.\n", color
);
4251 color
= get_surface_color(backbuffer3
, 320, 240);
4252 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
4253 U5(fx
).dwFillColor
= 0xffff0000;
4254 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4255 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4257 hr
= IDirectDrawSurface_Flip(primary
, backbuffer2
, DDFLIP_WAIT
);
4258 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4259 color
= get_surface_color(backbuffer1
, 320, 240);
4260 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
4261 color
= get_surface_color(backbuffer3
, 320, 240);
4262 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
4263 "Got unexpected color 0x%08x.\n", color
);
4264 U5(fx
).dwFillColor
= 0xff00ff00;
4265 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4266 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4268 hr
= IDirectDrawSurface_Flip(primary
, backbuffer3
, DDFLIP_WAIT
);
4269 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4270 color
= get_surface_color(backbuffer1
, 320, 240);
4271 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
4272 "Got unexpected color 0x%08x.\n", color
);
4273 color
= get_surface_color(backbuffer2
, 320, 240);
4274 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
4276 IDirectDrawSurface_Release(backbuffer3
);
4277 IDirectDrawSurface_Release(backbuffer2
);
4278 IDirectDrawSurface_Release(backbuffer1
);
4279 IDirectDrawSurface_Release(primary
);
4280 refcount
= IDirectDraw_Release(ddraw
);
4281 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4282 DestroyWindow(window
);
4285 static void test_sysmem_overlay(void)
4291 IDirectDrawSurface
*surface
;
4294 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4295 0, 0, 640, 480, 0, 0, 0, 0);
4296 ddraw
= create_ddraw();
4297 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4299 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4300 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4302 memset(&ddsd
, 0, sizeof(ddsd
));
4303 ddsd
.dwSize
= sizeof(ddsd
);
4304 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
4307 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
4308 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
4309 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
4310 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
4311 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
4312 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
4313 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
4314 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4315 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
4317 ref
= IDirectDraw_Release(ddraw
);
4318 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
4319 DestroyWindow(window
);
4322 static void test_primary_palette(void)
4324 DDSCAPS surface_caps
= {DDSCAPS_FLIP
};
4325 IDirectDrawSurface
*primary
, *backbuffer
;
4326 PALETTEENTRY palette_entries
[256];
4327 IDirectDrawPalette
*palette
, *tmp
;
4328 DDSURFACEDESC surface_desc
;
4335 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4336 0, 0, 640, 480, 0, 0, 0, 0);
4337 ddraw
= create_ddraw();
4338 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4339 if (FAILED(IDirectDraw_SetDisplayMode(ddraw
, 640, 480, 8)))
4341 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
4342 IDirectDraw_Release(ddraw
);
4343 DestroyWindow(window
);
4346 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4347 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4349 memset(&surface_desc
, 0, sizeof(surface_desc
));
4350 surface_desc
.dwSize
= sizeof(surface_desc
);
4351 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4352 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4353 surface_desc
.dwBackBufferCount
= 1;
4354 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
4355 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4356 hr
= IDirectDrawSurface_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
4357 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4359 memset(palette_entries
, 0, sizeof(palette_entries
));
4360 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
4361 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
4362 refcount
= get_refcount((IUnknown
*)palette
);
4363 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
4365 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
4366 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
4367 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
4369 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
4370 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
4372 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
4373 * and is generally somewhat broken with respect to 8 bpp / palette
4375 if (SUCCEEDED(IDirectDrawSurface_GetPalette(backbuffer
, &tmp
)))
4377 win_skip("Broken palette handling detected, skipping tests.\n");
4378 IDirectDrawPalette_Release(tmp
);
4379 IDirectDrawPalette_Release(palette
);
4380 /* The Windows 8 testbot keeps extra references to the primary and
4381 * backbuffer while in 8 bpp mode. */
4382 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
4383 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
4387 refcount
= get_refcount((IUnknown
*)palette
);
4388 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
4390 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
4391 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
4392 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
4393 "Got unexpected palette caps %#x.\n", palette_caps
);
4395 hr
= IDirectDrawSurface_SetPalette(primary
, NULL
);
4396 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
4397 refcount
= get_refcount((IUnknown
*)palette
);
4398 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
4400 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
4401 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
4402 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
4404 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
4405 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
4406 refcount
= get_refcount((IUnknown
*)palette
);
4407 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
4409 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
4410 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
4411 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
4412 IDirectDrawPalette_Release(tmp
);
4413 hr
= IDirectDrawSurface_GetPalette(backbuffer
, &tmp
);
4414 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
4416 refcount
= IDirectDrawPalette_Release(palette
);
4417 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
4418 refcount
= IDirectDrawPalette_Release(palette
);
4419 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4421 /* Note that this only seems to work when the palette is attached to the
4422 * primary surface. When attached to a regular surface, attempting to get
4423 * the palette here will cause an access violation. */
4424 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
4425 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
4428 refcount
= IDirectDrawSurface_Release(backbuffer
);
4429 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
4430 refcount
= IDirectDrawSurface_Release(primary
);
4431 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4432 refcount
= IDirectDraw_Release(ddraw
);
4433 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4434 DestroyWindow(window
);
4437 static HRESULT WINAPI
surface_counter(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
4439 UINT
*surface_count
= context
;
4442 IDirectDrawSurface_Release(surface
);
4444 return DDENUMRET_OK
;
4447 static void test_surface_attachment(void)
4449 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
4450 DDSCAPS caps
= {DDSCAPS_TEXTURE
};
4451 DDSURFACEDESC surface_desc
;
4458 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4459 0, 0, 640, 480, 0, 0, 0, 0);
4460 ddraw
= create_ddraw();
4461 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4462 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4463 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4465 memset(&surface_desc
, 0, sizeof(surface_desc
));
4466 surface_desc
.dwSize
= sizeof(surface_desc
);
4467 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
4468 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
4469 U2(surface_desc
).dwMipMapCount
= 3;
4470 surface_desc
.dwWidth
= 128;
4471 surface_desc
.dwHeight
= 128;
4472 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
4473 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4475 hr
= IDirectDrawSurface_GetAttachedSurface(surface1
, &caps
, &surface2
);
4476 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
4477 hr
= IDirectDrawSurface_GetAttachedSurface(surface2
, &caps
, &surface3
);
4478 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
4479 hr
= IDirectDrawSurface_GetAttachedSurface(surface3
, &caps
, &surface4
);
4480 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
4483 IDirectDrawSurface_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
4484 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
4486 IDirectDrawSurface_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
4487 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
4489 IDirectDrawSurface_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
4490 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
4492 memset(&surface_desc
, 0, sizeof(surface_desc
));
4493 surface_desc
.dwSize
= sizeof(surface_desc
);
4494 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4495 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
4496 surface_desc
.dwWidth
= 16;
4497 surface_desc
.dwHeight
= 16;
4498 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
4499 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4501 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
4502 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4503 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
4504 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4505 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
4506 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4507 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
4508 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4509 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
4510 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4511 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
4512 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4514 IDirectDrawSurface_Release(surface4
);
4516 memset(&surface_desc
, 0, sizeof(surface_desc
));
4517 surface_desc
.dwSize
= sizeof(surface_desc
);
4518 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4519 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
4520 surface_desc
.dwWidth
= 16;
4521 surface_desc
.dwHeight
= 16;
4522 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
4523 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4525 if (SUCCEEDED(hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
)))
4527 skip("Running on refrast, skipping some tests.\n");
4528 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface4
);
4529 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4533 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4534 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
4535 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4536 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
4537 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4538 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
4539 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4540 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
4541 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4542 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
4543 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4546 IDirectDrawSurface_Release(surface4
);
4547 IDirectDrawSurface_Release(surface3
);
4548 IDirectDrawSurface_Release(surface2
);
4549 IDirectDrawSurface_Release(surface1
);
4551 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4552 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4554 /* Try a single primary and two offscreen plain surfaces. */
4555 memset(&surface_desc
, 0, sizeof(surface_desc
));
4556 surface_desc
.dwSize
= sizeof(surface_desc
);
4557 surface_desc
.dwFlags
= DDSD_CAPS
;
4558 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
4559 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
4560 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4562 memset(&surface_desc
, 0, sizeof(surface_desc
));
4563 surface_desc
.dwSize
= sizeof(surface_desc
);
4564 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4565 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4566 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
4567 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
4568 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
4569 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4571 memset(&surface_desc
, 0, sizeof(surface_desc
));
4572 surface_desc
.dwSize
= sizeof(surface_desc
);
4573 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4574 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4575 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
4576 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
4577 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
4578 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4580 /* This one has a different size. */
4581 memset(&surface_desc
, 0, sizeof(surface_desc
));
4582 surface_desc
.dwSize
= sizeof(surface_desc
);
4583 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4584 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4585 surface_desc
.dwWidth
= 128;
4586 surface_desc
.dwHeight
= 128;
4587 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
4588 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4590 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
4591 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4592 /* Try the reverse without detaching first. */
4593 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
4594 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
4595 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
4596 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4598 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
4599 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4600 /* Try to detach reversed. */
4601 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
4602 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4603 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
4604 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4606 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
);
4607 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4608 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
4609 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4611 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
4612 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4613 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
4614 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4616 IDirectDrawSurface_Release(surface4
);
4617 IDirectDrawSurface_Release(surface3
);
4618 IDirectDrawSurface_Release(surface2
);
4619 IDirectDrawSurface_Release(surface1
);
4621 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
4622 memset(&surface_desc
, 0, sizeof(surface_desc
));
4623 surface_desc
.dwSize
= sizeof(surface_desc
);
4624 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
4625 surface_desc
.dwWidth
= 64;
4626 surface_desc
.dwHeight
= 64;
4627 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
4628 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
4629 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
4630 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
4631 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
4632 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
4633 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
4634 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
4635 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4636 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
4637 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4639 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
4640 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
4641 U1(surface_desc
.ddpfPixelFormat
).dwZBufferBitDepth
= 16;
4642 U3(surface_desc
.ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
4643 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
4644 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4646 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
4647 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4648 refcount
= get_refcount((IUnknown
*)surface2
);
4649 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
4650 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
4651 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
4653 /* Attaching while already attached to other surface. */
4654 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface2
);
4655 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4656 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface3
, 0, surface2
);
4657 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4658 IDirectDrawSurface_Release(surface3
);
4660 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
4661 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4662 refcount
= get_refcount((IUnknown
*)surface2
);
4663 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
4665 /* Automatic detachment on release. */
4666 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
4667 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4668 refcount
= get_refcount((IUnknown
*)surface2
);
4669 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
4670 refcount
= IDirectDrawSurface_Release(surface1
);
4671 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4672 refcount
= IDirectDrawSurface_Release(surface2
);
4673 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4674 refcount
= IDirectDraw_Release(ddraw
);
4675 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4676 DestroyWindow(window
);
4679 static void test_pixel_format(void)
4681 HWND window
, window2
= NULL
;
4682 HDC hdc
, hdc2
= NULL
;
4684 int format
, test_format
;
4685 PIXELFORMATDESCRIPTOR pfd
;
4686 IDirectDraw
*ddraw
= NULL
;
4687 IDirectDrawClipper
*clipper
= NULL
;
4689 IDirectDrawSurface
*primary
= NULL
;
4693 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
4694 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
4697 skip("Failed to create window\n");
4701 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
4702 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
4704 hdc
= GetDC(window
);
4707 skip("Failed to get DC\n");
4712 hdc2
= GetDC(window2
);
4714 gl
= LoadLibraryA("opengl32.dll");
4715 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
4717 format
= GetPixelFormat(hdc
);
4718 ok(format
== 0, "new window has pixel format %d\n", format
);
4720 ZeroMemory(&pfd
, sizeof(pfd
));
4721 pfd
.nSize
= sizeof(pfd
);
4723 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
4724 pfd
.iPixelType
= PFD_TYPE_RGBA
;
4725 pfd
.iLayerType
= PFD_MAIN_PLANE
;
4726 format
= ChoosePixelFormat(hdc
, &pfd
);
4729 skip("no pixel format available\n");
4733 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
4735 skip("failed to set pixel format\n");
4739 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
4741 skip("failed to set pixel format on second window\n");
4744 ReleaseDC(window2
, hdc2
);
4749 ddraw
= create_ddraw();
4750 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4752 test_format
= GetPixelFormat(hdc
);
4753 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4755 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4758 skip("Failed to set cooperative level, hr %#x.\n", hr
);
4762 test_format
= GetPixelFormat(hdc
);
4763 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4767 hr
= IDirectDraw_CreateClipper(ddraw
, 0, &clipper
, NULL
);
4768 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
4769 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
4770 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
4772 test_format
= GetPixelFormat(hdc
);
4773 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4775 test_format
= GetPixelFormat(hdc2
);
4776 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
4779 memset(&ddsd
, 0, sizeof(ddsd
));
4780 ddsd
.dwSize
= sizeof(ddsd
);
4781 ddsd
.dwFlags
= DDSD_CAPS
;
4782 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
4784 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
4785 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
4787 test_format
= GetPixelFormat(hdc
);
4788 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4792 test_format
= GetPixelFormat(hdc2
);
4793 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
4798 hr
= IDirectDrawSurface_SetClipper(primary
, clipper
);
4799 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
4801 test_format
= GetPixelFormat(hdc
);
4802 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4804 test_format
= GetPixelFormat(hdc2
);
4805 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
4808 memset(&fx
, 0, sizeof(fx
));
4809 fx
.dwSize
= sizeof(fx
);
4810 hr
= IDirectDrawSurface_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4811 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
4813 test_format
= GetPixelFormat(hdc
);
4814 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4818 test_format
= GetPixelFormat(hdc2
);
4819 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
4823 if (primary
) IDirectDrawSurface_Release(primary
);
4824 if (clipper
) IDirectDrawClipper_Release(clipper
);
4825 if (ddraw
) IDirectDraw_Release(ddraw
);
4826 if (gl
) FreeLibrary(gl
);
4827 if (hdc
) ReleaseDC(window
, hdc
);
4828 if (hdc2
) ReleaseDC(window2
, hdc2
);
4829 if (window
) DestroyWindow(window
);
4830 if (window2
) DestroyWindow(window2
);
4833 static void test_create_surface_pitch(void)
4835 IDirectDrawSurface
*surface
;
4836 DDSURFACEDESC surface_desc
;
4856 {DDSCAPS_VIDEOMEMORY
, 0, 0, DD_OK
,
4857 DDSD_PITCH
, 0x100, 0x100},
4858 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
4859 DDSD_PITCH
, 0x100, 0x100},
4860 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
4861 DDSD_PITCH
, 0x100, 0x100},
4862 {DDSCAPS_VIDEOMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
4864 {DDSCAPS_SYSTEMMEMORY
, 0, 0, DD_OK
,
4865 DDSD_PITCH
, 0x100, 0x0fc},
4866 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
4867 DDSD_PITCH
, 0x100, 0x0fc},
4868 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
4869 DDSD_PITCH
, 0x100, 0x0fc},
4870 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
4871 DDSD_PITCH
, 0x100, 0x0fc},
4872 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
4874 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
4877 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
4879 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4880 0, 0, 640, 480, 0, 0, 0, 0);
4881 ddraw
= create_ddraw();
4882 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4883 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4884 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4886 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
4888 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4890 memset(&surface_desc
, 0, sizeof(surface_desc
));
4891 surface_desc
.dwSize
= sizeof(surface_desc
);
4892 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
4893 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| test_data
[i
].placement
;
4894 surface_desc
.dwWidth
= 63;
4895 surface_desc
.dwHeight
= 63;
4896 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
4897 surface_desc
.lpSurface
= mem
;
4898 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
4899 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
4900 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
4901 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
4902 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
4903 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
4904 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4905 ok(hr
== test_data
[i
].hr
|| (test_data
[i
].placement
== DDSCAPS_VIDEOMEMORY
&& hr
== DDERR_NODIRECTDRAWHW
),
4906 "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
4910 memset(&surface_desc
, 0, sizeof(surface_desc
));
4911 surface_desc
.dwSize
= sizeof(surface_desc
);
4912 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4913 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4914 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
4915 "Test %u: Got unexpected flags %#x, expected %#x.\n",
4916 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
4917 if (sizeof(void *) != sizeof(DWORD
) && test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
4918 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
4919 "Test %u: Got unexpected pitch %u, expected %u.\n",
4920 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
4922 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
4923 "Test %u: Got unexpected pitch %u, expected %u.\n",
4924 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
4925 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
4927 IDirectDrawSurface_Release(surface
);
4930 HeapFree(GetProcessHeap(), 0, mem
);
4931 refcount
= IDirectDraw_Release(ddraw
);
4932 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4933 DestroyWindow(window
);
4936 static void test_mipmap_lock(void)
4938 IDirectDrawSurface
*surface
, *surface2
;
4939 DDSURFACEDESC surface_desc
;
4944 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
4947 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4948 0, 0, 640, 480, 0, 0, 0, 0);
4949 ddraw
= create_ddraw();
4950 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4951 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4952 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4954 memset(&hal_caps
, 0, sizeof(hal_caps
));
4955 hal_caps
.dwSize
= sizeof(hal_caps
);
4956 hr
= IDirectDraw_GetCaps(ddraw
, &hal_caps
, NULL
);
4957 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4958 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
4960 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
4961 IDirectDraw_Release(ddraw
);
4962 DestroyWindow(window
);
4966 memset(&surface_desc
, 0, sizeof(surface_desc
));
4967 surface_desc
.dwSize
= sizeof(surface_desc
);
4968 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
4969 surface_desc
.dwWidth
= 4;
4970 surface_desc
.dwHeight
= 4;
4971 U2(surface_desc
).dwMipMapCount
= 2;
4972 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
4973 | DDSCAPS_SYSTEMMEMORY
;
4974 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4975 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4976 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &surface2
);
4977 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4979 memset(&surface_desc
, 0, sizeof(surface_desc
));
4980 surface_desc
.dwSize
= sizeof(surface_desc
);
4981 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
4982 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4983 memset(&surface_desc
, 0, sizeof(surface_desc
));
4984 surface_desc
.dwSize
= sizeof(surface_desc
);
4985 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
4986 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4987 IDirectDrawSurface_Unlock(surface2
, NULL
);
4988 IDirectDrawSurface_Unlock(surface
, NULL
);
4990 IDirectDrawSurface_Release(surface2
);
4991 IDirectDrawSurface_Release(surface
);
4992 refcount
= IDirectDraw_Release(ddraw
);
4993 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4994 DestroyWindow(window
);
4997 static void test_palette_complex(void)
4999 IDirectDrawSurface
*surface
, *mipmap
, *tmp
;
5000 DDSURFACEDESC surface_desc
;
5002 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
5006 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
5008 PALETTEENTRY palette_entries
[256];
5014 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5015 0, 0, 640, 480, 0, 0, 0, 0);
5016 ddraw
= create_ddraw();
5017 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5018 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5019 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5021 memset(&hal_caps
, 0, sizeof(hal_caps
));
5022 hal_caps
.dwSize
= sizeof(hal_caps
);
5023 hr
= IDirectDraw_GetCaps(ddraw
, &hal_caps
, NULL
);
5024 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5025 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
5027 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
5028 IDirectDraw_Release(ddraw
);
5029 DestroyWindow(window
);
5033 memset(&surface_desc
, 0, sizeof(surface_desc
));
5034 surface_desc
.dwSize
= sizeof(surface_desc
);
5035 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5036 surface_desc
.dwWidth
= 128;
5037 surface_desc
.dwHeight
= 128;
5038 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
5039 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5040 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
5041 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
5042 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5043 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5045 memset(palette_entries
, 0, sizeof(palette_entries
));
5046 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
5047 palette_entries
, &palette
, NULL
);
5048 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5050 memset(palette_entries
, 0, sizeof(palette_entries
));
5051 palette_entries
[1].peRed
= 0xff;
5052 palette_entries
[1].peGreen
= 0x80;
5053 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
5054 palette_entries
, &palette_mipmap
, NULL
);
5055 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5057 palette2
= (void *)0xdeadbeef;
5058 hr
= IDirectDrawSurface_GetPalette(surface
, &palette2
);
5059 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5060 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
5061 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
5062 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5063 hr
= IDirectDrawSurface_GetPalette(surface
, &palette2
);
5064 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
5065 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
5066 IDirectDrawPalette_Release(palette2
);
5069 IDirectDrawSurface_AddRef(mipmap
);
5070 for (i
= 0; i
< 7; ++i
)
5072 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
5073 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
5074 palette2
= (void *)0xdeadbeef;
5075 hr
= IDirectDrawSurface_GetPalette(tmp
, &palette2
);
5076 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
5077 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
5079 hr
= IDirectDrawSurface_SetPalette(tmp
, palette_mipmap
);
5080 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
5082 hr
= IDirectDrawSurface_GetPalette(tmp
, &palette2
);
5083 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
5084 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
5085 IDirectDrawPalette_Release(palette2
);
5087 hr
= IDirectDrawSurface_GetDC(tmp
, &dc
);
5088 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
5089 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
5090 ok(count
== 1, "Expected count 1, got %u.\n", count
);
5091 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
5092 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
5093 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
5094 hr
= IDirectDrawSurface_ReleaseDC(tmp
, dc
);
5095 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
5097 IDirectDrawSurface_Release(mipmap
);
5101 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
5102 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5103 IDirectDrawSurface_Release(mipmap
);
5104 refcount
= IDirectDrawSurface_Release(surface
);
5105 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5106 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
5107 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5108 refcount
= IDirectDrawPalette_Release(palette
);
5109 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5111 refcount
= IDirectDraw_Release(ddraw
);
5112 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5113 DestroyWindow(window
);
5116 static void test_p8_rgb_blit(void)
5118 IDirectDrawSurface
*src
, *dst
;
5119 DDSURFACEDESC surface_desc
;
5121 IDirectDrawPalette
*palette
;
5125 PALETTEENTRY palette_entries
[256];
5127 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
5128 static const D3DCOLOR expected
[] =
5130 0x00101010, 0x00010101, 0x00020202, 0x00030303,
5131 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
5135 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5136 0, 0, 640, 480, 0, 0, 0, 0);
5137 ddraw
= create_ddraw();
5138 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5139 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5140 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5142 memset(palette_entries
, 0, sizeof(palette_entries
));
5143 palette_entries
[1].peGreen
= 0xff;
5144 palette_entries
[2].peBlue
= 0xff;
5145 palette_entries
[3].peFlags
= 0xff;
5146 palette_entries
[4].peRed
= 0xff;
5147 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
5148 palette_entries
, &palette
, NULL
);
5149 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5151 memset(&surface_desc
, 0, sizeof(surface_desc
));
5152 surface_desc
.dwSize
= sizeof(surface_desc
);
5153 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5154 surface_desc
.dwWidth
= 8;
5155 surface_desc
.dwHeight
= 1;
5156 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5157 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5158 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
5159 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
5160 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
5161 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5163 memset(&surface_desc
, 0, sizeof(surface_desc
));
5164 surface_desc
.dwSize
= sizeof(surface_desc
);
5165 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5166 surface_desc
.dwWidth
= 8;
5167 surface_desc
.dwHeight
= 1;
5168 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5169 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5170 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
5171 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5172 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5173 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5174 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5175 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
5176 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
5177 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5179 memset(&surface_desc
, 0, sizeof(surface_desc
));
5180 surface_desc
.dwSize
= sizeof(surface_desc
);
5181 hr
= IDirectDrawSurface_Lock(src
, NULL
, &surface_desc
, 0, NULL
);
5182 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
5183 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
5184 hr
= IDirectDrawSurface_Unlock(src
, NULL
);
5185 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
5187 hr
= IDirectDrawSurface_SetPalette(src
, palette
);
5188 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5189 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
5190 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
5191 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
5192 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
5193 "Failed to blit, hr %#x.\n", hr
);
5197 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
5199 color
= get_surface_color(dst
, x
, 0);
5200 todo_wine
ok(compare_color(color
, expected
[x
], 0),
5201 "Pixel %u: Got color %#x, expected %#x.\n",
5202 x
, color
, expected
[x
]);
5206 IDirectDrawSurface_Release(src
);
5207 IDirectDrawSurface_Release(dst
);
5208 IDirectDrawPalette_Release(palette
);
5210 refcount
= IDirectDraw_Release(ddraw
);
5211 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5212 DestroyWindow(window
);
5215 static void test_material(void)
5217 IDirect3DMaterial
*background
, *material
;
5218 IDirect3DExecuteBuffer
*execute_buffer
;
5219 D3DMATERIALHANDLE mat_handle
, tmp
;
5220 D3DEXECUTEBUFFERDESC exec_desc
;
5221 IDirect3DViewport
*viewport
;
5222 IDirect3DDevice
*device
;
5223 IDirectDrawSurface
*rt
;
5234 static D3DVERTEX quad
[] =
5236 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5237 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5238 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5239 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5244 D3DCOLOR expected_color
;
5249 {FALSE
, 0x00ffffff},
5251 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
5253 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5254 0, 0, 640, 480, 0, 0, 0, 0);
5255 ddraw
= create_ddraw();
5256 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5257 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
5259 skip("Failed to create a 3D device, skipping test.\n");
5260 DestroyWindow(window
);
5264 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
5265 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
5267 background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
5268 viewport
= create_viewport(device
, 0, 0, 640, 480);
5269 viewport_set_background(device
, viewport
, background
);
5271 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
5272 hr
= IDirect3DMaterial_GetHandle(material
, device
, &mat_handle
);
5273 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
5275 memset(&exec_desc
, 0, sizeof(exec_desc
));
5276 exec_desc
.dwSize
= sizeof(exec_desc
);
5277 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
5278 exec_desc
.dwBufferSize
= 1024;
5279 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
5281 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
5282 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
5284 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5286 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5287 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5289 memcpy(exec_desc
.lpData
, quad
, sizeof(quad
));
5290 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(quad
);
5291 emit_set_ls(&ptr
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
5292 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORMLIGHT
, 0, 4);
5293 emit_tquad(&ptr
, 0);
5295 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5296 inst_length
-= sizeof(quad
);
5298 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5299 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5301 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
5302 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5304 hr
= IDirect3DDevice_BeginScene(device
);
5305 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5306 set_execute_data(execute_buffer
, 4, sizeof(quad
), inst_length
);
5307 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5308 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5309 hr
= IDirect3DDevice_EndScene(device
);
5310 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5311 color
= get_surface_color(rt
, 320, 240);
5312 if (test_data
[i
].material
)
5313 todo_wine
ok(compare_color(color
, test_data
[i
].expected_color
, 1)
5314 /* The Windows 8 testbot appears to return undefined results. */
5316 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
5318 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
5319 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
5322 destroy_material(material
);
5323 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
5324 hr
= IDirect3DMaterial_GetHandle(material
, device
, &mat_handle
);
5325 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
5327 hr
= IDirect3DViewport_SetBackground(viewport
, mat_handle
);
5328 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
5329 hr
= IDirect3DViewport_GetBackground(viewport
, &tmp
, &valid
);
5330 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
5331 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
5332 ok(valid
, "Got unexpected valid %#x.\n", valid
);
5333 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
5334 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5335 color
= get_surface_color(rt
, 320, 240);
5336 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
5338 hr
= IDirect3DViewport_SetBackground(viewport
, 0);
5339 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
5340 hr
= IDirect3DViewport_GetBackground(viewport
, &tmp
, &valid
);
5341 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
5342 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
5343 ok(valid
, "Got unexpected valid %#x.\n", valid
);
5344 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
5345 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5346 color
= get_surface_color(rt
, 320, 240);
5347 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
5349 destroy_viewport(device
, viewport
);
5350 viewport
= create_viewport(device
, 0, 0, 640, 480);
5352 hr
= IDirect3DViewport_GetBackground(viewport
, &tmp
, &valid
);
5353 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
5354 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
5355 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
5356 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
5357 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5358 color
= get_surface_color(rt
, 320, 240);
5359 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
5361 IDirect3DExecuteBuffer_Release(execute_buffer
);
5362 destroy_viewport(device
, viewport
);
5363 destroy_material(background
);
5364 destroy_material(material
);
5365 IDirectDrawSurface_Release(rt
);
5366 refcount
= IDirect3DDevice_Release(device
);
5367 ok(!refcount
, "Device has %u references left.\n", refcount
);
5368 refcount
= IDirectDraw_Release(ddraw
);
5369 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
5370 DestroyWindow(window
);
5373 static void test_lighting(void)
5375 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
5376 static D3DMATRIX mat
=
5378 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5379 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5380 0.0f
, 0.0f
, 1.0f
, 0.0f
,
5381 0.0f
, 0.0f
, 0.0f
, 1.0f
,
5385 1.0f
, 0.0f
, 1.0f
, 0.0f
,
5386 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5387 1.0f
, 0.0f
, 1.0f
, 0.0f
,
5388 0.0f
, 0.0f
, 0.5f
, 1.0f
,
5392 0.0f
, 0.0f
, 1.0f
, 0.0f
,
5393 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5394 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
5395 10.f
, 10.0f
, 10.0f
, 1.0f
,
5399 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5400 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5401 0.0f
, 0.0f
, 1.0f
, -1.0f
,
5402 10.f
, 10.0f
, 10.0f
, 0.0f
,
5404 static D3DLVERTEX unlitquad
[] =
5406 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
5407 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
5408 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
5409 {{ 0.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
5413 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
5414 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
5415 {{ 0.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
5416 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
5418 static D3DVERTEX unlitnquad
[] =
5420 {{0.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5421 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5422 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5423 {{1.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5427 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5428 {{0.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5429 {{1.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5430 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5434 {{-1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5435 {{-1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5436 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5437 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5441 {{-10.0f
}, {-11.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
5442 {{-10.0f
}, { -9.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
5443 {{-10.0f
}, { -9.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
5444 {{-10.0f
}, {-11.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
5448 {{-11.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5449 {{-11.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5450 {{ -9.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5451 {{ -9.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5455 D3DMATRIX
*world_matrix
;
5458 const char *message
;
5462 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
5463 {&mat_singular
, nquad
, 0x000000b4, "Lit quad with singular world matrix"},
5464 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
5465 {&mat_nonaffine
, translatedquad
, 0x000000ff, "Lit quad with non-affine matrix"},
5470 IDirect3DDevice
*device
;
5472 IDirectDrawSurface
*rt
;
5473 IDirect3DViewport
*viewport
;
5474 IDirect3DMaterial
*material
;
5475 IDirect3DLight
*light
;
5476 IDirect3DExecuteBuffer
*execute_buffer
;
5477 D3DEXECUTEBUFFERDESC exec_desc
;
5478 D3DMATERIALHANDLE mat_handle
;
5479 D3DMATRIXHANDLE world_handle
, view_handle
, proj_handle
;
5480 D3DLIGHT light_desc
;
5488 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5489 0, 0, 640, 480, 0, 0, 0, 0);
5490 ddraw
= create_ddraw();
5491 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5492 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
5494 skip("Failed to create a 3D device, skipping test.\n");
5495 DestroyWindow(window
);
5499 hr
= IDirect3DDevice_GetDirect3D(device
, &d3d
);
5500 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
5502 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
5503 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
5505 viewport
= create_viewport(device
, 0, 0, 640, 480);
5506 material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
5507 viewport_set_background(device
, viewport
, material
);
5509 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
5510 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5512 hr
= IDirect3DDevice_CreateMatrix(device
, &world_handle
);
5513 ok(hr
== D3D_OK
, "Creating a matrix object failed, hr %#x.\n", hr
);
5514 hr
= IDirect3DDevice_SetMatrix(device
, world_handle
, &mat
);
5515 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
5516 hr
= IDirect3DDevice_CreateMatrix(device
, &view_handle
);
5517 ok(hr
== D3D_OK
, "Creating a matrix object failed, hr %#x.\n", hr
);
5518 hr
= IDirect3DDevice_SetMatrix(device
, view_handle
, &mat
);
5519 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
5520 hr
= IDirect3DDevice_CreateMatrix(device
, &proj_handle
);
5521 ok(hr
== D3D_OK
, "Creating a matrix object failed, hr %#x.\n", hr
);
5522 hr
= IDirect3DDevice_SetMatrix(device
, proj_handle
, &mat
);
5523 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
5525 memset(&exec_desc
, 0, sizeof(exec_desc
));
5526 exec_desc
.dwSize
= sizeof(exec_desc
);
5527 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
5528 exec_desc
.dwBufferSize
= 1024;
5529 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
5531 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
5532 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
5534 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5535 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5537 memcpy(exec_desc
.lpData
, unlitquad
, sizeof(unlitquad
));
5538 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(unlitquad
);
5539 emit_set_ts(&ptr
, D3DTRANSFORMSTATE_WORLD
, world_handle
);
5540 emit_set_ts(&ptr
, D3DTRANSFORMSTATE_VIEW
, view_handle
);
5541 emit_set_ts(&ptr
, D3DTRANSFORMSTATE_PROJECTION
, proj_handle
);
5542 emit_set_rs(&ptr
, D3DRENDERSTATE_CLIPPING
, FALSE
);
5543 emit_set_rs(&ptr
, D3DRENDERSTATE_ZENABLE
, FALSE
);
5544 emit_set_rs(&ptr
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
5545 emit_set_rs(&ptr
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
5546 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORM
, 0, 4);
5547 emit_tquad_tlist(&ptr
, 0);
5549 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5550 inst_length
-= sizeof(unlitquad
);
5552 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5553 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5555 hr
= IDirect3DDevice_BeginScene(device
);
5556 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5558 set_execute_data(execute_buffer
, 4, sizeof(unlitquad
), inst_length
);
5559 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5560 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5562 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5563 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5565 memcpy(exec_desc
.lpData
, litquad
, sizeof(litquad
));
5566 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(litquad
);
5567 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORM
, 0, 4);
5568 emit_tquad_tlist(&ptr
, 0);
5570 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5571 inst_length
-= sizeof(litquad
);
5573 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5574 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5576 set_execute_data(execute_buffer
, 4, sizeof(litquad
), inst_length
);
5577 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5578 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5580 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5581 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5583 memcpy(exec_desc
.lpData
, unlitnquad
, sizeof(unlitnquad
));
5584 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(unlitnquad
);
5585 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORMLIGHT
, 0, 4);
5586 emit_tquad_tlist(&ptr
, 0);
5588 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5589 inst_length
-= sizeof(unlitnquad
);
5591 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5592 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5594 set_execute_data(execute_buffer
, 4, sizeof(unlitnquad
), inst_length
);
5595 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5596 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5598 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5599 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5601 memcpy(exec_desc
.lpData
, litnquad
, sizeof(litnquad
));
5602 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(litnquad
);
5603 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORMLIGHT
, 0, 4);
5604 emit_tquad_tlist(&ptr
, 0);
5606 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5607 inst_length
-= sizeof(litnquad
);
5609 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5610 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5612 set_execute_data(execute_buffer
, 4, sizeof(litnquad
), inst_length
);
5613 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5614 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5616 hr
= IDirect3DDevice_EndScene(device
);
5617 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5619 color
= get_surface_color(rt
, 160, 360);
5620 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color
);
5621 color
= get_surface_color(rt
, 160, 120);
5622 ok(color
== 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color
);
5623 color
= get_surface_color(rt
, 480, 360);
5624 ok(color
== 0x00ffffff, "Unlit quad with normals has color 0x%08x.\n", color
);
5625 color
= get_surface_color(rt
, 480, 120);
5626 ok(color
== 0x00ffffff, "Lit quad with normals has color 0x%08x.\n", color
);
5628 hr
= IDirect3DMaterial_GetHandle(material
, device
, &mat_handle
);
5629 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
5631 hr
= IDirect3D_CreateLight(d3d
, &light
, NULL
);
5632 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
5633 memset(&light_desc
, 0, sizeof(light_desc
));
5634 light_desc
.dwSize
= sizeof(light_desc
);
5635 light_desc
.dltType
= D3DLIGHT_DIRECTIONAL
;
5636 U1(light_desc
.dcvColor
).r
= 0.0f
;
5637 U2(light_desc
.dcvColor
).g
= 0.0f
;
5638 U3(light_desc
.dcvColor
).b
= 1.0f
;
5639 U4(light_desc
.dcvColor
).a
= 1.0f
;
5640 U3(light_desc
.dvDirection
).z
= 1.0f
;
5641 hr
= IDirect3DLight_SetLight(light
, &light_desc
);
5642 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
5643 hr
= IDirect3DViewport_AddLight(viewport
, light
);
5644 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
5646 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
5648 hr
= IDirect3DDevice_SetMatrix(device
, world_handle
, tests
[i
].world_matrix
);
5649 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
5651 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
5652 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5654 hr
= IDirect3DDevice_BeginScene(device
);
5655 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5657 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5658 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5660 memcpy(exec_desc
.lpData
, tests
[i
].quad
, sizeof(nquad
));
5661 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(nquad
);
5662 emit_set_ls(&ptr
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
5663 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORMLIGHT
, 0, 4);
5664 emit_tquad_tlist(&ptr
, 0);
5666 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5667 inst_length
-= sizeof(nquad
);
5669 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5670 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5672 set_execute_data(execute_buffer
, 4, sizeof(nquad
), inst_length
);
5673 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5674 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5676 hr
= IDirect3DDevice_EndScene(device
);
5677 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5679 color
= get_surface_color(rt
, 320, 240);
5680 todo_wine
ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
5683 IDirect3DExecuteBuffer_Release(execute_buffer
);
5684 IDirect3DDevice_DeleteMatrix(device
, world_handle
);
5685 IDirect3DDevice_DeleteMatrix(device
, view_handle
);
5686 IDirect3DDevice_DeleteMatrix(device
, proj_handle
);
5687 hr
= IDirect3DViewport_DeleteLight(viewport
, light
);
5688 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
5689 IDirect3DLight_Release(light
);
5690 destroy_material(material
);
5691 destroy_viewport(device
, viewport
);
5692 IDirectDrawSurface_Release(rt
);
5693 refcount
= IDirect3DDevice_Release(device
);
5694 ok(!refcount
, "Device has %u references left.\n", refcount
);
5695 IDirect3D_Release(d3d
);
5696 refcount
= IDirectDraw_Release(ddraw
);
5697 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
5698 DestroyWindow(window
);
5701 static void test_palette_gdi(void)
5703 IDirectDrawSurface
*surface
, *primary
;
5704 DDSURFACEDESC surface_desc
;
5706 IDirectDrawPalette
*palette
, *palette2
;
5710 PALETTEENTRY palette_entries
[256];
5713 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
5714 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
5715 * not the point of this test. */
5716 static const RGBQUAD expected1
[] =
5718 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
5719 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
5721 static const RGBQUAD expected2
[] =
5723 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
5724 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
5726 static const RGBQUAD expected3
[] =
5728 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
5729 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
5731 HPALETTE ddraw_palette_handle
;
5732 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
5733 RGBQUAD rgbquad
[255];
5734 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
5736 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5737 0, 0, 640, 480, 0, 0, 0, 0);
5738 ddraw
= create_ddraw();
5739 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5740 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5741 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5743 memset(&surface_desc
, 0, sizeof(surface_desc
));
5744 surface_desc
.dwSize
= sizeof(surface_desc
);
5745 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5746 surface_desc
.dwWidth
= 16;
5747 surface_desc
.dwHeight
= 16;
5748 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5749 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5750 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
5751 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
5752 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5753 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5755 /* Avoid colors from the Windows default palette. */
5756 memset(palette_entries
, 0, sizeof(palette_entries
));
5757 palette_entries
[1].peRed
= 0x01;
5758 palette_entries
[2].peGreen
= 0x02;
5759 palette_entries
[3].peBlue
= 0x03;
5760 palette_entries
[4].peRed
= 0x13;
5761 palette_entries
[4].peGreen
= 0x14;
5762 palette_entries
[4].peBlue
= 0x15;
5763 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
5764 palette_entries
, &palette
, NULL
);
5765 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5767 /* If there is no palette assigned and the display mode is not 8 bpp, some
5768 * drivers refuse to create a DC while others allow it. If a DC is created,
5769 * the DIB color table is uninitialized and contains random colors. No error
5770 * is generated when trying to read pixels and random garbage is returned.
5772 * The most likely explanation is that if the driver creates a DC, it (or
5773 * the higher-level runtime) uses GetSystemPaletteEntries to find the
5774 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
5775 * contains uninitialized garbage. See comments below for the P8 case. */
5777 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
5778 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5779 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
5780 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5781 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
5782 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
5783 "Got unexpected palette %p, expected %p.\n",
5784 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
5786 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
5787 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
5788 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
5790 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
5791 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
5792 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
5793 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
5795 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
5797 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
5798 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
5799 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
5802 /* Update the palette while the DC is in use. This does not modify the DC. */
5803 palette_entries
[4].peRed
= 0x23;
5804 palette_entries
[4].peGreen
= 0x24;
5805 palette_entries
[4].peBlue
= 0x25;
5806 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
5807 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
5809 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
5810 ok(i
== 1, "Expected count 1, got %u.\n", i
);
5811 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
5812 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
5813 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
5814 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
5816 /* Neither does re-setting the palette. */
5817 hr
= IDirectDrawSurface_SetPalette(surface
, NULL
);
5818 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5819 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
5820 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5822 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
5823 ok(i
== 1, "Expected count 1, got %u.\n", i
);
5824 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
5825 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
5826 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
5827 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
5829 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
5830 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5832 /* Refresh the DC. This updates the palette. */
5833 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
5834 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5835 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
5836 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
5837 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
5839 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
5840 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
5841 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
5842 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
5844 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
5846 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
5847 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
5848 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
5850 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
5851 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5853 refcount
= IDirectDrawSurface_Release(surface
);
5854 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5856 if (FAILED(IDirectDraw_SetDisplayMode(ddraw
, 640, 480, 8)))
5858 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5859 IDirectDrawPalette_Release(palette
);
5860 IDirectDraw_Release(ddraw
);
5861 DestroyWindow(window
);
5864 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
5865 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
5866 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5868 memset(&surface_desc
, 0, sizeof(surface_desc
));
5869 surface_desc
.dwSize
= sizeof(surface_desc
);
5870 surface_desc
.dwFlags
= DDSD_CAPS
;
5871 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
5872 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
5873 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5875 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5876 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5877 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
5878 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5879 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
5880 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
5881 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
5882 "Got unexpected palette %p, expected %p.\n",
5883 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
5884 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
5886 /* The primary uses the system palette. In exclusive mode, the system palette matches
5887 * the ddraw palette attached to the primary, so the result is what you would expect
5888 * from a regular surface. Tests for the interaction between the ddraw palette and
5889 * the system palette are not included pending an application that depends on this.
5890 * The relation between those causes problems on Windows Vista and newer for games
5891 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
5892 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
5893 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
5894 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
5896 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
5897 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
5898 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
5899 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
5901 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
5903 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
5904 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
5905 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
5907 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
5908 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5910 memset(&surface_desc
, 0, sizeof(surface_desc
));
5911 surface_desc
.dwSize
= sizeof(surface_desc
);
5912 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5913 surface_desc
.dwWidth
= 16;
5914 surface_desc
.dwHeight
= 16;
5915 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5916 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5917 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5919 /* Here the offscreen surface appears to use the primary's palette,
5920 * but in all likelihood it is actually the system palette. */
5921 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
5922 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5923 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
5924 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
5925 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
5927 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
5928 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
5929 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
5930 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
5932 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
5934 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
5935 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
5936 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
5938 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
5939 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5941 /* On real hardware a change to the primary surface's palette applies immediately,
5942 * even on device contexts from offscreen surfaces that do not have their own
5943 * palette. On the testbot VMs this is not the case. Don't test this until we
5944 * know of an application that depends on this. */
5946 memset(palette_entries
, 0, sizeof(palette_entries
));
5947 palette_entries
[1].peBlue
= 0x40;
5948 palette_entries
[2].peRed
= 0x40;
5949 palette_entries
[3].peGreen
= 0x40;
5950 palette_entries
[4].peRed
= 0x12;
5951 palette_entries
[4].peGreen
= 0x34;
5952 palette_entries
[4].peBlue
= 0x56;
5953 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
5954 palette_entries
, &palette2
, NULL
);
5955 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5956 hr
= IDirectDrawSurface_SetPalette(surface
, palette2
);
5957 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5959 /* A palette assigned to the offscreen surface overrides the primary / system
5961 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
5962 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5963 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
5964 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
5965 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
5967 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
5968 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
5969 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
5970 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
5972 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
5974 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
5975 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
5976 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
5978 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
5979 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5981 refcount
= IDirectDrawSurface_Release(surface
);
5982 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5984 /* The Windows 8 testbot keeps extra references to the primary and
5985 * backbuffer while in 8 bpp mode. */
5986 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
5987 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
5989 refcount
= IDirectDrawSurface_Release(primary
);
5990 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5991 refcount
= IDirectDrawPalette_Release(palette2
);
5992 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5993 refcount
= IDirectDrawPalette_Release(palette
);
5994 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5995 refcount
= IDirectDraw_Release(ddraw
);
5996 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5997 DestroyWindow(window
);
6000 static void test_palette_alpha(void)
6002 IDirectDrawSurface
*surface
;
6003 DDSURFACEDESC surface_desc
;
6005 IDirectDrawPalette
*palette
;
6009 PALETTEENTRY palette_entries
[256];
6014 BOOL attach_allowed
;
6019 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
6020 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
6021 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
6024 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6025 0, 0, 640, 480, 0, 0, 0, 0);
6026 ddraw
= create_ddraw();
6027 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6028 if (FAILED(IDirectDraw_SetDisplayMode(ddraw
, 640, 480, 8)))
6030 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6031 IDirectDraw_Release(ddraw
);
6032 DestroyWindow(window
);
6035 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6036 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6038 memset(palette_entries
, 0, sizeof(palette_entries
));
6039 palette_entries
[1].peFlags
= 0x42;
6040 palette_entries
[2].peFlags
= 0xff;
6041 palette_entries
[3].peFlags
= 0x80;
6042 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
6043 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6045 memset(palette_entries
, 0x66, sizeof(palette_entries
));
6046 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
6047 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
6048 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6049 palette_entries
[0].peFlags
);
6050 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6051 palette_entries
[1].peFlags
);
6052 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
6053 palette_entries
[2].peFlags
);
6054 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
6055 palette_entries
[3].peFlags
);
6057 IDirectDrawPalette_Release(palette
);
6059 memset(palette_entries
, 0, sizeof(palette_entries
));
6060 palette_entries
[1].peFlags
= 0x42;
6061 palette_entries
[1].peRed
= 0xff;
6062 palette_entries
[2].peFlags
= 0xff;
6063 palette_entries
[3].peFlags
= 0x80;
6064 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
6065 palette_entries
, &palette
, NULL
);
6066 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6068 memset(palette_entries
, 0x66, sizeof(palette_entries
));
6069 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
6070 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
6071 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6072 palette_entries
[0].peFlags
);
6073 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6074 palette_entries
[1].peFlags
);
6075 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
6076 palette_entries
[2].peFlags
);
6077 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
6078 palette_entries
[3].peFlags
);
6080 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
6082 memset(&surface_desc
, 0, sizeof(surface_desc
));
6083 surface_desc
.dwSize
= sizeof(surface_desc
);
6084 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
6085 surface_desc
.dwWidth
= 128;
6086 surface_desc
.dwHeight
= 128;
6087 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
6088 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6089 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
6091 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
6092 if (test_data
[i
].attach_allowed
)
6093 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
6095 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
6103 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
6104 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_CANTCREATEDC
) /* Win2k testbot */,
6105 "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
6108 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
6109 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
6110 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
6111 rgbquad
.rgbRed
, test_data
[i
].name
);
6112 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
6113 rgbquad
.rgbGreen
, test_data
[i
].name
);
6114 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
6115 rgbquad
.rgbBlue
, test_data
[i
].name
);
6116 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
6117 rgbquad
.rgbReserved
, test_data
[i
].name
);
6118 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
6119 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6122 IDirectDrawSurface_Release(surface
);
6125 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
6126 memset(&surface_desc
, 0, sizeof(surface_desc
));
6127 surface_desc
.dwSize
= sizeof(surface_desc
);
6128 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6129 surface_desc
.dwWidth
= 128;
6130 surface_desc
.dwHeight
= 128;
6131 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6132 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6133 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6134 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6135 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6136 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6137 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6138 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6139 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6140 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
6141 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
6142 IDirectDrawSurface_Release(surface
);
6144 /* The Windows 8 testbot keeps extra references to the primary
6145 * while in 8 bpp mode. */
6146 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
6147 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
6149 refcount
= IDirectDrawPalette_Release(palette
);
6150 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6151 refcount
= IDirectDraw_Release(ddraw
);
6152 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6153 DestroyWindow(window
);
6156 static void test_lost_device(void)
6158 IDirectDrawSurface
*surface
;
6159 DDSURFACEDESC surface_desc
;
6166 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6167 0, 0, 640, 480, 0, 0, 0, 0);
6168 ddraw
= create_ddraw();
6169 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6170 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6171 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6173 memset(&surface_desc
, 0, sizeof(surface_desc
));
6174 surface_desc
.dwSize
= sizeof(surface_desc
);
6175 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6176 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6177 surface_desc
.dwBackBufferCount
= 1;
6178 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6179 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6181 hr
= IDirectDrawSurface_IsLost(surface
);
6182 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6183 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6184 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6186 ret
= SetForegroundWindow(GetDesktopWindow());
6187 ok(ret
, "Failed to set foreground window.\n");
6188 hr
= IDirectDrawSurface_IsLost(surface
);
6189 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6190 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6191 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6193 ret
= SetForegroundWindow(window
);
6194 ok(ret
, "Failed to set foreground window.\n");
6195 hr
= IDirectDrawSurface_IsLost(surface
);
6196 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6197 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6198 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6200 hr
= restore_surfaces(ddraw
);
6201 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6202 hr
= IDirectDrawSurface_IsLost(surface
);
6203 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6204 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6205 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6207 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6208 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6209 hr
= IDirectDrawSurface_IsLost(surface
);
6210 todo_wine
ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6211 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6212 todo_wine
ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
6214 /* Trying to restore the primary will crash, probably because flippable
6215 * surfaces can't exist in DDSCL_NORMAL. */
6216 IDirectDrawSurface_Release(surface
);
6217 memset(&surface_desc
, 0, sizeof(surface_desc
));
6218 surface_desc
.dwSize
= sizeof(surface_desc
);
6219 surface_desc
.dwFlags
= DDSD_CAPS
;
6220 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6221 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6222 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6224 hr
= IDirectDrawSurface_IsLost(surface
);
6225 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6227 ret
= SetForegroundWindow(GetDesktopWindow());
6228 ok(ret
, "Failed to set foreground window.\n");
6229 hr
= IDirectDrawSurface_IsLost(surface
);
6230 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6232 ret
= SetForegroundWindow(window
);
6233 ok(ret
, "Failed to set foreground window.\n");
6234 hr
= IDirectDrawSurface_IsLost(surface
);
6235 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6237 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6238 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6239 hr
= IDirectDrawSurface_IsLost(surface
);
6240 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6242 hr
= restore_surfaces(ddraw
);
6243 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6244 hr
= IDirectDrawSurface_IsLost(surface
);
6245 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6247 IDirectDrawSurface_Release(surface
);
6248 refcount
= IDirectDraw_Release(ddraw
);
6249 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6250 DestroyWindow(window
);
6253 static void test_surface_desc_lock(void)
6255 IDirectDrawSurface
*surface
;
6256 DDSURFACEDESC surface_desc
;
6262 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6263 0, 0, 640, 480, 0, 0, 0, 0);
6264 ddraw
= create_ddraw();
6265 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6266 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6267 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6269 memset(&surface_desc
, 0, sizeof(surface_desc
));
6270 surface_desc
.dwSize
= sizeof(surface_desc
);
6271 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6272 surface_desc
.dwWidth
= 16;
6273 surface_desc
.dwHeight
= 16;
6274 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6275 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6276 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6278 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
6279 surface_desc
.dwSize
= sizeof(surface_desc
);
6280 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
6281 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6282 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
6284 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
6285 surface_desc
.dwSize
= sizeof(surface_desc
);
6286 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
6287 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6288 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
6289 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
6290 surface_desc
.dwSize
= sizeof(surface_desc
);
6291 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
6292 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6293 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
6294 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
6295 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6297 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
6298 surface_desc
.dwSize
= sizeof(surface_desc
);
6299 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
6300 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6301 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
6303 IDirectDrawSurface_Release(surface
);
6304 refcount
= IDirectDraw_Release(ddraw
);
6305 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6306 DestroyWindow(window
);
6309 static void test_texturemapblend(void)
6313 D3DEXECUTEBUFFERDESC exec_desc
;
6315 static RECT rect
= {0, 0, 64, 128};
6316 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6318 IDirectDrawSurface
*surface
, *rt
;
6319 IDirect3DTexture
*texture
;
6320 D3DTEXTUREHANDLE texture_handle
;
6323 IDirect3DDevice
*device
;
6324 IDirect3DMaterial
*material
;
6325 IDirect3DViewport
*viewport
;
6326 IDirect3DExecuteBuffer
*execute_buffer
;
6332 static const D3DTLVERTEX test1_quads
[] =
6334 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {0.0f
}},
6335 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {1.0f
}},
6336 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {0.0f
}},
6337 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {1.0f
}},
6338 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {0.0f
}},
6339 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {1.0f
}},
6340 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {0.0f
}},
6341 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {1.0f
}},
6345 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {0.0f
}},
6346 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {1.0f
}},
6347 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {0.0f
}},
6348 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {1.0f
}},
6349 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {0.0f
}},
6350 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {1.0f
}},
6351 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {0.0f
}},
6352 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {1.0f
}},
6355 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6356 0, 0, 640, 480, 0, 0, 0, 0);
6357 ddraw
= create_ddraw();
6358 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6359 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6361 skip("Failed to create a 3D device, skipping test.\n");
6362 DestroyWindow(window
);
6363 IDirectDraw_Release(ddraw
);
6367 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
6368 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6370 material
= create_diffuse_material(device
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
6371 viewport
= create_viewport(device
, 0, 0, 640, 480);
6372 viewport_set_background(device
, viewport
, material
);
6374 memset(&exec_desc
, 0, sizeof(exec_desc
));
6375 exec_desc
.dwSize
= sizeof(exec_desc
);
6376 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
6377 exec_desc
.dwBufferSize
= 1024;
6378 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
6379 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
6380 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
6382 /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel.
6384 * The vertex alpha is completely ignored in this case, so case 1 and 2 combined are not
6385 * a D3DTOP_MODULATE with texture alpha = 0xff in case 2 (no alpha in texture). */
6386 memset(&ddsd
, 0, sizeof(ddsd
));
6387 ddsd
.dwSize
= sizeof(ddsd
);
6388 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
6389 ddsd
.dwHeight
= 128;
6391 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6392 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
6393 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6394 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6395 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6396 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6397 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6398 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6399 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6400 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6402 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
6403 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
6404 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
6405 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
6407 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6408 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
6410 memset(&fx
, 0, sizeof(fx
));
6411 fx
.dwSize
= sizeof(fx
);
6412 U5(fx
).dwFillColor
= 0xff0000ff;
6413 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6414 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6415 U5(fx
).dwFillColor
= 0x800000ff;
6416 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6417 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6419 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
6420 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
6422 memcpy(exec_desc
.lpData
, test1_quads
, sizeof(test1_quads
));
6424 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(test1_quads
);
6425 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 8);
6426 emit_set_rs(&ptr
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
6427 emit_set_rs(&ptr
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
6428 emit_set_rs(&ptr
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
6429 emit_set_rs(&ptr
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
6430 /* The history of D3DRENDERSTATE_ALPHABLENDENABLE is quite a mess. In the
6431 * first D3D release there was a D3DRENDERSTATE_BLENDENABLE (enum value 27).
6432 * D3D5 introduced a new and separate D3DRENDERSTATE_ALPHABLENDENABLE (42)
6433 * together with D3DRENDERSTATE_COLORKEYENABLE (41). The docs aren't all
6434 * that clear but they mention that D3DRENDERSTATE_BLENDENABLE overrides the
6436 * Then D3D6 came and got rid of the new D3DRENDERSTATE_ALPHABLENDENABLE
6437 * state (42), renaming the older D3DRENDERSTATE_BLENDENABLE enum (27)
6438 * as D3DRENDERSTATE_ALPHABLENDENABLE.
6439 * There is a comment in the D3D6 docs which mentions that hardware
6440 * rasterizers always used D3DRENDERSTATE_BLENDENABLE to just toggle alpha
6441 * blending while prior to D3D5 software rasterizers toggled both color
6442 * keying and alpha blending according to it. What I gather is that, from
6443 * D3D6 onwards, D3DRENDERSTATE_ALPHABLENDENABLE always only toggles the
6444 * alpha blending state.
6445 * These tests seem to show that actual, current hardware follows the D3D6
6446 * behavior even when using the original D3D interfaces, for the HAL device
6448 emit_set_rs(&ptr
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
6449 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
);
6450 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
6452 emit_tquad(&ptr
, 0);
6453 emit_tquad(&ptr
, 4);
6456 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
6457 inst_length
-= sizeof(test1_quads
);
6458 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
6459 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
6460 set_execute_data(execute_buffer
, 8, sizeof(test1_quads
), inst_length
);
6462 hr
= IDirect3DDevice_BeginScene(device
);
6463 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6464 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_UNCLIPPED
);
6465 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
6466 hr
= IDirect3DDevice_EndScene(device
);
6467 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6469 color
= get_surface_color(rt
, 5, 5);
6470 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
6471 color
= get_surface_color(rt
, 400, 5);
6472 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
6473 color
= get_surface_color(rt
, 5, 245);
6474 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
6475 color
= get_surface_color(rt
, 400, 245);
6476 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
6478 IDirect3DTexture_Release(texture
);
6479 ref
= IDirectDrawSurface_Release(surface
);
6480 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
6482 /* Test alpha with texture that has no alpha channel - alpha should be taken from diffuse vertex color. */
6483 memset(&ddsd
, 0, sizeof(ddsd
));
6484 ddsd
.dwSize
= sizeof(ddsd
);
6485 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
6486 ddsd
.dwHeight
= 128;
6488 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6489 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
6490 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6491 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6492 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6493 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6494 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6496 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6497 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6499 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
6500 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
6501 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
6502 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
6504 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6505 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
6507 U5(fx
).dwFillColor
= 0xff0000ff;
6508 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6509 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6510 U5(fx
).dwFillColor
= 0x800000ff;
6511 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6512 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6514 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
6515 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
6517 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(test1_quads
);
6518 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 8);
6519 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
6521 emit_tquad(&ptr
, 0);
6522 emit_tquad(&ptr
, 4);
6525 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
6526 inst_length
-= sizeof(test1_quads
);
6527 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
6528 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
6529 set_execute_data(execute_buffer
, 8, sizeof(test1_quads
), inst_length
);
6531 hr
= IDirect3DDevice_BeginScene(device
);
6532 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6533 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_UNCLIPPED
);
6534 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
6535 hr
= IDirect3DDevice_EndScene(device
);
6536 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6538 color
= get_surface_color(rt
, 5, 5);
6539 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
6540 color
= get_surface_color(rt
, 400, 5);
6541 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
6542 color
= get_surface_color(rt
, 5, 245);
6543 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
6544 color
= get_surface_color(rt
, 400, 245);
6545 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
6547 IDirect3DTexture_Release(texture
);
6548 ref
= IDirectDrawSurface_Release(surface
);
6549 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
6551 /* Test RGB - should multiply color components from diffuse vertex color and texture. */
6552 memset(&ddsd
, 0, sizeof(ddsd
));
6553 ddsd
.dwSize
= sizeof(ddsd
);
6554 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
6555 ddsd
.dwHeight
= 128;
6557 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6558 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
6559 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6560 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6561 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6562 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6563 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6564 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6565 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6566 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6568 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
6569 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
6570 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
6571 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
6573 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6574 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
6576 U5(fx
).dwFillColor
= 0x00ffffff;
6577 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6578 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6579 U5(fx
).dwFillColor
= 0x00ffff80;
6580 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6581 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6583 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
6584 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
6586 memcpy(exec_desc
.lpData
, test2_quads
, sizeof(test2_quads
));
6588 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(test2_quads
);
6589 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 8);
6590 emit_set_rs(&ptr
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
6591 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
6593 emit_tquad(&ptr
, 0);
6594 emit_tquad(&ptr
, 4);
6597 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
6598 inst_length
-= sizeof(test2_quads
);
6599 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
6600 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
6601 set_execute_data(execute_buffer
, 8, sizeof(test2_quads
), inst_length
);
6603 hr
= IDirect3DDevice_BeginScene(device
);
6604 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6605 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_UNCLIPPED
);
6606 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
6607 hr
= IDirect3DDevice_EndScene(device
);
6608 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6610 /* WARP (Win8 testbot) emulates color keying with the alpha channel like Wine does,
6611 * but even applies it when there's no color key assigned. The surface alpha is zero
6612 * here, so nothing gets drawn.
6614 * The ddraw2 version of this test draws these quads with color keying off due to
6615 * different defaults in ddraw1 and ddraw2. */
6616 color
= get_surface_color(rt
, 5, 5);
6617 ok(compare_color(color
, 0x00ff0040, 2) || broken(compare_color(color
, 0x00000000, 1)),
6618 "Got unexpected color 0x%08x.\n", color
);
6619 color
= get_surface_color(rt
, 400, 5);
6620 ok(compare_color(color
, 0x00ff0080, 2) || broken(compare_color(color
, 0x00000000, 1)),
6621 "Got unexpected color 0x%08x.\n", color
);
6622 color
= get_surface_color(rt
, 5, 245);
6623 ok(compare_color(color
, 0x00800080, 2) || broken(compare_color(color
, 0x00000000, 1)),
6624 "Got unexpected color 0x%08x.\n", color
);
6625 color
= get_surface_color(rt
, 400, 245);
6626 ok(compare_color(color
, 0x008000ff, 2) || broken(compare_color(color
, 0x00000000, 1)),
6627 "Got unexpected color 0x%08x.\n", color
);
6629 IDirect3DTexture_Release(texture
);
6630 ref
= IDirectDrawSurface_Release(surface
);
6631 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
6633 /* Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere). */
6634 memset(&ddsd
, 0, sizeof(ddsd
));
6635 ddsd
.dwSize
= sizeof(ddsd
);
6636 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
6637 ddsd
.dwHeight
= 128;
6639 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6640 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
6641 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6642 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 16;
6643 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
6644 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
6645 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
6647 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6648 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6650 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
6651 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
6652 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
6653 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
6655 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6656 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
6658 U5(fx
).dwFillColor
= 0xf800;
6659 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6660 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6661 U5(fx
).dwFillColor
= 0x001f;
6662 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6663 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6665 ckey
.dwColorSpaceLowValue
= 0x001f;
6666 ckey
.dwColorSpaceHighValue
= 0x001f;
6667 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
6668 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
6670 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
6671 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
6673 memcpy(exec_desc
.lpData
, test1_quads
, sizeof(test1_quads
));
6675 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(test1_quads
);
6676 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 8);
6677 emit_set_rs(&ptr
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
6678 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
6679 /* D3DRENDERSTATE_COLORKEYENABLE is supposed to be on by default on version
6680 * 1 devices, but for some reason it randomly defaults to FALSE on the W8
6681 * testbot. This is either the fault of Windows 8 or the WARP driver.
6682 * Also D3DRENDERSTATE_COLORKEYENABLE was introduced in D3D 5 aka version 2
6683 * devices only, which might imply this doesn't actually do anything on
6685 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
6687 emit_tquad(&ptr
, 0);
6688 emit_tquad(&ptr
, 4);
6691 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
6692 inst_length
-= sizeof(test1_quads
);
6693 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
6694 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
6695 set_execute_data(execute_buffer
, 8, sizeof(test1_quads
), inst_length
);
6697 hr
= IDirect3DDevice_BeginScene(device
);
6698 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6699 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_UNCLIPPED
);
6700 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
6701 hr
= IDirect3DDevice_EndScene(device
);
6702 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6704 /* Allow broken WARP results (colorkey disabled). */
6705 color
= get_surface_color(rt
, 5, 5);
6706 ok(compare_color(color
, 0x00000000, 2) || broken(compare_color(color
, 0x000000ff, 2)),
6707 "Got unexpected color 0x%08x.\n", color
);
6708 color
= get_surface_color(rt
, 400, 5);
6709 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
6710 color
= get_surface_color(rt
, 5, 245);
6711 ok(compare_color(color
, 0x00000000, 2) || broken(compare_color(color
, 0x00000080, 2)),
6712 "Got unexpected color 0x%08x.\n", color
);
6713 color
= get_surface_color(rt
, 400, 245);
6714 ok(compare_color(color
, 0x00800000, 2), "Got unexpected color 0x%08x.\n", color
);
6716 IDirect3DTexture_Release(texture
);
6717 ref
= IDirectDrawSurface_Release(surface
);
6718 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
6720 ref
= IDirect3DExecuteBuffer_Release(execute_buffer
);
6721 ok(ref
== 0, "Execute buffer not properly released, refcount %u.\n", ref
);
6722 destroy_viewport(device
, viewport
);
6723 ref
= IDirect3DMaterial_Release(material
);
6724 ok(ref
== 0, "Material not properly released, refcount %u.\n", ref
);
6725 IDirectDrawSurface_Release(rt
);
6726 IDirect3DDevice_Release(device
);
6727 ref
= IDirectDraw_Release(ddraw
);
6728 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6729 DestroyWindow(window
);
6732 static void test_viewport_clear_rect(void)
6735 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6736 static D3DRECT clear_rect2
= {{90}, {90}, {110}, {110}};
6737 IDirectDrawSurface
*rt
;
6740 IDirect3DDevice
*device
;
6741 IDirect3DMaterial
*red
, *green
;
6742 IDirect3DViewport
*viewport
, *viewport2
;
6746 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6747 0, 0, 640, 480, 0, 0, 0, 0);
6748 ddraw
= create_ddraw();
6749 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6750 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6752 skip("Failed to create a 3D device, skipping test.\n");
6753 DestroyWindow(window
);
6754 IDirectDraw_Release(ddraw
);
6758 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
6759 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6761 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
6762 viewport
= create_viewport(device
, 0, 0, 640, 480);
6763 viewport_set_background(device
, viewport
, red
);
6764 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6765 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6767 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
6768 viewport2
= create_viewport(device
, 100, 100, 20, 20);
6769 viewport_set_background(device
, viewport2
, green
);
6770 hr
= IDirect3DViewport_Clear(viewport2
, 1, &clear_rect2
, D3DCLEAR_TARGET
);
6771 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6773 color
= get_surface_color(rt
, 85, 85); /* Outside both. */
6774 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6775 color
= get_surface_color(rt
, 95, 95); /* Outside vp, inside rect. */
6776 /* AMD GPUs ignore the viewport dimensions and only care about the rectangle. */
6777 ok(compare_color(color
, 0x00ff0000, 1) || broken(compare_color(color
, 0x0000ff00, 1)),
6778 "Got unexpected color 0x%08x.\n", color
);
6779 color
= get_surface_color(rt
, 105, 105); /* Inside both. */
6780 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
6781 color
= get_surface_color(rt
, 115, 115); /* Inside vp, outside rect. */
6782 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6783 color
= get_surface_color(rt
, 125, 125); /* Outside both. */
6784 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6786 destroy_viewport(device
, viewport2
);
6787 destroy_material(green
);
6788 destroy_viewport(device
, viewport
);
6789 destroy_material(red
);
6790 IDirectDrawSurface_Release(rt
);
6791 IDirect3DDevice_Release(device
);
6792 ref
= IDirectDraw_Release(ddraw
);
6793 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6794 DestroyWindow(window
);
6797 static void test_color_fill(void)
6800 IDirect3DDevice
*device
;
6802 IDirectDrawSurface
*surface
, *surface2
;
6803 DDSURFACEDESC surface_desc
;
6808 RECT rect
= {5, 5, 7, 7};
6810 DWORD num_fourcc_codes
, *fourcc_codes
;
6812 BOOL support_uyvy
= FALSE
, support_yuy2
= FALSE
;
6816 HRESULT colorfill_hr
, depthfill_hr
;
6821 DDPIXELFORMAT format
;
6826 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
6827 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
6829 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
6830 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
6834 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
6835 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
6837 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
6838 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
6842 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
6843 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
6845 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
6846 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
6850 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
6851 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
6853 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
6854 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
6858 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
,
6859 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
6860 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
6863 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
6864 * different afterwards. DX9+ GPUs set one of the two luminance values
6865 * in each block, but AMD and Nvidia GPUs disagree on which luminance
6866 * value they set. r200 (dx8) just sets the entire block to the clear
6868 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
6869 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
6871 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
6872 {0}, {0}, {0}, {0}, {0}
6876 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
6877 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
6879 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
6880 {0}, {0}, {0}, {0}, {0}
6884 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
6885 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
6887 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
6888 {0}, {0}, {0}, {0}, {0}
6892 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
6893 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
6895 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
6896 {0}, {0}, {0}, {0}, {0}
6900 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
6901 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
6903 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
6904 {0}, {0}, {0}, {0}, {0}
6908 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
6909 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
6911 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
6912 {0}, {0}, {0}, {0}, {0}
6916 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
6917 * surface works, presumably because it is handled by the runtime instead of
6919 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
6920 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
6922 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
6923 {8}, {0}, {0}, {0}, {0}
6927 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
6928 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
6930 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
6931 {8}, {0}, {0}, {0}, {0}
6943 {SRCCOPY
, "SRCCOPY", DD_OK
},
6944 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
6945 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
6946 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
6947 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
6948 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
6949 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
6950 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
6951 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
6952 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
6953 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
6954 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
6955 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
6956 {BLACKNESS
, "BLACKNESS", DD_OK
},
6957 {WHITENESS
, "WHITENESS", DD_OK
},
6958 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
6961 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6962 0, 0, 640, 480, 0, 0, 0, 0);
6963 ddraw
= create_ddraw();
6964 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6965 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6967 skip("Failed to create a 3D device, skipping test.\n");
6968 DestroyWindow(window
);
6969 IDirectDraw_Release(ddraw
);
6973 hr
= IDirectDraw_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
6974 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
6975 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
6976 num_fourcc_codes
* sizeof(*fourcc_codes
));
6979 hr
= IDirectDraw_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
6980 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
6981 for (i
= 0; i
< num_fourcc_codes
; i
++)
6983 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
6984 support_yuy2
= TRUE
;
6985 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
6986 support_uyvy
= TRUE
;
6988 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
6990 memset(&hal_caps
, 0, sizeof(hal_caps
));
6991 hal_caps
.dwSize
= sizeof(hal_caps
);
6992 hr
= IDirectDraw_GetCaps(ddraw
, &hal_caps
, NULL
);
6993 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6995 if ((!support_yuy2
&& !support_uyvy
) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
6996 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
6998 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
7000 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
7001 memset(&fx
, 0, sizeof(fx
));
7002 fx
.dwSize
= sizeof(fx
);
7003 U5(fx
).dwFillColor
= 0xdeadbeef;
7005 memset(&surface_desc
, 0, sizeof(surface_desc
));
7006 surface_desc
.dwSize
= sizeof(surface_desc
);
7007 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7008 surface_desc
.dwWidth
= 64;
7009 surface_desc
.dwHeight
= 64;
7010 surface_desc
.ddpfPixelFormat
= tests
[i
].format
;
7011 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
7013 if (tests
[i
].caps
& DDSCAPS_TEXTURE
)
7015 struct format_support_check check
= {&tests
[i
].format
, FALSE
};
7016 hr
= IDirect3DDevice_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
7017 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
7018 if (!check
.supported
)
7022 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !support_yuy2
)
7024 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !support_uyvy
)
7026 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
7029 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
7031 surface_desc
.dwFlags
&= ~DDSD_PIXELFORMAT
;
7032 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
7033 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
7036 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7037 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7039 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7040 if (tests
[i
].format
.dwFourCC
)
7041 todo_wine
ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
7042 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
7044 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
7045 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
7047 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7048 if (tests
[i
].format
.dwFourCC
)
7049 todo_wine
ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
7050 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
7052 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
7053 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
7055 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
7057 memset(&surface_desc
, 0, sizeof(surface_desc
));
7058 surface_desc
.dwSize
= sizeof(surface_desc
);
7059 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
7060 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7061 color
= surface_desc
.lpSurface
;
7062 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
7063 *color
, tests
[i
].result
, tests
[i
].name
);
7064 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
7065 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7068 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7069 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
7070 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
7071 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7072 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
7073 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
7075 U5(fx
).dwFillColor
= 0xdeadbeef;
7076 fx
.dwROP
= BLACKNESS
;
7077 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7078 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
7079 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
7080 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
7081 U5(fx
).dwFillColor
, tests
[i
].name
);
7083 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
7085 memset(&surface_desc
, 0, sizeof(surface_desc
));
7086 surface_desc
.dwSize
= sizeof(surface_desc
);
7087 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
7088 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7089 color
= surface_desc
.lpSurface
;
7090 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
7091 *color
, tests
[i
].name
);
7092 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
7093 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7096 fx
.dwROP
= WHITENESS
;
7097 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7098 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
7099 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
7100 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
7101 U5(fx
).dwFillColor
, tests
[i
].name
);
7103 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
7105 memset(&surface_desc
, 0, sizeof(surface_desc
));
7106 surface_desc
.dwSize
= sizeof(surface_desc
);
7107 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
7108 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7109 color
= surface_desc
.lpSurface
;
7110 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
7111 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
7112 *color
, tests
[i
].name
);
7113 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
7114 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7117 IDirectDrawSurface_Release(surface
);
7120 memset(&fx
, 0, sizeof(fx
));
7121 fx
.dwSize
= sizeof(fx
);
7122 U5(fx
).dwFillColor
= 0xdeadbeef;
7123 fx
.dwROP
= WHITENESS
;
7125 memset(&surface_desc
, 0, sizeof(surface_desc
));
7126 surface_desc
.dwSize
= sizeof(surface_desc
);
7127 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7128 surface_desc
.dwWidth
= 64;
7129 surface_desc
.dwHeight
= 64;
7130 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7131 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7132 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7133 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7134 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7135 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7136 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
7137 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7138 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7139 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
7140 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7143 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
7144 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7145 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
7146 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7148 /* Unused source rectangle. */
7149 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7150 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7151 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7152 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7154 /* Unused source surface. */
7155 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7156 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7157 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7158 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7159 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7160 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7161 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7162 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7164 /* Inverted destination or source rectangle. */
7165 SetRect(&rect
, 5, 7, 7, 5);
7166 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7167 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7168 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7169 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7170 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7171 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7172 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7173 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7174 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7175 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7177 /* Negative rectangle. */
7178 SetRect(&rect
, -1, -1, 5, 5);
7179 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7180 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7181 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7182 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7183 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7184 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7185 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7186 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7187 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7188 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7190 /* Out of bounds rectangle. */
7191 SetRect(&rect
, 0, 0, 65, 65);
7192 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7193 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7194 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7195 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7197 /* Combine multiple flags. */
7198 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7199 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7200 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7201 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7202 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7203 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7205 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
7207 fx
.dwROP
= rops
[i
].rop
;
7208 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7209 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
7212 IDirectDrawSurface_Release(surface2
);
7213 IDirectDrawSurface_Release(surface
);
7215 memset(&surface_desc
, 0, sizeof(surface_desc
));
7216 surface_desc
.dwSize
= sizeof(surface_desc
);
7217 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_ZBUFFERBITDEPTH
;
7218 surface_desc
.dwWidth
= 64;
7219 surface_desc
.dwHeight
= 64;
7220 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
7221 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
7222 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7223 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7224 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
7225 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7228 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
7229 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7231 /* Unused source rectangle. */
7232 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7233 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7235 /* Unused source surface. */
7236 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7237 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7238 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7239 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7241 /* Inverted destination or source rectangle. */
7242 SetRect(&rect
, 5, 7, 7, 5);
7243 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7244 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7245 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7246 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7247 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7248 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7249 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7250 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7252 /* Negative rectangle. */
7253 SetRect(&rect
, -1, -1, 5, 5);
7254 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7255 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7256 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7257 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7258 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7259 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7260 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7261 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7263 /* Out of bounds rectangle. */
7264 SetRect(&rect
, 0, 0, 65, 65);
7265 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7266 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7268 /* Combine multiple flags. */
7269 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7270 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7272 IDirectDrawSurface_Release(surface2
);
7273 IDirectDrawSurface_Release(surface
);
7276 IDirect3DDevice_Release(device
);
7277 refcount
= IDirectDraw_Release(ddraw
);
7278 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
7279 DestroyWindow(window
);
7282 static void test_colorkey_precision(void)
7284 static D3DTLVERTEX quad
[] =
7286 {{ 0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x00000000}, {0x00000000}, {0.0f
}, {1.0f
}},
7287 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0x00000000}, {0x00000000}, {0.0f
}, {0.0f
}},
7288 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x00000000}, {0x00000000}, {1.0f
}, {1.0f
}},
7289 {{640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0x00000000}, {0x00000000}, {1.0f
}, {0.0f
}},
7291 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7292 IDirect3DDevice
*device
;
7294 IDirectDrawSurface
*rt
;
7295 IDirect3DViewport
*viewport
;
7296 IDirect3DExecuteBuffer
*execute_buffer
;
7297 D3DEXECUTEBUFFERDESC exec_desc
;
7302 IDirectDrawSurface
*src
, *dst
, *texture
;
7303 D3DTEXTUREHANDLE handle
;
7304 IDirect3DTexture
*d3d_texture
;
7305 IDirect3DMaterial
*green
;
7306 DDSURFACEDESC surface_desc
, lock_desc
;
7312 DWORD data
[4] = {0}, color_mask
;
7313 D3DDEVICEDESC device_desc
, hel_desc
;
7317 unsigned int max
, shift
, bpp
, clear
;
7324 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8",
7326 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
7327 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
7332 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel",
7334 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
7335 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
7340 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel",
7342 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
7343 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
7348 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4",
7350 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
7351 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
7357 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7358 0, 0, 640, 480, 0, 0, 0, 0);
7359 ddraw
= create_ddraw();
7360 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7361 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
7363 skip("Failed to create a 3D device, skipping test.\n");
7364 DestroyWindow(window
);
7365 IDirectDraw_Release(ddraw
);
7368 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
7369 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
7371 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
7372 * (color key doesn't match although the values are equal), and a false
7373 * positive when the color key is 0 and the texture contains the value 1.
7374 * I don't want to mark this broken unconditionally since this would
7375 * essentially disable the test on Windows. Try to detect WARP (and I
7376 * guess mismatch other SW renderers) by its ability to texture from
7377 * system memory. Also on random occasions 254 == 255 and 255 != 255.*/
7378 memset(&device_desc
, 0, sizeof(device_desc
));
7379 device_desc
.dwSize
= sizeof(device_desc
);
7380 memset(&hel_desc
, 0, sizeof(hel_desc
));
7381 hel_desc
.dwSize
= sizeof(hel_desc
);
7382 hr
= IDirect3DDevice_GetCaps(device
, &device_desc
, &hel_desc
);
7383 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7384 warp
= !!(device_desc
.dwDevCaps
& D3DDEVCAPS_TEXTURESYSTEMMEMORY
);
7386 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
7387 viewport
= create_viewport(device
, 0, 0, 640, 480);
7388 viewport_set_background(device
, viewport
, green
);
7390 memset(&exec_desc
, 0, sizeof(exec_desc
));
7391 exec_desc
.dwSize
= sizeof(exec_desc
);
7392 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
7393 exec_desc
.dwBufferSize
= 1024;
7394 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
7395 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
7396 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
7398 memset(&fx
, 0, sizeof(fx
));
7399 fx
.dwSize
= sizeof(fx
);
7400 memset(&lock_desc
, 0, sizeof(lock_desc
));
7401 lock_desc
.dwSize
= sizeof(lock_desc
);
7403 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
7405 memset(&surface_desc
, 0, sizeof(surface_desc
));
7406 surface_desc
.dwSize
= sizeof(surface_desc
);
7407 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7408 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7409 surface_desc
.dwWidth
= 4;
7410 surface_desc
.dwHeight
= 1;
7411 surface_desc
.ddpfPixelFormat
= tests
[t
].fmt
;
7412 /* Windows XP (at least with the r200 driver, other drivers untested) produces
7413 * garbage when doing color keyed texture->texture blits. */
7414 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
7415 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7416 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
7417 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7419 fx
.dwFillColor
= tests
[t
].clear
;
7420 /* On the w8 testbot (WARP driver) the blit result has different values in the
7422 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
7423 | U3(tests
[t
].fmt
).dwGBitMask
7424 | U4(tests
[t
].fmt
).dwBBitMask
;
7426 for (c
= 0; c
<= tests
[t
].max
; ++c
)
7428 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
7429 * texture after it has been set once... */
7430 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
7431 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
7432 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
7433 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
7434 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
7435 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7437 hr
= IDirectDrawSurface_QueryInterface(texture
, &IID_IDirect3DTexture
, (void **)&d3d_texture
);
7438 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
7439 hr
= IDirect3DTexture_GetHandle(d3d_texture
, device
, &handle
);
7440 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
7441 IDirect3DTexture_Release(d3d_texture
);
7443 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
7444 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
7446 memcpy(exec_desc
.lpData
, quad
, sizeof(quad
));
7448 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(quad
);
7449 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 8);
7450 emit_set_rs(&ptr
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
7451 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, handle
);
7452 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATEALPHA
);
7453 /* D3DRENDERSTATE_COLORKEYENABLE is supposed to be on by default on version
7454 * 1 devices, but for some reason it randomly defaults to FALSE on the W8
7455 * testbot. This is either the fault of Windows 8 or the WARP driver.
7456 * Also D3DRENDERSTATE_COLORKEYENABLE was introduced in D3D 5 aka version 2
7457 * devices only, which might imply this doesn't actually do anything on
7459 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
7461 emit_tquad(&ptr
, 0);
7462 emit_tquad(&ptr
, 4);
7463 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
7466 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
7467 inst_length
-= sizeof(quad
);
7468 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
7469 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
7470 set_execute_data(execute_buffer
, 8, sizeof(quad
), inst_length
);
7472 hr
= IDirectDrawSurface_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7473 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
7475 hr
= IDirectDrawSurface_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
7476 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7477 switch (tests
[t
].bpp
)
7480 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
7481 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
7482 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
7483 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
7487 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
7488 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
7489 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
7490 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
7493 hr
= IDirectDrawSurface_Unlock(src
, 0);
7494 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7495 hr
= IDirectDrawSurface_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
7496 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
7498 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
7499 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
7500 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
7501 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
7503 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
7504 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
7506 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
7507 hr
= IDirectDrawSurface_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
7508 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7509 switch (tests
[t
].bpp
)
7512 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
7513 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
7514 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
7515 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
7519 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
7520 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
7521 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
7522 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
7525 hr
= IDirectDrawSurface_Unlock(dst
, 0);
7526 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7530 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7531 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
7533 if (data
[3] == tests
[t
].clear
)
7535 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
7536 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
7537 * even when a different surface is used. The blit itself doesn't draw anything,
7538 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
7539 * never be masked out by the key.
7541 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
7542 * terrible on WARP. */
7543 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
7544 IDirectDrawSurface_Release(texture
);
7545 IDirectDrawSurface_Release(src
);
7546 IDirectDrawSurface_Release(dst
);
7551 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7552 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
7554 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7555 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
7557 if (c
== tests
[t
].max
)
7558 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7559 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
7561 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7562 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
7564 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7565 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
7567 hr
= IDirect3DDevice_BeginScene(device
);
7568 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7569 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_UNCLIPPED
);
7570 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7571 hr
= IDirect3DDevice_EndScene(device
);
7572 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7574 color
= get_surface_color(rt
, 80, 240);
7576 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
7577 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7578 color
, tests
[t
].name
, c
);
7580 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
7581 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7582 color
, tests
[t
].name
, c
);
7584 color
= get_surface_color(rt
, 240, 240);
7585 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
7586 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7587 color
, tests
[t
].name
, c
);
7589 color
= get_surface_color(rt
, 400, 240);
7590 if (c
== tests
[t
].max
)
7591 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
7592 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7593 color
, tests
[t
].name
, c
);
7595 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
7596 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7597 color
, tests
[t
].name
, c
);
7599 IDirectDrawSurface_Release(texture
);
7601 IDirectDrawSurface_Release(src
);
7602 IDirectDrawSurface_Release(dst
);
7606 destroy_viewport(device
, viewport
);
7607 destroy_material(green
);
7608 IDirectDrawSurface_Release(rt
);
7609 IDirect3DExecuteBuffer_Release(execute_buffer
);
7610 IDirect3DDevice_Release(device
);
7611 refcount
= IDirectDraw_Release(ddraw
);
7612 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
7613 DestroyWindow(window
);
7616 static void test_range_colorkey(void)
7621 IDirectDrawSurface
*surface
;
7622 DDSURFACEDESC surface_desc
;
7626 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7627 0, 0, 640, 480, 0, 0, 0, 0);
7628 ddraw
= create_ddraw();
7629 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7630 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7631 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7633 memset(&surface_desc
, 0, sizeof(surface_desc
));
7634 surface_desc
.dwSize
= sizeof(surface_desc
);
7635 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
7636 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
7637 surface_desc
.dwWidth
= 1;
7638 surface_desc
.dwHeight
= 1;
7639 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7640 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7641 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7642 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7643 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7644 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
7646 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
7647 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
7648 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
7649 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7650 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
7652 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
7653 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
7654 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7655 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
7657 /* Same for DDSCAPS_OFFSCREENPLAIN. */
7658 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7659 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
7660 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
7661 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7662 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
7664 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
7665 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
7666 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7667 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
7669 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
7670 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
7671 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7672 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7674 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
7675 ckey
.dwColorSpaceLowValue
= 0x00000000;
7676 ckey
.dwColorSpaceHighValue
= 0x00000001;
7677 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
7678 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
7680 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
7681 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
7682 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
7683 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
7685 ckey
.dwColorSpaceLowValue
= 0x00000001;
7686 ckey
.dwColorSpaceHighValue
= 0x00000000;
7687 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
7688 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
7690 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
7691 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
7692 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
7693 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
7695 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
7696 ckey
.dwColorSpaceLowValue
= 0x00000000;
7697 ckey
.dwColorSpaceHighValue
= 0x00000000;
7698 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
7699 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
7701 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
7702 ckey
.dwColorSpaceLowValue
= 0x00000001;
7703 ckey
.dwColorSpaceHighValue
= 0x00000000;
7704 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
7705 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
7706 ckey
.dwColorSpaceLowValue
= 0x00000000;
7707 ckey
.dwColorSpaceHighValue
= 0x00000001;
7708 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
7709 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
7710 /* Range destination keys don't work either. */
7711 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
7712 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
7714 /* Just to show it's not because of A, R, and G having equal values. */
7715 ckey
.dwColorSpaceLowValue
= 0x00000000;
7716 ckey
.dwColorSpaceHighValue
= 0x01010101;
7717 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
7718 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
7720 /* None of these operations modified the key. */
7721 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
7722 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
7723 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
7724 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
7726 IDirectDrawSurface_Release(surface
),
7727 refcount
= IDirectDraw_Release(ddraw
);
7728 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7729 DestroyWindow(window
);
7735 DEVMODEW current_mode
;
7737 if (!(ddraw
= create_ddraw()))
7739 skip("Failed to create a ddraw object, skipping tests.\n");
7742 IDirectDraw_Release(ddraw
);
7744 memset(¤t_mode
, 0, sizeof(current_mode
));
7745 current_mode
.dmSize
= sizeof(current_mode
);
7746 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
7747 registry_mode
.dmSize
= sizeof(registry_mode
);
7748 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
7749 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
7750 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
7752 skip("Current mode does not match registry mode, skipping test.\n");
7756 test_coop_level_create_device_window();
7758 test_coop_level_d3d_state();
7759 test_surface_interface_mismatch();
7760 test_coop_level_threaded();
7769 test_window_style();
7770 test_redundant_mode_set();
7771 test_coop_level_mode_set();
7772 test_coop_level_mode_set_multi();
7774 test_coop_level_surf_create();
7775 test_coop_level_multi_window();
7776 test_clear_rect_count();
7777 test_coop_level_activateapp();
7778 test_unsupported_formats();
7780 test_primary_caps();
7781 test_surface_lock();
7782 test_surface_discard();
7784 test_sysmem_overlay();
7785 test_primary_palette();
7786 test_surface_attachment();
7787 test_pixel_format();
7788 test_create_surface_pitch();
7790 test_palette_complex();
7795 test_palette_alpha();
7797 test_surface_desc_lock();
7798 test_texturemapblend();
7799 test_viewport_clear_rect();
7801 test_colorkey_precision();
7802 test_range_colorkey();