2 * Copyright 2011-2012 Henri Verbeet for CodeWeavers
3 * Copyright 2012-2014 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"
40 struct create_window_thread_param
43 HANDLE window_created
;
44 HANDLE destroy_window
;
48 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
58 if (abs(x
- y
) > ulps
)
64 static BOOL
compare_vec4(struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
66 return compare_float(vec
->x
, x
, ulps
)
67 && compare_float(vec
->y
, y
, ulps
)
68 && compare_float(vec
->z
, z
, ulps
)
69 && compare_float(vec
->w
, w
, ulps
);
72 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
74 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
76 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
78 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
80 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
84 static DWORD WINAPI
create_window_thread_proc(void *param
)
86 struct create_window_thread_param
*p
= param
;
90 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
91 0, 0, 640, 480, 0, 0, 0, 0);
92 ret
= SetEvent(p
->window_created
);
93 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
99 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
100 DispatchMessageA(&msg
);
101 res
= WaitForSingleObject(p
->destroy_window
, 100);
102 if (res
== WAIT_OBJECT_0
)
104 if (res
!= WAIT_TIMEOUT
)
106 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
111 DestroyWindow(p
->window
);
116 static void create_window_thread(struct create_window_thread_param
*p
)
120 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
121 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
122 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
123 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
124 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
125 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
126 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
127 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
130 static void destroy_window_thread(struct create_window_thread_param
*p
)
132 SetEvent(p
->destroy_window
);
133 WaitForSingleObject(p
->thread
, INFINITE
);
134 CloseHandle(p
->destroy_window
);
135 CloseHandle(p
->window_created
);
136 CloseHandle(p
->thread
);
139 static IDirectDrawSurface4
*get_depth_stencil(IDirect3DDevice3
*device
)
141 IDirectDrawSurface4
*rt
, *ret
;
142 DDSCAPS2 caps
= {DDSCAPS_ZBUFFER
, 0, 0, 0};
145 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
146 ok(SUCCEEDED(hr
), "Failed to get the render target, hr %#x.\n", hr
);
147 hr
= IDirectDrawSurface4_GetAttachedSurface(rt
, &caps
, &ret
);
148 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
149 IDirectDrawSurface4_Release(rt
);
153 static HRESULT
set_display_mode(IDirectDraw4
*ddraw
, DWORD width
, DWORD height
)
155 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
157 return IDirectDraw4_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
160 static D3DCOLOR
get_surface_color(IDirectDrawSurface4
*surface
, UINT x
, UINT y
)
162 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
163 DDSURFACEDESC2 surface_desc
;
167 memset(&surface_desc
, 0, sizeof(surface_desc
));
168 surface_desc
.dwSize
= sizeof(surface_desc
);
170 hr
= IDirectDrawSurface4_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
171 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
175 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
177 hr
= IDirectDrawSurface4_Unlock(surface
, &rect
);
178 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
183 static HRESULT CALLBACK
enum_z_fmt(DDPIXELFORMAT
*format
, void *ctx
)
185 DDPIXELFORMAT
*z_fmt
= ctx
;
187 if (U1(*format
).dwZBufferBitDepth
> U1(*z_fmt
).dwZBufferBitDepth
)
193 static IDirectDraw4
*create_ddraw(void)
195 IDirectDraw4
*ddraw4
;
199 if (FAILED(DirectDrawCreate(NULL
, &ddraw1
, NULL
)))
202 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw4
, (void **)&ddraw4
);
203 IDirectDraw_Release(ddraw1
);
210 static IDirect3DDevice3
*create_device(HWND window
, DWORD coop_level
)
212 IDirectDrawSurface4
*surface
, *ds
;
213 IDirect3DDevice3
*device
= NULL
;
214 DDSURFACEDESC2 surface_desc
;
215 IDirectDraw4
*ddraw4
;
220 if (!(ddraw4
= create_ddraw()))
223 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, coop_level
);
224 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
226 memset(&surface_desc
, 0, sizeof(surface_desc
));
227 surface_desc
.dwSize
= sizeof(surface_desc
);
228 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
229 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
230 surface_desc
.dwWidth
= 640;
231 surface_desc
.dwHeight
= 480;
233 hr
= IDirectDraw4_CreateSurface(ddraw4
, &surface_desc
, &surface
, NULL
);
234 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
236 if (coop_level
& DDSCL_NORMAL
)
238 IDirectDrawClipper
*clipper
;
240 hr
= IDirectDraw4_CreateClipper(ddraw4
, 0, &clipper
, NULL
);
241 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
242 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
243 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
244 hr
= IDirectDrawSurface4_SetClipper(surface
, clipper
);
245 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
246 IDirectDrawClipper_Release(clipper
);
249 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirect3D3
, (void **)&d3d3
);
250 IDirectDraw4_Release(ddraw4
);
253 IDirectDrawSurface4_Release(surface
);
257 memset(&z_fmt
, 0, sizeof(z_fmt
));
258 hr
= IDirect3D3_EnumZBufferFormats(d3d3
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
259 if (FAILED(hr
) || !z_fmt
.dwSize
)
261 IDirect3D3_Release(d3d3
);
262 IDirectDrawSurface4_Release(surface
);
266 memset(&surface_desc
, 0, sizeof(surface_desc
));
267 surface_desc
.dwSize
= sizeof(surface_desc
);
268 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
269 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
270 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
271 surface_desc
.dwWidth
= 640;
272 surface_desc
.dwHeight
= 480;
273 hr
= IDirectDraw4_CreateSurface(ddraw4
, &surface_desc
, &ds
, NULL
);
274 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
277 IDirect3D3_Release(d3d3
);
278 IDirectDrawSurface4_Release(surface
);
282 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
283 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
284 IDirectDrawSurface4_Release(ds
);
287 IDirect3D3_Release(d3d3
);
288 IDirectDrawSurface4_Release(surface
);
292 hr
= IDirect3D3_CreateDevice(d3d3
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
293 IDirect3D3_Release(d3d3
);
294 IDirectDrawSurface4_Release(surface
);
301 static IDirect3DViewport3
*create_viewport(IDirect3DDevice3
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
303 IDirect3DViewport3
*viewport
;
308 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
309 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
310 hr
= IDirect3D3_CreateViewport(d3d
, &viewport
, NULL
);
311 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
312 hr
= IDirect3DDevice3_AddViewport(device
, viewport
);
313 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
314 memset(&vp
, 0, sizeof(vp
));
315 vp
.dwSize
= sizeof(vp
);
322 vp
.dvClipWidth
= 2.0f
;
323 vp
.dvClipHeight
= 2.0f
;
326 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp
);
327 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
328 IDirect3D3_Release(d3d
);
333 static void destroy_viewport(IDirect3DDevice3
*device
, IDirect3DViewport3
*viewport
)
337 hr
= IDirect3DDevice3_DeleteViewport(device
, viewport
);
338 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
339 IDirect3DViewport3_Release(viewport
);
342 static IDirect3DMaterial3
*create_material(IDirect3DDevice3
*device
, D3DMATERIAL
*mat
)
344 IDirect3DMaterial3
*material
;
348 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
349 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
350 hr
= IDirect3D3_CreateMaterial(d3d
, &material
, NULL
);
351 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
352 hr
= IDirect3DMaterial3_SetMaterial(material
, mat
);
353 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
354 IDirect3D3_Release(d3d
);
359 static IDirect3DMaterial3
*create_diffuse_material(IDirect3DDevice3
*device
, float r
, float g
, float b
, float a
)
363 memset(&mat
, 0, sizeof(mat
));
364 mat
.dwSize
= sizeof(mat
);
365 U1(U(mat
).diffuse
).r
= r
;
366 U2(U(mat
).diffuse
).g
= g
;
367 U3(U(mat
).diffuse
).b
= b
;
368 U4(U(mat
).diffuse
).a
= a
;
370 return create_material(device
, &mat
);
373 static IDirect3DMaterial3
*create_emissive_material(IDirect3DDevice3
*device
, float r
, float g
, float b
, float a
)
377 memset(&mat
, 0, sizeof(mat
));
378 mat
.dwSize
= sizeof(mat
);
379 U1(U3(mat
).emissive
).r
= r
;
380 U2(U3(mat
).emissive
).g
= g
;
381 U3(U3(mat
).emissive
).b
= b
;
382 U4(U3(mat
).emissive
).a
= a
;
384 return create_material(device
, &mat
);
387 static void destroy_material(IDirect3DMaterial3
*material
)
389 IDirect3DMaterial3_Release(material
);
392 static const UINT
*expect_messages
;
394 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
396 if (expect_messages
&& message
== *expect_messages
)
399 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
402 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
403 * interface. This prevents subsequent SetCooperativeLevel() calls on a
404 * different window from failing with DDERR_HWNDALREADYSET. */
405 static void fix_wndproc(HWND window
, LONG_PTR proc
)
410 if (!(ddraw
= create_ddraw()))
413 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
414 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
415 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
416 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
417 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
419 IDirectDraw4_Release(ddraw
);
422 static void test_process_vertices(void)
424 IDirect3DVertexBuffer
*src_vb
, *dst_vb
;
425 IDirect3DViewport3
*viewport
;
426 D3DVERTEXBUFFERDESC vb_desc
;
427 IDirect3DDevice3
*device
;
428 struct vec3
*src_data
;
429 struct vec4
*dst_data
;
436 static D3DMATRIX identity
=
438 1.0f
, 0.0f
, 0.0f
, 0.0f
,
439 0.0f
, 1.0f
, 0.0f
, 0.0f
,
440 0.0f
, 0.0f
, 1.0f
, 0.0f
,
441 0.0f
, 0.0f
, 0.0f
, 1.0f
,
443 static D3DMATRIX projection
=
445 1.0f
, 0.0f
, 0.0f
, 0.0f
,
446 0.0f
, 1.0f
, 0.0f
, 0.0f
,
447 0.0f
, 0.0f
, 1.0f
, 0.0f
,
448 6.0f
, 7.0f
, 8.0f
, 1.0f
,
451 window
= CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW
,
452 0, 0, 640, 480, 0, 0, 0, 0);
453 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
455 skip("Failed to create a 3D device, skipping test.\n");
456 DestroyWindow(window
);
460 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d3
);
461 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
463 memset(&vb_desc
, 0, sizeof(vb_desc
));
464 vb_desc
.dwSize
= sizeof(vb_desc
);
465 vb_desc
.dwFVF
= D3DFVF_XYZ
;
466 vb_desc
.dwNumVertices
= 3;
467 hr
= IDirect3D3_CreateVertexBuffer(d3d3
, &vb_desc
, &src_vb
, 0, NULL
);
468 ok(SUCCEEDED(hr
), "Failed to create source vertex buffer, hr %#x.\n", hr
);
470 hr
= IDirect3DVertexBuffer_Lock(src_vb
, DDLOCK_WRITEONLY
, (void **)&src_data
, NULL
);
471 ok(SUCCEEDED(hr
), "Failed to lock source vertex buffer, hr %#x.\n", hr
);
472 src_data
[0].x
= -1.0f
;
473 src_data
[0].y
= -1.0f
;
474 src_data
[0].z
= -1.0f
;
475 src_data
[1].x
= 0.0f
;
476 src_data
[1].y
= 0.0f
;
477 src_data
[1].z
= 0.0f
;
478 src_data
[2].x
= 1.0f
;
479 src_data
[2].y
= 1.0f
;
480 src_data
[2].z
= 1.0f
;
481 hr
= IDirect3DVertexBuffer_Unlock(src_vb
);
482 ok(SUCCEEDED(hr
), "Failed to unlock source vertex buffer, hr %#x.\n", hr
);
484 memset(&vb_desc
, 0, sizeof(vb_desc
));
485 vb_desc
.dwSize
= sizeof(vb_desc
);
486 vb_desc
.dwFVF
= D3DFVF_XYZRHW
;
487 vb_desc
.dwNumVertices
= 3;
488 hr
= IDirect3D3_CreateVertexBuffer(d3d3
, &vb_desc
, &dst_vb
, 0, NULL
);
489 ok(SUCCEEDED(hr
), "Failed to create destination vertex buffer, hr %#x.\n", hr
);
491 hr
= IDirect3D3_CreateViewport(d3d3
, &viewport
, NULL
);
492 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
493 hr
= IDirect3DDevice3_AddViewport(device
, viewport
);
494 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
495 vp2
.dwSize
= sizeof(vp2
);
502 vp2
.dvClipWidth
= 4.0f
;
503 vp2
.dvClipHeight
= 5.0f
;
506 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp2
);
507 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
508 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
509 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
511 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &identity
);
512 ok(SUCCEEDED(hr
), "Failed to set world transformation, hr %#x.\n", hr
);
513 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &identity
);
514 ok(SUCCEEDED(hr
), "Failed to set view transformation, hr %#x.\n", hr
);
515 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &identity
);
516 ok(SUCCEEDED(hr
), "Failed to set projection transformation, hr %#x.\n", hr
);
518 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
519 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
521 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
522 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
523 ok(compare_vec4(&dst_data
[0], -6.500e+1f
, +1.800e+2f
, +2.000e-1f
, +1.000e+0f
, 4096),
524 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
525 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
526 ok(compare_vec4(&dst_data
[1], -4.000e+1f
, +1.400e+2f
, +4.000e-1f
, +1.000e+0f
, 4096),
527 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
528 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
529 ok(compare_vec4(&dst_data
[2], -1.500e+1f
, +1.000e+2f
, +6.000e-1f
, +1.000e+0f
, 4096),
530 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
531 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
532 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
533 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
535 hr
= IDirect3DDevice3_MultiplyTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &projection
);
536 ok(SUCCEEDED(hr
), "Failed to set projection transformation, hr %#x.\n", hr
);
538 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
539 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
541 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
542 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
543 ok(compare_vec4(&dst_data
[0], +8.500e+1f
, -1.000e+2f
, +1.800e+0f
, +1.000e+0f
, 4096),
544 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
545 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
546 ok(compare_vec4(&dst_data
[1], +1.100e+2f
, -1.400e+2f
, +2.000e+0f
, +1.000e+0f
, 4096),
547 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
548 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
549 ok(compare_vec4(&dst_data
[2], +1.350e+2f
, -1.800e+2f
, +2.200e+0f
, +1.000e+0f
, 4096),
550 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
551 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
552 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
553 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
555 vp2
.dwSize
= sizeof(vp2
);
562 vp2
.dvClipWidth
= 2.0f
;
563 vp2
.dvClipHeight
= 4.0f
;
566 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp2
);
567 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
569 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
570 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
572 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
573 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
574 ok(compare_vec4(&dst_data
[0], +7.500e+1f
, +4.000e+1f
, -8.000e-1f
, +1.000e+0f
, 4096),
575 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
576 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
577 ok(compare_vec4(&dst_data
[1], +1.200e+2f
, +2.000e+1f
, -1.000e+0f
, +1.000e+0f
, 4096),
578 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
579 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
580 ok(compare_vec4(&dst_data
[2], +1.650e+2f
, +0.000e+0f
, -1.200e+0f
, +1.000e+0f
, 4096),
581 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
582 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
583 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
584 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
586 vp1
.dwSize
= sizeof(vp1
);
597 hr
= IDirect3DViewport3_SetViewport(viewport
, &vp1
);
598 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
600 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
601 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
603 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
604 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
605 ok(compare_vec4(&dst_data
[0], +1.100e+2f
, +6.800e+1f
, +7.000e+0f
, +1.000e+0f
, 4096),
606 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
607 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
608 ok(compare_vec4(&dst_data
[1], +1.170e+2f
, +6.600e+1f
, +8.000e+0f
, +1.000e+0f
, 4096),
609 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
610 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
611 ok(compare_vec4(&dst_data
[2], +1.240e+2f
, +6.400e+1f
, +9.000e+0f
, +1.000e+0f
, 4096),
612 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
613 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
614 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
615 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
617 hr
= IDirect3DDevice3_DeleteViewport(device
, viewport
);
618 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
620 IDirect3DVertexBuffer_Release(dst_vb
);
621 IDirect3DVertexBuffer_Release(src_vb
);
622 IDirect3DViewport3_Release(viewport
);
623 IDirect3D3_Release(d3d3
);
624 IDirect3DDevice3_Release(device
);
625 DestroyWindow(window
);
628 static void test_coop_level_create_device_window(void)
630 HWND focus_window
, device_window
;
634 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
635 0, 0, 640, 480, 0, 0, 0, 0);
636 ddraw
= create_ddraw();
637 ok(!!ddraw
, "Failed to create a ddraw object.\n");
639 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
640 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
641 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
642 ok(!device_window
, "Unexpected device window found.\n");
643 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
644 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
645 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
646 ok(!device_window
, "Unexpected device window found.\n");
647 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
648 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
649 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
650 ok(!device_window
, "Unexpected device window found.\n");
651 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
652 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
653 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
654 ok(!device_window
, "Unexpected device window found.\n");
655 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
656 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
657 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
658 ok(!device_window
, "Unexpected device window found.\n");
660 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
661 if (broken(hr
== DDERR_INVALIDPARAMS
))
663 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
664 IDirectDraw4_Release(ddraw
);
665 DestroyWindow(focus_window
);
669 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
670 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
671 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
672 ok(!device_window
, "Unexpected device window found.\n");
673 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
674 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
675 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
676 ok(!device_window
, "Unexpected device window found.\n");
678 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
679 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
680 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
681 ok(!device_window
, "Unexpected device window found.\n");
682 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
683 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
684 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
685 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
686 ok(!!device_window
, "Device window not found.\n");
688 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
689 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
690 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
691 ok(!device_window
, "Unexpected device window found.\n");
692 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
693 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
694 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
695 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
696 ok(!!device_window
, "Device window not found.\n");
698 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
699 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
700 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
701 ok(!device_window
, "Unexpected device window found.\n");
702 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
703 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
704 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
705 ok(!device_window
, "Unexpected device window found.\n");
706 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
707 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
708 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
709 ok(!device_window
, "Unexpected device window found.\n");
710 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
711 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
712 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
713 ok(!!device_window
, "Device window not found.\n");
715 IDirectDraw4_Release(ddraw
);
716 DestroyWindow(focus_window
);
719 static void test_clipper_blt(void)
721 IDirectDrawSurface4
*src_surface
, *dst_surface
;
722 RECT client_rect
, src_rect
;
723 IDirectDrawClipper
*clipper
;
724 DDSURFACEDESC2 surface_desc
;
725 unsigned int i
, j
, x
, y
;
736 static const DWORD src_data
[] =
738 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
739 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
740 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
742 static const D3DCOLOR expected1
[] =
744 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
745 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
746 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
747 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
749 /* Nvidia on Windows seems to have an off-by-one error
750 * when processing source rectangles. Our left = 1 and
751 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
752 * read as well, but only for the edge pixels on the
753 * output image. The bug happens on the y axis as well,
754 * but we only read one row there, and all source rows
755 * contain the same data. This bug is not dependent on
756 * the presence of a clipper. */
757 static const D3DCOLOR expected1_broken
[] =
759 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
760 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
761 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
762 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
764 static const D3DCOLOR expected2
[] =
766 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
767 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
768 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
769 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
772 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
773 10, 10, 640, 480, 0, 0, 0, 0);
774 ShowWindow(window
, SW_SHOW
);
775 ddraw
= create_ddraw();
776 ok(!!ddraw
, "Failed to create a ddraw object.\n");
778 ret
= GetClientRect(window
, &client_rect
);
779 ok(ret
, "Failed to get client rect.\n");
780 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
781 ok(ret
, "Failed to map client rect.\n");
783 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
784 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
786 hr
= IDirectDraw4_CreateClipper(ddraw
, 0, &clipper
, NULL
);
787 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
788 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
789 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
790 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
791 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
792 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
793 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
794 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
795 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
796 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
797 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
798 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
799 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
800 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
801 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
802 rgn_data
->rdh
.rcBound
.left
, rgn_data
->rdh
.rcBound
.top
,
803 rgn_data
->rdh
.rcBound
.right
, rgn_data
->rdh
.rcBound
.bottom
,
804 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
805 HeapFree(GetProcessHeap(), 0, rgn_data
);
807 r1
= CreateRectRgn(0, 0, 320, 240);
808 ok(!!r1
, "Failed to create region.\n");
809 r2
= CreateRectRgn(320, 240, 640, 480);
810 ok(!!r2
, "Failed to create region.\n");
811 CombineRgn(r1
, r1
, r2
, RGN_OR
);
812 ret
= GetRegionData(r1
, 0, NULL
);
813 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
814 ret
= GetRegionData(r1
, ret
, rgn_data
);
815 ok(!!ret
, "Failed to get region data.\n");
820 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
821 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
822 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
823 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
824 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
825 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
827 HeapFree(GetProcessHeap(), 0, rgn_data
);
829 memset(&surface_desc
, 0, sizeof(surface_desc
));
830 surface_desc
.dwSize
= sizeof(surface_desc
);
831 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
832 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
833 surface_desc
.dwWidth
= 640;
834 surface_desc
.dwHeight
= 480;
835 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
836 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
837 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
838 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
839 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
840 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
842 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
843 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
844 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
845 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
847 memset(&fx
, 0, sizeof(fx
));
848 fx
.dwSize
= sizeof(fx
);
849 hr
= IDirectDrawSurface4_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
850 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
851 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
852 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
854 hr
= IDirectDrawSurface4_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
855 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
856 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
857 ptr
= surface_desc
.lpSurface
;
858 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
859 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
860 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
861 hr
= IDirectDrawSurface4_Unlock(src_surface
, NULL
);
862 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
864 hr
= IDirectDrawSurface4_SetClipper(dst_surface
, clipper
);
865 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
867 SetRect(&src_rect
, 1, 1, 5, 2);
868 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
869 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
870 for (i
= 0; i
< 4; ++i
)
872 for (j
= 0; j
< 4; ++j
)
874 x
= 80 * ((2 * j
) + 1);
875 y
= 60 * ((2 * i
) + 1);
876 color
= get_surface_color(dst_surface
, x
, y
);
877 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
878 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
879 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
883 U5(fx
).dwFillColor
= 0xff0000ff;
884 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
885 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
886 for (i
= 0; i
< 4; ++i
)
888 for (j
= 0; j
< 4; ++j
)
890 x
= 80 * ((2 * j
) + 1);
891 y
= 60 * ((2 * i
) + 1);
892 color
= get_surface_color(dst_surface
, x
, y
);
893 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
894 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
898 hr
= IDirectDrawSurface4_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
899 ok(hr
== DDERR_BLTFASTCANTCLIP
, "Got unexpected hr %#x.\n", hr
);
901 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
902 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
903 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
904 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
905 DestroyWindow(window
);
906 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
907 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
908 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
909 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
910 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
911 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
912 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
913 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
914 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
915 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
916 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
917 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
919 IDirectDrawSurface4_Release(dst_surface
);
920 IDirectDrawSurface4_Release(src_surface
);
921 IDirectDrawClipper_Release(clipper
);
922 IDirectDraw4_Release(ddraw
);
925 static void test_coop_level_d3d_state(void)
927 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
928 IDirectDrawSurface4
*rt
, *surface
;
929 IDirect3DViewport3
*viewport
;
930 IDirect3DDevice3
*device
;
938 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
939 0, 0, 640, 480, 0, 0, 0, 0);
940 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
942 skip("Failed to create a 3D device, skipping test.\n");
943 DestroyWindow(window
);
947 viewport
= create_viewport(device
, 0, 0, 640, 480);
949 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
950 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
951 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
952 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
953 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
954 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
955 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
956 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
957 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
958 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
959 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
960 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
961 color
= get_surface_color(rt
, 320, 240);
962 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
964 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
965 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
966 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
967 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
968 IDirect3D3_Release(d3d
);
969 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
970 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
971 hr
= IDirectDrawSurface4_IsLost(rt
);
972 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
973 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
974 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
975 IDirectDraw4_Release(ddraw
);
977 hr
= IDirect3DDevice3_GetRenderTarget(device
, &surface
);
978 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
979 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
980 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
981 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
982 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
983 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
984 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
985 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
986 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
987 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
988 color
= get_surface_color(rt
, 320, 240);
989 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
991 destroy_viewport(device
, viewport
);
992 IDirectDrawSurface4_Release(surface
);
993 IDirectDrawSurface4_Release(rt
);
994 IDirect3DDevice3_Release(device
);
995 DestroyWindow(window
);
998 static void test_surface_interface_mismatch(void)
1000 IDirectDraw4
*ddraw
= NULL
;
1001 IDirect3D3
*d3d
= NULL
;
1002 IDirectDrawSurface4
*surface
= NULL
, *ds
;
1003 IDirectDrawSurface3
*surface3
= NULL
;
1004 IDirect3DDevice3
*device
= NULL
;
1005 IDirect3DViewport3
*viewport
= NULL
;
1006 DDSURFACEDESC2 surface_desc
;
1007 DDPIXELFORMAT z_fmt
;
1012 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1014 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1015 0, 0, 640, 480, 0, 0, 0, 0);
1016 ddraw
= create_ddraw();
1017 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1018 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
1019 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1021 memset(&surface_desc
, 0, sizeof(surface_desc
));
1022 surface_desc
.dwSize
= sizeof(surface_desc
);
1023 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1024 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
1025 surface_desc
.dwWidth
= 640;
1026 surface_desc
.dwHeight
= 480;
1028 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1029 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1031 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
1032 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr
);
1034 if (FAILED(hr
= IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
)))
1036 skip("D3D interface is not available, skipping test.\n");
1040 memset(&z_fmt
, 0, sizeof(z_fmt
));
1041 hr
= IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
1042 if (FAILED(hr
) || !z_fmt
.dwSize
)
1044 skip("No depth buffer formats available, skipping test.\n");
1048 memset(&surface_desc
, 0, sizeof(surface_desc
));
1049 surface_desc
.dwSize
= sizeof(surface_desc
);
1050 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
1051 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1052 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
1053 surface_desc
.dwWidth
= 640;
1054 surface_desc
.dwHeight
= 480;
1055 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
1056 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
1060 /* Using a different surface interface version still works */
1061 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
1062 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
1063 refcount
= IDirectDrawSurface4_Release(ds
);
1064 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1069 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface4
*)surface3
, &device
, NULL
);
1070 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
1074 viewport
= create_viewport(device
, 0, 0, 640, 480);
1076 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
1077 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1078 color
= get_surface_color(surface
, 320, 240);
1079 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
1083 destroy_viewport(device
, viewport
);
1084 if (surface3
) IDirectDrawSurface3_Release(surface3
);
1085 if (surface
) IDirectDrawSurface4_Release(surface
);
1086 if (device
) IDirect3DDevice3_Release(device
);
1087 if (d3d
) IDirect3D3_Release(d3d
);
1088 if (ddraw
) IDirectDraw4_Release(ddraw
);
1089 DestroyWindow(window
);
1092 static void test_coop_level_threaded(void)
1094 struct create_window_thread_param p
;
1095 IDirectDraw4
*ddraw
;
1098 ddraw
= create_ddraw();
1099 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1100 create_window_thread(&p
);
1102 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1103 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1105 IDirectDraw4_Release(ddraw
);
1106 destroy_window_thread(&p
);
1109 static void test_depth_blit(void)
1118 { -1.0, 1.0, 0.50f
, 0xff00ff00},
1119 { 1.0, 1.0, 0.50f
, 0xff00ff00},
1120 { -1.0, -1.0, 0.50f
, 0xff00ff00},
1121 { 1.0, -1.0, 0.50f
, 0xff00ff00},
1123 static const D3DCOLOR expected_colors
[4][4] =
1125 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1126 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1127 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1128 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1130 DDSURFACEDESC2 ddsd_new
, ddsd_existing
;
1132 IDirect3DDevice3
*device
;
1133 IDirectDrawSurface4
*ds1
, *ds2
, *ds3
, *rt
;
1134 IDirect3DViewport3
*viewport
;
1135 RECT src_rect
, dst_rect
;
1140 IDirectDraw4
*ddraw
;
1145 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1146 0, 0, 640, 480, 0, 0, 0, 0);
1147 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1149 skip("Failed to create a 3D device, skipping test.\n");
1150 DestroyWindow(window
);
1154 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1155 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
1156 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1157 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
1158 IDirect3D3_Release(d3d
);
1160 ds1
= get_depth_stencil(device
);
1162 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1163 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1164 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1165 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1166 hr
= IDirectDrawSurface4_GetSurfaceDesc(ds1
, &ddsd_existing
);
1167 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1168 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1169 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1170 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1171 U4(ddsd_new
).ddpfPixelFormat
= U4(ddsd_existing
).ddpfPixelFormat
;
1172 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1173 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1174 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1175 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1176 IDirectDraw4_Release(ddraw
);
1178 viewport
= create_viewport(device
, 0, 0, ddsd_existing
.dwWidth
, ddsd_existing
.dwHeight
);
1179 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1180 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
1182 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1183 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1184 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1185 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1187 U1(d3drect
).x1
= U2(d3drect
).y1
= 0;
1188 U3(d3drect
).x2
= ddsd_existing
.dwWidth
; U4(d3drect
).y2
= ddsd_existing
.dwHeight
;
1189 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
1190 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1193 SetRect(&src_rect
, 0, 0, 320, 240);
1194 SetRect(&dst_rect
, 0, 0, 320, 240);
1195 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1196 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1197 /* Different locations. */
1198 SetRect(&src_rect
, 0, 0, 320, 240);
1199 SetRect(&dst_rect
, 320, 240, 640, 480);
1200 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1201 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1203 SetRect(&src_rect
, 0, 0, 320, 240);
1204 SetRect(&dst_rect
, 0, 0, 640, 480);
1205 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1206 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1208 SetRect(&src_rect
, 0, 480, 640, 0);
1209 SetRect(&dst_rect
, 0, 0, 640, 480);
1210 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1211 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1212 SetRect(&src_rect
, 0, 0, 640, 480);
1213 SetRect(&dst_rect
, 0, 480, 640, 0);
1214 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1215 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1216 /* Full, explicit. */
1217 SetRect(&src_rect
, 0, 0, 640, 480);
1218 SetRect(&dst_rect
, 0, 0, 640, 480);
1219 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1220 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1221 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1223 /* Depth blit inside a BeginScene / EndScene pair */
1224 hr
= IDirect3DDevice3_BeginScene(device
);
1225 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1226 /* From the current depth stencil */
1227 hr
= IDirectDrawSurface4_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1228 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1229 /* To the current depth stencil */
1230 hr
= IDirectDrawSurface4_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1231 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1232 /* Between unbound surfaces */
1233 hr
= IDirectDrawSurface4_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1234 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1235 hr
= IDirect3DDevice3_EndScene(device
);
1236 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1238 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1239 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1240 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1241 * a reliable result(z = 0.0) */
1242 memset(&fx
, 0, sizeof(fx
));
1243 fx
.dwSize
= sizeof(fx
);
1244 hr
= IDirectDrawSurface4_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1245 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1247 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
, 0xffff0000, 1.0f
, 0);
1248 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1249 SetRect(&dst_rect
, 0, 0, 320, 240);
1250 hr
= IDirectDrawSurface4_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1251 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1252 IDirectDrawSurface4_Release(ds3
);
1253 IDirectDrawSurface4_Release(ds2
);
1254 IDirectDrawSurface4_Release(ds1
);
1256 hr
= IDirect3DDevice3_BeginScene(device
);
1257 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1258 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
1260 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1261 hr
= IDirect3DDevice3_EndScene(device
);
1262 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1264 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1265 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1266 for (i
= 0; i
< 4; ++i
)
1268 for (j
= 0; j
< 4; ++j
)
1270 unsigned int x
= 80 * ((2 * j
) + 1);
1271 unsigned int y
= 60 * ((2 * i
) + 1);
1272 color
= get_surface_color(rt
, x
, y
);
1273 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1274 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1277 IDirectDrawSurface4_Release(rt
);
1279 destroy_viewport(device
, viewport
);
1280 IDirect3DDevice3_Release(device
);
1281 DestroyWindow(window
);
1284 static void test_texture_load_ckey(void)
1286 IDirectDraw4
*ddraw
;
1287 IDirectDrawSurface4
*src
;
1288 IDirectDrawSurface4
*dst
;
1289 IDirect3DTexture2
*src_tex
;
1290 IDirect3DTexture2
*dst_tex
;
1291 DDSURFACEDESC2 ddsd
;
1295 ddraw
= create_ddraw();
1296 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1297 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
1298 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1300 memset(&ddsd
, 0, sizeof(ddsd
));
1301 ddsd
.dwSize
= sizeof(ddsd
);
1302 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1303 ddsd
.dwHeight
= 128;
1305 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1306 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1307 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1308 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1309 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1310 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1312 hr
= IDirectDrawSurface4_QueryInterface(src
, &IID_IDirect3DTexture2
, (void **)&src_tex
);
1313 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr
);
1316 /* 64 bit ddraw does not support d3d */
1317 skip("Could not get Direct3DTexture2 interface, skipping texture::Load color keying tests.\n");
1318 IDirectDrawSurface4_Release(dst
);
1319 IDirectDrawSurface4_Release(src
);
1320 IDirectDraw4_Release(ddraw
);
1323 hr
= IDirectDrawSurface4_QueryInterface(dst
, &IID_IDirect3DTexture2
, (void **)&dst_tex
);
1324 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr
);
1326 /* No surface has a color key */
1327 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1328 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1329 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1330 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1331 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1332 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1333 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1335 /* Source surface has a color key */
1336 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1337 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1338 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1339 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1340 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1341 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1342 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1343 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1344 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1346 /* Both surfaces have a color key: Dest ckey is overwritten */
1347 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1348 hr
= IDirectDrawSurface4_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1349 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1350 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1351 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1352 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1353 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1354 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1355 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1357 /* Only the destination has a color key: It is not deleted */
1358 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1359 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1360 hr
= IDirectDrawSurface4_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1361 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1362 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1363 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1364 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1365 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1366 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1367 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1369 IDirect3DTexture2_Release(dst_tex
);
1370 IDirect3DTexture2_Release(src_tex
);
1371 IDirectDrawSurface4_Release(dst
);
1372 IDirectDrawSurface4_Release(src
);
1373 IDirectDraw4_Release(ddraw
);
1376 static ULONG
get_refcount(IUnknown
*test_iface
)
1378 IUnknown_AddRef(test_iface
);
1379 return IUnknown_Release(test_iface
);
1382 static void test_viewport(void)
1384 IDirectDraw4
*ddraw
;
1386 HRESULT hr
, old_d3d_ref
;
1388 IDirect3DViewport
*viewport
;
1389 IDirect3DViewport2
*viewport2
;
1390 IDirect3DViewport3
*viewport3
, *another_vp
, *test_vp
;
1391 IDirectDrawGammaControl
*gamma
;
1394 IDirect3DDevice3
*device
;
1396 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1397 0, 0, 640, 480, 0, 0, 0, 0);
1398 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1400 skip("Failed to create a 3D device, skipping test.\n");
1401 DestroyWindow(window
);
1404 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1405 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
1406 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1407 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
1408 old_d3d_ref
= get_refcount((IUnknown
*) d3d
);
1410 hr
= IDirect3D3_CreateViewport(d3d
, &viewport3
, NULL
);
1411 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1412 ref
= get_refcount((IUnknown
*)viewport3
);
1413 ok(ref
== 1, "Initial IDirect3DViewport3 refcount is %u\n", ref
);
1414 ref
= get_refcount((IUnknown
*)d3d
);
1415 ok(ref
== old_d3d_ref
, "IDirect3D3 refcount is %u\n", ref
);
1417 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1418 hr
= IDirect3DViewport2_QueryInterface(viewport3
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1419 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
1420 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1421 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1422 /* NULL iid: Segfaults */
1424 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IDirect3DViewport
, (void **)&viewport
);
1425 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport, hr %#x.\n", hr
);
1428 ref
= get_refcount((IUnknown
*)viewport
);
1429 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1430 ref
= get_refcount((IUnknown
*)viewport3
);
1431 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1432 IDirect3DViewport_Release(viewport
);
1436 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IDirect3DViewport3
, (void **)&viewport2
);
1437 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1440 ref
= get_refcount((IUnknown
*)viewport2
);
1441 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1442 ref
= get_refcount((IUnknown
*)viewport3
);
1443 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1444 IDirect3DViewport3_Release(viewport2
);
1447 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IUnknown
, (void **)&unknown
);
1448 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1451 ref
= get_refcount((IUnknown
*)viewport3
);
1452 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1453 ref
= get_refcount(unknown
);
1454 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1455 IUnknown_Release(unknown
);
1458 /* AddViewport(NULL): Segfault */
1459 hr
= IDirect3DDevice3_DeleteViewport(device
, NULL
);
1460 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1461 hr
= IDirect3DDevice3_GetCurrentViewport(device
, NULL
);
1462 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1464 hr
= IDirect3D3_CreateViewport(d3d
, &another_vp
, NULL
);
1465 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1467 /* Setting a viewport not in the viewport list fails */
1468 hr
= IDirect3DDevice3_SetCurrentViewport(device
, another_vp
);
1469 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1471 hr
= IDirect3DDevice3_AddViewport(device
, viewport3
);
1472 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1473 ref
= get_refcount((IUnknown
*) viewport3
);
1474 ok(ref
== 2, "viewport3 refcount is %d\n", ref
);
1475 hr
= IDirect3DDevice3_AddViewport(device
, another_vp
);
1476 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1477 ref
= get_refcount((IUnknown
*) another_vp
);
1478 ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1480 test_vp
= (IDirect3DViewport3
*) 0xbaadc0de;
1481 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1482 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1483 ok(test_vp
== (IDirect3DViewport3
*) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp
);
1485 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport3
);
1486 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1487 ref
= get_refcount((IUnknown
*) viewport3
);
1488 ok(ref
== 3, "viewport3 refcount is %d\n", ref
);
1489 ref
= get_refcount((IUnknown
*) device
);
1490 ok(ref
== 1, "device refcount is %d\n", ref
);
1493 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1494 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1495 ok(test_vp
== viewport3
, "Got unexpected viewport %p\n", test_vp
);
1496 ref
= get_refcount((IUnknown
*) viewport3
);
1497 ok(ref
== 4, "viewport3 refcount is %d\n", ref
);
1498 if(test_vp
) IDirect3DViewport3_Release(test_vp
);
1500 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1502 /* Cannot set the viewport to NULL */
1503 hr
= IDirect3DDevice3_SetCurrentViewport(device
, NULL
);
1504 ok(hr
== DDERR_INVALIDPARAMS
, "Failed to set viewport to NULL, hr %#x.\n", hr
);
1506 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1507 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1508 ok(test_vp
== viewport3
, "Got unexpected viewport %p\n", test_vp
);
1509 if(test_vp
) IDirect3DViewport3_Release(test_vp
);
1511 /* SetCurrentViewport properly releases the old viewport's reference */
1512 hr
= IDirect3DDevice3_SetCurrentViewport(device
, another_vp
);
1513 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1514 ref
= get_refcount((IUnknown
*) viewport3
);
1515 ok(ref
== 2, "viewport3 refcount is %d\n", ref
);
1516 ref
= get_refcount((IUnknown
*) another_vp
);
1517 ok(ref
== 3, "another_vp refcount is %d\n", ref
);
1519 /* Unlike device2::DeleteViewport, device3::DeleteViewport releases the
1520 * reference held by SetCurrentViewport */
1521 hr
= IDirect3DDevice3_DeleteViewport(device
, another_vp
);
1522 ok(SUCCEEDED(hr
), "Failed to delete viewport from device, hr %#x.\n", hr
);
1523 ref
= get_refcount((IUnknown
*) another_vp
);
1524 ok(ref
== 1, "another_vp refcount is %d\n", ref
);
1526 /* GetCurrentViewport still fails */
1528 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1529 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1530 ok(test_vp
== NULL
, "Got unexpected viewport %p\n", test_vp
);
1531 if(test_vp
) IDirect3DViewport3_Release(test_vp
);
1533 /* Setting a different viewport doesn't have any surprises now */
1534 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport3
);
1535 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1536 ref
= get_refcount((IUnknown
*) viewport3
);
1537 ok(ref
== 3, "viewport3 refcount is %d\n", ref
);
1538 ref
= get_refcount((IUnknown
*) another_vp
);
1539 ok(ref
== 1, "another_vp refcount is %d\n", ref
);
1541 /* Destroying the device removes the viewport and releases the reference */
1542 IDirect3DDevice3_Release(device
);
1543 ref
= get_refcount((IUnknown
*) viewport3
);
1544 ok(ref
== 1, "viewport3 refcount is %d\n", ref
);
1546 ref
= IDirect3DViewport3_Release(another_vp
);
1547 ok(ref
== 0, "Got unexpected ref %d\n", ref
);
1548 ref
= IDirect3DViewport3_Release(viewport3
);
1549 ok(ref
== 0, "Got unexpected ref %d\n", ref
);
1550 IDirect3D3_Release(d3d
);
1551 DestroyWindow(window
);
1552 IDirectDraw4_Release(ddraw
);
1555 static void test_zenable(void)
1557 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1560 struct vec4 position
;
1565 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1566 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1567 {{640.0f
, 480.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1568 {{640.0f
, 0.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1570 IDirect3DViewport3
*viewport
;
1571 IDirect3DDevice3
*device
;
1572 IDirectDrawSurface4
*rt
;
1579 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1580 0, 0, 640, 480, 0, 0, 0, 0);
1581 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1583 skip("Failed to create a 3D device, skipping test.\n");
1584 DestroyWindow(window
);
1588 viewport
= create_viewport(device
, 0, 0, 640, 480);
1589 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1590 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1592 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1593 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1595 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 0.0f
, 0);
1596 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1597 hr
= IDirect3DDevice3_BeginScene(device
);
1598 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1599 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, tquad
, 4, 0);
1600 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1601 hr
= IDirect3DDevice3_EndScene(device
);
1602 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1604 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1605 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1606 for (i
= 0; i
< 4; ++i
)
1608 for (j
= 0; j
< 4; ++j
)
1610 x
= 80 * ((2 * j
) + 1);
1611 y
= 60 * ((2 * i
) + 1);
1612 color
= get_surface_color(rt
, x
, y
);
1613 ok(compare_color(color
, 0x0000ff00, 1),
1614 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1617 IDirectDrawSurface4_Release(rt
);
1619 destroy_viewport(device
, viewport
);
1620 IDirect3DDevice3_Release(device
);
1621 DestroyWindow(window
);
1624 static void test_ck_rgba(void)
1626 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1629 struct vec4 position
;
1630 struct vec2 texcoord
;
1634 {{ 0.0f
, 480.0f
, 0.25f
, 1.0f
}, {0.0f
, 0.0f
}},
1635 {{ 0.0f
, 0.0f
, 0.25f
, 1.0f
}, {0.0f
, 1.0f
}},
1636 {{640.0f
, 480.0f
, 0.25f
, 1.0f
}, {1.0f
, 0.0f
}},
1637 {{640.0f
, 0.0f
, 0.25f
, 1.0f
}, {1.0f
, 1.0f
}},
1638 {{ 0.0f
, 480.0f
, 0.75f
, 1.0f
}, {0.0f
, 0.0f
}},
1639 {{ 0.0f
, 0.0f
, 0.75f
, 1.0f
}, {0.0f
, 1.0f
}},
1640 {{640.0f
, 480.0f
, 0.75f
, 1.0f
}, {1.0f
, 0.0f
}},
1641 {{640.0f
, 0.0f
, 0.75f
, 1.0f
}, {1.0f
, 1.0f
}},
1645 D3DCOLOR fill_color
;
1653 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x000000ff},
1654 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x000000ff},
1655 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00},
1656 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00},
1657 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00807f00},
1658 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x0000ff00},
1659 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00},
1660 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00},
1663 IDirectDrawSurface4
*surface
;
1664 IDirect3DViewport3
*viewport
;
1665 DDSURFACEDESC2 surface_desc
;
1666 IDirect3DTexture2
*texture
;
1667 IDirect3DDevice3
*device
;
1668 IDirectDrawSurface4
*rt
;
1669 IDirectDraw4
*ddraw
;
1677 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1678 0, 0, 640, 480, 0, 0, 0, 0);
1679 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1681 skip("Failed to create a 3D device, skipping test.\n");
1682 DestroyWindow(window
);
1686 viewport
= create_viewport(device
, 0, 0, 640, 480);
1687 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1688 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1690 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1691 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1692 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1693 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1694 IDirect3D3_Release(d3d
);
1696 memset(&surface_desc
, 0, sizeof(surface_desc
));
1697 surface_desc
.dwSize
= sizeof(surface_desc
);
1698 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1699 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1700 surface_desc
.dwWidth
= 256;
1701 surface_desc
.dwHeight
= 256;
1702 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1703 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1704 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1705 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1706 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1707 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1708 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1709 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1710 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1711 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1712 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1713 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1714 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1716 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
1717 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1718 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1719 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1720 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1721 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1723 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1724 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1726 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1728 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1729 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1730 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1731 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1733 memset(&fx
, 0, sizeof(fx
));
1734 fx
.dwSize
= sizeof(fx
);
1735 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1736 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1737 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1739 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
,
1740 D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 1.0f
, 0);
1741 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1742 hr
= IDirect3DDevice3_BeginScene(device
);
1743 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1744 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1745 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1746 hr
= IDirect3DDevice3_EndScene(device
);
1747 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1749 color
= get_surface_color(rt
, 320, 240);
1751 todo_wine
ok(compare_color(color
, tests
[i
].result1
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1752 tests
[i
].result1
, i
, color
);
1754 ok(compare_color(color
, tests
[i
].result1
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1755 tests
[i
].result1
, i
, color
);
1757 U5(fx
).dwFillColor
= 0xff0000ff;
1758 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1759 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1761 hr
= IDirect3DDevice3_BeginScene(device
);
1762 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1763 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[4], 4, 0);
1764 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1765 hr
= IDirect3DDevice3_EndScene(device
);
1766 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1768 /* This tests that fragments that are masked out by the color key are
1769 * discarded, instead of just fully transparent. */
1770 color
= get_surface_color(rt
, 320, 240);
1772 todo_wine
ok(compare_color(color
, tests
[i
].result2
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1773 tests
[i
].result2
, i
, color
);
1775 ok(compare_color(color
, tests
[i
].result2
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1776 tests
[i
].result2
, i
, color
);
1779 IDirectDrawSurface4_Release(rt
);
1780 IDirect3DTexture2_Release(texture
);
1781 IDirectDrawSurface4_Release(surface
);
1782 destroy_viewport(device
, viewport
);
1783 IDirectDraw4_Release(ddraw
);
1784 IDirect3DDevice3_Release(device
);
1785 DestroyWindow(window
);
1788 static void test_ck_default(void)
1790 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1793 struct vec4 position
;
1794 struct vec2 texcoord
;
1798 {{ 0.0f
, 480.0f
, 0.0f
, 1.0f
}, {0.0f
, 0.0f
}},
1799 {{ 0.0f
, 0.0f
, 0.0f
, 1.0f
}, {0.0f
, 1.0f
}},
1800 {{640.0f
, 480.0f
, 0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
1801 {{640.0f
, 0.0f
, 0.0f
, 1.0f
}, {1.0f
, 1.0f
}},
1803 IDirectDrawSurface4
*surface
, *rt
;
1804 IDirect3DViewport3
*viewport
;
1805 DDSURFACEDESC2 surface_desc
;
1806 IDirect3DTexture2
*texture
;
1807 IDirect3DDevice3
*device
;
1808 IDirectDraw4
*ddraw
;
1816 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1817 0, 0, 640, 480, 0, 0, 0, 0);
1819 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1821 skip("Failed to create a 3D device, skipping test.\n");
1822 DestroyWindow(window
);
1826 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1827 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1828 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1829 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1830 IDirect3D3_Release(d3d
);
1832 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1833 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1835 viewport
= create_viewport(device
, 0, 0, 640, 480);
1836 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1837 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1839 memset(&surface_desc
, 0, sizeof(surface_desc
));
1840 surface_desc
.dwSize
= sizeof(surface_desc
);
1841 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1842 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1843 surface_desc
.dwWidth
= 256;
1844 surface_desc
.dwHeight
= 256;
1845 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1846 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1847 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1848 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1849 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1850 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1851 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1852 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1853 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1854 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1855 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1856 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1857 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
1858 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1860 memset(&fx
, 0, sizeof(fx
));
1861 fx
.dwSize
= sizeof(fx
);
1862 U5(fx
).dwFillColor
= 0x000000ff;
1863 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1864 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1866 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1867 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1868 hr
= IDirect3DDevice3_BeginScene(device
);
1869 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1870 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1871 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1872 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1873 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1874 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1875 hr
= IDirect3DDevice3_EndScene(device
);
1876 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1877 color
= get_surface_color(rt
, 320, 240);
1878 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1880 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1881 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1882 hr
= IDirect3DDevice3_BeginScene(device
);
1883 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1884 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1885 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1886 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1887 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1888 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1889 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1890 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1891 hr
= IDirect3DDevice3_EndScene(device
);
1892 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1893 color
= get_surface_color(rt
, 320, 240);
1894 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1896 IDirect3DTexture_Release(texture
);
1897 IDirectDrawSurface4_Release(surface
);
1898 destroy_viewport(device
, viewport
);
1899 IDirectDrawSurface4_Release(rt
);
1900 IDirect3DDevice3_Release(device
);
1901 IDirectDraw4_Release(ddraw
);
1902 DestroyWindow(window
);
1905 static void test_ck_complex(void)
1907 IDirectDrawSurface4
*surface
, *mipmap
, *tmp
;
1908 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, 0};
1909 DDSURFACEDESC2 surface_desc
;
1910 IDirect3DDevice3
*device
;
1911 DDCOLORKEY color_key
;
1912 IDirectDraw4
*ddraw
;
1919 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1920 0, 0, 640, 480, 0, 0, 0, 0);
1921 if (!(device
= create_device(window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1923 skip("Failed to create a 3D device, skipping test.\n");
1924 DestroyWindow(window
);
1927 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1928 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1929 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1930 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1931 IDirect3D3_Release(d3d
);
1933 memset(&surface_desc
, 0, sizeof(surface_desc
));
1934 surface_desc
.dwSize
= sizeof(surface_desc
);
1935 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1936 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1937 surface_desc
.dwWidth
= 128;
1938 surface_desc
.dwHeight
= 128;
1939 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1940 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1942 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1943 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1944 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1945 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1946 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1947 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1948 memset(&color_key
, 0, sizeof(color_key
));
1949 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1950 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1951 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1952 color_key
.dwColorSpaceLowValue
);
1953 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1954 color_key
.dwColorSpaceHighValue
);
1957 IDirectDrawSurface_AddRef(mipmap
);
1958 for (i
= 0; i
< 7; ++i
)
1960 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1961 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1963 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1964 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1965 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1966 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1967 hr
= IDirectDrawSurface4_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1968 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x, i %u.\n", hr
, i
);
1969 memset(&color_key
, 0, sizeof(color_key
));
1970 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1971 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x, i %u.\n", hr
, i
);
1972 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1973 color_key
.dwColorSpaceLowValue
, i
);
1974 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1975 color_key
.dwColorSpaceHighValue
, i
);
1977 IDirectDrawSurface_Release(mipmap
);
1981 memset(&color_key
, 0, sizeof(color_key
));
1982 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1983 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1984 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1985 color_key
.dwColorSpaceLowValue
);
1986 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1987 color_key
.dwColorSpaceHighValue
);
1989 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1990 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1991 IDirectDrawSurface_Release(mipmap
);
1992 refcount
= IDirectDrawSurface4_Release(surface
);
1993 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1995 memset(&surface_desc
, 0, sizeof(surface_desc
));
1996 surface_desc
.dwSize
= sizeof(surface_desc
);
1997 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1998 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1999 surface_desc
.dwBackBufferCount
= 1;
2000 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2001 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2003 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2004 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
2005 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
2006 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
2007 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2008 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
2009 memset(&color_key
, 0, sizeof(color_key
));
2010 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2011 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
2012 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2013 color_key
.dwColorSpaceLowValue
);
2014 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2015 color_key
.dwColorSpaceHighValue
);
2017 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &tmp
);
2018 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
2020 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2021 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
2022 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
2023 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
2024 hr
= IDirectDrawSurface4_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2025 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
2026 memset(&color_key
, 0, sizeof(color_key
));
2027 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2028 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
2029 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2030 color_key
.dwColorSpaceLowValue
);
2031 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2032 color_key
.dwColorSpaceHighValue
);
2034 IDirectDrawSurface_Release(tmp
);
2036 refcount
= IDirectDrawSurface4_Release(surface
);
2037 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2038 IDirectDraw4_Release(ddraw
);
2039 refcount
= IDirect3DDevice3_Release(device
);
2040 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2041 DestroyWindow(window
);
2047 REFIID refcount_iid
;
2051 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
2052 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
2054 ULONG refcount
, expected_refcount
;
2055 IUnknown
*iface1
, *iface2
;
2059 for (i
= 0; i
< entry_count
; ++i
)
2061 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
2062 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
2065 for (j
= 0; j
< entry_count
; ++j
)
2067 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
2068 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
2071 expected_refcount
= 0;
2072 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
2073 ++expected_refcount
;
2074 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
2075 ++expected_refcount
;
2076 refcount
= IUnknown_Release(iface2
);
2077 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2078 refcount
, test_name
, i
, j
, expected_refcount
);
2082 expected_refcount
= 0;
2083 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
2084 ++expected_refcount
;
2085 refcount
= IUnknown_Release(iface1
);
2086 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2087 refcount
, test_name
, i
, expected_refcount
);
2092 static void test_surface_qi(void)
2094 static const struct qi_test tests
[] =
2096 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface4
, S_OK
},
2097 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface4
, S_OK
},
2098 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
2099 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2100 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
2101 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
2102 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
2103 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
2104 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
2105 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
2106 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
2107 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
2108 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
2109 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
2110 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
2111 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
2112 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
2113 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
2114 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
2115 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
2116 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
2117 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
2118 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
2119 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
2120 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
2121 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
2122 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
2123 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
2124 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
2125 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
2126 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
2127 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
2128 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
2129 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
2130 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
2133 IDirectDrawSurface4
*surface
;
2134 DDSURFACEDESC2 surface_desc
;
2135 IDirect3DDevice3
*device
;
2136 IDirectDraw4
*ddraw
;
2140 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2142 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2146 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2147 0, 0, 640, 480, 0, 0, 0, 0);
2148 /* Try to create a D3D device to see if the ddraw implementation supports
2149 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2150 * doesn't support e.g. the IDirect3DTexture interfaces. */
2151 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
2153 skip("Failed to create a 3D device, skipping test.\n");
2154 DestroyWindow(window
);
2157 IDirect3DDevice_Release(device
);
2158 ddraw
= create_ddraw();
2159 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2160 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2161 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
2163 memset(&surface_desc
, 0, sizeof(surface_desc
));
2164 surface_desc
.dwSize
= sizeof(surface_desc
);
2165 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2166 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2167 surface_desc
.dwWidth
= 512;
2168 surface_desc
.dwHeight
= 512;
2169 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2170 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2172 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface4
, tests
, sizeof(tests
) / sizeof(*tests
));
2174 IDirectDrawSurface4_Release(surface
);
2175 IDirectDraw4_Release(ddraw
);
2176 DestroyWindow(window
);
2179 static void test_device_qi(void)
2181 static const struct qi_test tests
[] =
2183 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
2184 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
2185 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
2186 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2187 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
2188 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
2189 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
2190 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
2191 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
2192 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
2193 {&IID_IDirect3DDevice3
, &IID_IDirect3DDevice3
, S_OK
},
2194 {&IID_IDirect3DDevice2
, &IID_IDirect3DDevice3
, S_OK
},
2195 {&IID_IDirect3DDevice
, &IID_IDirect3DDevice3
, S_OK
},
2196 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
2197 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
2198 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
2199 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
2200 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
2201 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
2202 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
2203 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
2204 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
2205 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
2206 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
2207 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
2208 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
2209 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
2210 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
2211 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
2212 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
2213 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
2214 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
2215 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
2216 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
2217 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
2218 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
2219 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
2220 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
2221 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
2222 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
2223 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
2224 {&IID_IUnknown
, &IID_IDirect3DDevice3
, S_OK
},
2227 IDirect3DDevice3
*device
;
2230 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2231 0, 0, 640, 480, 0, 0, 0, 0);
2232 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
2234 skip("Failed to create a 3D device, skipping test.\n");
2235 DestroyWindow(window
);
2239 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice3
, tests
, sizeof(tests
) / sizeof(*tests
));
2241 IDirect3DDevice3_Release(device
);
2242 DestroyWindow(window
);
2245 static void test_wndproc(void)
2247 LONG_PTR proc
, ddraw_proc
;
2248 IDirectDraw4
*ddraw
;
2254 static const UINT messages
[] =
2256 WM_WINDOWPOSCHANGING
,
2259 WM_WINDOWPOSCHANGING
,
2265 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2266 ddraw
= create_ddraw();
2267 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2269 wc
.lpfnWndProc
= test_proc
;
2270 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2271 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2273 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2274 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2276 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2277 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2278 (LONG_PTR
)test_proc
, proc
);
2279 expect_messages
= messages
;
2280 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2281 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2282 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2283 expect_messages
= NULL
;
2284 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2285 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2286 (LONG_PTR
)test_proc
, proc
);
2287 ref
= IDirectDraw4_Release(ddraw
);
2288 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2289 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2290 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2291 (LONG_PTR
)test_proc
, proc
);
2293 /* DDSCL_NORMAL doesn't. */
2294 ddraw
= create_ddraw();
2295 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2296 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2297 (LONG_PTR
)test_proc
, proc
);
2298 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2299 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2300 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2301 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2302 (LONG_PTR
)test_proc
, proc
);
2303 ref
= IDirectDraw4_Release(ddraw
);
2304 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2305 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2306 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2307 (LONG_PTR
)test_proc
, proc
);
2309 /* The original window proc is only restored by ddraw if the current
2310 * window proc matches the one ddraw set. This also affects switching
2311 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2312 ddraw
= create_ddraw();
2313 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2314 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2315 (LONG_PTR
)test_proc
, proc
);
2316 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2317 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2318 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2319 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2320 (LONG_PTR
)test_proc
, proc
);
2322 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2323 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2324 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2325 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2326 (LONG_PTR
)test_proc
, proc
);
2327 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2328 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2329 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2330 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2331 (LONG_PTR
)test_proc
, proc
);
2332 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2333 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2334 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2335 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2336 (LONG_PTR
)DefWindowProcA
, proc
);
2337 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2338 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2339 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2340 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2341 (LONG_PTR
)DefWindowProcA
, proc
);
2342 ref
= IDirectDraw4_Release(ddraw
);
2343 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2344 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2345 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2346 (LONG_PTR
)test_proc
, proc
);
2348 ddraw
= create_ddraw();
2349 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2350 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2351 (LONG_PTR
)test_proc
, proc
);
2352 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2353 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2354 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2355 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2356 (LONG_PTR
)test_proc
, proc
);
2357 ref
= IDirectDraw4_Release(ddraw
);
2358 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2359 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2360 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2361 (LONG_PTR
)DefWindowProcA
, proc
);
2363 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2364 expect_messages
= NULL
;
2365 DestroyWindow(window
);
2366 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2369 static void test_window_style(void)
2371 LONG style
, exstyle
, tmp
;
2372 RECT fullscreen_rect
, r
;
2373 IDirectDraw4
*ddraw
;
2378 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2379 0, 0, 100, 100, 0, 0, 0, 0);
2380 ddraw
= create_ddraw();
2381 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2383 style
= GetWindowLongA(window
, GWL_STYLE
);
2384 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2385 SetRect(&fullscreen_rect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
2387 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2388 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2390 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2391 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2392 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2393 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2395 GetWindowRect(window
, &r
);
2396 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2397 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2398 r
.left
, r
.top
, r
.right
, r
.bottom
);
2399 GetClientRect(window
, &r
);
2400 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2402 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2403 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2405 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2406 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2407 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2408 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2410 ref
= IDirectDraw4_Release(ddraw
);
2411 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2413 DestroyWindow(window
);
2416 static void test_redundant_mode_set(void)
2418 DDSURFACEDESC2 surface_desc
= {0};
2419 IDirectDraw4
*ddraw
;
2425 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2426 0, 0, 100, 100, 0, 0, 0, 0);
2427 ddraw
= create_ddraw();
2428 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2430 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2431 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2433 surface_desc
.dwSize
= sizeof(surface_desc
);
2434 hr
= IDirectDraw4_GetDisplayMode(ddraw
, &surface_desc
);
2435 ok(SUCCEEDED(hr
), "GetDipslayMode failed, hr %#x.\n", hr
);
2437 hr
= IDirectDraw4_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2438 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2439 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2441 GetWindowRect(window
, &r
);
2444 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2445 GetWindowRect(window
, &s
);
2446 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2447 r
.left
, r
.top
, r
.right
, r
.bottom
,
2448 s
.left
, s
.top
, s
.right
, s
.bottom
);
2450 hr
= IDirectDraw4_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2451 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2452 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2454 GetWindowRect(window
, &s
);
2455 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2456 r
.left
, r
.top
, r
.right
, r
.bottom
,
2457 s
.left
, s
.top
, s
.right
, s
.bottom
);
2459 ref
= IDirectDraw4_Release(ddraw
);
2460 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2462 DestroyWindow(window
);
2465 static SIZE screen_size
, screen_size2
;
2467 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2469 if (message
== WM_SIZE
)
2471 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2472 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2475 return test_proc(hwnd
, message
, wparam
, lparam
);
2478 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2480 if (message
== WM_SIZE
)
2482 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2483 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2486 return test_proc(hwnd
, message
, wparam
, lparam
);
2489 static void test_coop_level_mode_set(void)
2491 IDirectDrawSurface4
*primary
;
2492 RECT fullscreen_rect
, r
, s
;
2493 IDirectDraw4
*ddraw
;
2494 DDSURFACEDESC2 ddsd
;
2496 HWND window
, window2
;
2501 static const UINT exclusive_messages
[] =
2503 WM_WINDOWPOSCHANGING
,
2504 WM_WINDOWPOSCHANGED
,
2510 static const UINT normal_messages
[] =
2516 ddraw
= create_ddraw();
2517 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2519 wc
.lpfnWndProc
= mode_set_proc
;
2520 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2521 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2522 wc
.lpfnWndProc
= mode_set_proc2
;
2523 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2524 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2526 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2527 0, 0, 100, 100, 0, 0, 0, 0);
2528 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2529 0, 0, 100, 100, 0, 0, 0, 0);
2531 SetRect(&fullscreen_rect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
2532 SetRect(&s
, 0, 0, 640, 480);
2534 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2535 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2537 GetWindowRect(window
, &r
);
2538 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2539 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2540 r
.left
, r
.top
, r
.right
, r
.bottom
);
2542 memset(&ddsd
, 0, sizeof(ddsd
));
2543 ddsd
.dwSize
= sizeof(ddsd
);
2544 ddsd
.dwFlags
= DDSD_CAPS
;
2545 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2547 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2548 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2549 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2550 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2551 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2552 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2553 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2554 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2556 GetWindowRect(window
, &r
);
2557 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2558 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2559 r
.left
, r
.top
, r
.right
, r
.bottom
);
2561 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2562 expect_messages
= exclusive_messages
;
2566 hr
= set_display_mode(ddraw
, 640, 480);
2567 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2569 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2570 expect_messages
= NULL
;
2571 ok(screen_size
.cx
== s
.right
&& screen_size
.cy
== s
.bottom
,
2572 "Expected screen size %ux%u, got %ux%u.\n",
2573 s
.right
, s
.bottom
, screen_size
.cx
, screen_size
.cy
);
2575 GetWindowRect(window
, &r
);
2576 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2577 s
.left
, s
.top
, s
.right
, s
.bottom
,
2578 r
.left
, r
.top
, r
.right
, r
.bottom
);
2580 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2581 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2582 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2583 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2584 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2585 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2586 IDirectDrawSurface4_Release(primary
);
2588 memset(&ddsd
, 0, sizeof(ddsd
));
2589 ddsd
.dwSize
= sizeof(ddsd
);
2590 ddsd
.dwFlags
= DDSD_CAPS
;
2591 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2593 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2594 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2595 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2596 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2597 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2598 s
.right
- s
.left
, ddsd
.dwWidth
);
2599 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2600 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2602 GetWindowRect(window
, &r
);
2603 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2604 s
.left
, s
.top
, s
.right
, s
.bottom
,
2605 r
.left
, r
.top
, r
.right
, r
.bottom
);
2607 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2608 expect_messages
= exclusive_messages
;
2612 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2613 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2615 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2616 expect_messages
= NULL
;
2617 ok(screen_size
.cx
== fullscreen_rect
.right
&& screen_size
.cy
== fullscreen_rect
.bottom
,
2618 "Expected screen size %ux%u, got %ux%u.\n",
2619 fullscreen_rect
.right
, fullscreen_rect
.bottom
, screen_size
.cx
, screen_size
.cy
);
2621 GetWindowRect(window
, &r
);
2622 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2623 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2624 r
.left
, r
.top
, r
.right
, r
.bottom
);
2626 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2627 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2628 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2629 s
.right
- s
.left
, ddsd
.dwWidth
);
2630 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2631 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2632 IDirectDrawSurface4_Release(primary
);
2634 memset(&ddsd
, 0, sizeof(ddsd
));
2635 ddsd
.dwSize
= sizeof(ddsd
);
2636 ddsd
.dwFlags
= DDSD_CAPS
;
2637 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2639 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2640 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2641 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2642 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2643 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2644 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2645 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2646 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2648 GetWindowRect(window
, &r
);
2649 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2650 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2651 r
.left
, r
.top
, r
.right
, r
.bottom
);
2653 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2654 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2656 GetWindowRect(window
, &r
);
2657 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2658 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2659 r
.left
, r
.top
, r
.right
, r
.bottom
);
2661 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2662 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2663 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2664 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2665 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2666 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2667 IDirectDrawSurface4_Release(primary
);
2669 memset(&ddsd
, 0, sizeof(ddsd
));
2670 ddsd
.dwSize
= sizeof(ddsd
);
2671 ddsd
.dwFlags
= DDSD_CAPS
;
2672 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2674 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2675 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2676 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2677 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2678 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2679 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2680 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2681 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2683 GetWindowRect(window
, &r
);
2684 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2685 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2686 r
.left
, r
.top
, r
.right
, r
.bottom
);
2688 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2689 expect_messages
= normal_messages
;
2693 hr
= set_display_mode(ddraw
, 640, 480);
2694 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2696 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2697 expect_messages
= NULL
;
2698 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2700 GetWindowRect(window
, &r
);
2701 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2702 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2703 r
.left
, r
.top
, r
.right
, r
.bottom
);
2705 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2706 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2707 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2708 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2709 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2710 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2711 IDirectDrawSurface4_Release(primary
);
2713 memset(&ddsd
, 0, sizeof(ddsd
));
2714 ddsd
.dwSize
= sizeof(ddsd
);
2715 ddsd
.dwFlags
= DDSD_CAPS
;
2716 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2718 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2719 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2720 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2721 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2722 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2723 s
.right
- s
.left
, ddsd
.dwWidth
);
2724 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2725 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2727 GetWindowRect(window
, &r
);
2728 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2729 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2730 r
.left
, r
.top
, r
.right
, r
.bottom
);
2732 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2733 expect_messages
= normal_messages
;
2737 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2738 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2740 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2741 expect_messages
= NULL
;
2742 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2744 GetWindowRect(window
, &r
);
2745 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2746 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2747 r
.left
, r
.top
, r
.right
, r
.bottom
);
2749 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2750 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2751 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2752 s
.right
- s
.left
, ddsd
.dwWidth
);
2753 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2754 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2755 IDirectDrawSurface4_Release(primary
);
2757 memset(&ddsd
, 0, sizeof(ddsd
));
2758 ddsd
.dwSize
= sizeof(ddsd
);
2759 ddsd
.dwFlags
= DDSD_CAPS
;
2760 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2762 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2763 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2764 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2765 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2766 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2767 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2768 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2769 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2771 GetWindowRect(window
, &r
);
2772 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2773 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2774 r
.left
, r
.top
, r
.right
, r
.bottom
);
2776 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2777 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2778 * not DDSCL_FULLSCREEN. */
2779 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2780 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2782 GetWindowRect(window
, &r
);
2783 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2784 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2785 r
.left
, r
.top
, r
.right
, r
.bottom
);
2787 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2788 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2789 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2790 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2791 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2792 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2793 IDirectDrawSurface4_Release(primary
);
2795 memset(&ddsd
, 0, sizeof(ddsd
));
2796 ddsd
.dwSize
= sizeof(ddsd
);
2797 ddsd
.dwFlags
= DDSD_CAPS
;
2798 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2800 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2801 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2802 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2803 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2804 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2805 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2806 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2807 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2809 GetWindowRect(window
, &r
);
2810 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2811 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2812 r
.left
, r
.top
, r
.right
, r
.bottom
);
2814 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2815 expect_messages
= normal_messages
;
2819 hr
= set_display_mode(ddraw
, 640, 480);
2820 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2822 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2823 expect_messages
= NULL
;
2824 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2826 GetWindowRect(window
, &r
);
2827 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2828 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2829 r
.left
, r
.top
, r
.right
, r
.bottom
);
2831 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2832 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2833 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2834 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2835 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2836 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2837 IDirectDrawSurface4_Release(primary
);
2839 memset(&ddsd
, 0, sizeof(ddsd
));
2840 ddsd
.dwSize
= sizeof(ddsd
);
2841 ddsd
.dwFlags
= DDSD_CAPS
;
2842 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2844 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2845 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2846 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2847 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2848 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2849 s
.right
- s
.left
, ddsd
.dwWidth
);
2850 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2851 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2853 GetWindowRect(window
, &r
);
2854 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2855 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2856 r
.left
, r
.top
, r
.right
, r
.bottom
);
2858 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2859 expect_messages
= normal_messages
;
2863 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2864 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2866 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2867 expect_messages
= NULL
;
2868 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2870 GetWindowRect(window
, &r
);
2871 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2872 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2873 r
.left
, r
.top
, r
.right
, r
.bottom
);
2875 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2876 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2877 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2878 s
.right
- s
.left
, ddsd
.dwWidth
);
2879 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2880 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2881 IDirectDrawSurface4_Release(primary
);
2883 memset(&ddsd
, 0, sizeof(ddsd
));
2884 ddsd
.dwSize
= sizeof(ddsd
);
2885 ddsd
.dwFlags
= DDSD_CAPS
;
2886 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2888 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2889 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2890 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2891 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2892 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2893 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2894 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2895 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2896 IDirectDrawSurface4_Release(primary
);
2898 GetWindowRect(window
, &r
);
2899 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2900 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2901 r
.left
, r
.top
, r
.right
, r
.bottom
);
2903 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2904 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2905 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2906 hr
= set_display_mode(ddraw
, 640, 480);
2907 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2909 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2910 expect_messages
= exclusive_messages
;
2914 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2915 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2917 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2918 expect_messages
= NULL
;
2919 ok(screen_size
.cx
== fullscreen_rect
.right
&& screen_size
.cy
== fullscreen_rect
.bottom
,
2920 "Expected screen size %ux%u, got %ux%u.\n",
2921 fullscreen_rect
.right
, fullscreen_rect
.bottom
, screen_size
.cx
, screen_size
.cy
);
2923 GetWindowRect(window
, &r
);
2924 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2925 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2926 r
.left
, r
.top
, r
.right
, r
.bottom
);
2928 memset(&ddsd
, 0, sizeof(ddsd
));
2929 ddsd
.dwSize
= sizeof(ddsd
);
2930 ddsd
.dwFlags
= DDSD_CAPS
;
2931 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2933 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2934 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2935 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2936 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2937 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2938 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2939 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2940 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2941 IDirectDrawSurface_Release(primary
);
2943 /* The screen restore is a property of DDSCL_EXCLUSIVE */
2944 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2945 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2946 hr
= set_display_mode(ddraw
, 640, 480);
2947 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2949 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2950 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2952 memset(&ddsd
, 0, sizeof(ddsd
));
2953 ddsd
.dwSize
= sizeof(ddsd
);
2954 ddsd
.dwFlags
= DDSD_CAPS
;
2955 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2957 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2958 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2959 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2960 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2961 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2962 s
.right
- s
.left
, ddsd
.dwWidth
);
2963 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2964 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2965 IDirectDrawSurface_Release(primary
);
2967 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2968 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2970 /* If the window is changed at the same time, messages are sent to the new window. */
2971 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2972 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2973 hr
= set_display_mode(ddraw
, 640, 480);
2974 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2976 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2977 expect_messages
= exclusive_messages
;
2980 screen_size2
.cx
= 0;
2981 screen_size2
.cy
= 0;
2983 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
2984 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2986 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2987 expect_messages
= NULL
;
2988 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
2989 screen_size
.cx
, screen_size
.cy
);
2990 ok(screen_size2
.cx
== fullscreen_rect
.right
&& screen_size2
.cy
== fullscreen_rect
.bottom
,
2991 "Expected screen size 2 %ux%u, got %ux%u.\n",
2992 fullscreen_rect
.right
, fullscreen_rect
.bottom
, screen_size2
.cx
, screen_size2
.cy
);
2994 GetWindowRect(window
, &r
);
2995 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2996 s
.left
, s
.top
, s
.right
, s
.bottom
,
2997 r
.left
, r
.top
, r
.right
, r
.bottom
);
2998 GetWindowRect(window2
, &r
);
2999 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3000 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
3001 r
.left
, r
.top
, r
.right
, r
.bottom
);
3003 memset(&ddsd
, 0, sizeof(ddsd
));
3004 ddsd
.dwSize
= sizeof(ddsd
);
3005 ddsd
.dwFlags
= DDSD_CAPS
;
3006 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3008 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3009 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3010 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3011 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3012 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
3013 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
3014 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
3015 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
3016 IDirectDrawSurface_Release(primary
);
3018 ref
= IDirectDraw4_Release(ddraw
);
3019 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3021 GetWindowRect(window
, &r
);
3022 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3023 s
.left
, s
.top
, s
.right
, s
.bottom
,
3024 r
.left
, r
.top
, r
.right
, r
.bottom
);
3026 expect_messages
= NULL
;
3027 DestroyWindow(window
);
3028 DestroyWindow(window2
);
3029 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3030 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3033 static void test_coop_level_mode_set_multi(void)
3035 IDirectDraw4
*ddraw1
, *ddraw2
;
3036 UINT orig_w
, orig_h
, w
, h
;
3041 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3042 0, 0, 100, 100, 0, 0, 0, 0);
3043 ddraw1
= create_ddraw();
3044 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3046 orig_w
= GetSystemMetrics(SM_CXSCREEN
);
3047 orig_h
= GetSystemMetrics(SM_CYSCREEN
);
3049 /* With just a single ddraw object, the display mode is restored on
3051 hr
= set_display_mode(ddraw1
, 800, 600);
3052 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3053 w
= GetSystemMetrics(SM_CXSCREEN
);
3054 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3055 h
= GetSystemMetrics(SM_CYSCREEN
);
3056 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3058 ref
= IDirectDraw4_Release(ddraw1
);
3059 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3060 w
= GetSystemMetrics(SM_CXSCREEN
);
3061 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
3062 h
= GetSystemMetrics(SM_CYSCREEN
);
3063 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
3065 /* When there are multiple ddraw objects, the display mode is restored to
3066 * the initial mode, before the first SetDisplayMode() call. */
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 ddraw2
= create_ddraw();
3076 hr
= set_display_mode(ddraw2
, 640, 480);
3077 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3078 w
= GetSystemMetrics(SM_CXSCREEN
);
3079 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3080 h
= GetSystemMetrics(SM_CYSCREEN
);
3081 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3083 ref
= IDirectDraw4_Release(ddraw2
);
3084 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3085 w
= GetSystemMetrics(SM_CXSCREEN
);
3086 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
3087 h
= GetSystemMetrics(SM_CYSCREEN
);
3088 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
3090 ref
= IDirectDraw4_Release(ddraw1
);
3091 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3092 w
= GetSystemMetrics(SM_CXSCREEN
);
3093 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
3094 h
= GetSystemMetrics(SM_CYSCREEN
);
3095 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
3097 /* Regardless of release ordering. */
3098 ddraw1
= create_ddraw();
3099 hr
= set_display_mode(ddraw1
, 800, 600);
3100 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3101 w
= GetSystemMetrics(SM_CXSCREEN
);
3102 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3103 h
= GetSystemMetrics(SM_CYSCREEN
);
3104 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3106 ddraw2
= create_ddraw();
3107 hr
= set_display_mode(ddraw2
, 640, 480);
3108 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3109 w
= GetSystemMetrics(SM_CXSCREEN
);
3110 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3111 h
= GetSystemMetrics(SM_CYSCREEN
);
3112 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3114 ref
= IDirectDraw4_Release(ddraw1
);
3115 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3116 w
= GetSystemMetrics(SM_CXSCREEN
);
3117 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
3118 h
= GetSystemMetrics(SM_CYSCREEN
);
3119 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
3121 ref
= IDirectDraw4_Release(ddraw2
);
3122 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3123 w
= GetSystemMetrics(SM_CXSCREEN
);
3124 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
3125 h
= GetSystemMetrics(SM_CYSCREEN
);
3126 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
3128 /* But only for ddraw objects that called SetDisplayMode(). */
3129 ddraw1
= create_ddraw();
3130 ddraw2
= create_ddraw();
3131 hr
= set_display_mode(ddraw2
, 640, 480);
3132 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3133 w
= GetSystemMetrics(SM_CXSCREEN
);
3134 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3135 h
= GetSystemMetrics(SM_CYSCREEN
);
3136 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3138 ref
= IDirectDraw4_Release(ddraw1
);
3139 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3140 w
= GetSystemMetrics(SM_CXSCREEN
);
3141 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3142 h
= GetSystemMetrics(SM_CYSCREEN
);
3143 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3145 ref
= IDirectDraw4_Release(ddraw2
);
3146 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3147 w
= GetSystemMetrics(SM_CXSCREEN
);
3148 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
3149 h
= GetSystemMetrics(SM_CYSCREEN
);
3150 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
3152 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3153 * restoring the display mode. */
3154 ddraw1
= create_ddraw();
3155 hr
= set_display_mode(ddraw1
, 800, 600);
3156 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3157 w
= GetSystemMetrics(SM_CXSCREEN
);
3158 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3159 h
= GetSystemMetrics(SM_CYSCREEN
);
3160 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3162 ddraw2
= create_ddraw();
3163 hr
= set_display_mode(ddraw2
, 640, 480);
3164 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3165 w
= GetSystemMetrics(SM_CXSCREEN
);
3166 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3167 h
= GetSystemMetrics(SM_CYSCREEN
);
3168 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3170 hr
= IDirectDraw4_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3171 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3173 ref
= IDirectDraw4_Release(ddraw1
);
3174 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3175 w
= GetSystemMetrics(SM_CXSCREEN
);
3176 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3177 h
= GetSystemMetrics(SM_CYSCREEN
);
3178 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3180 ref
= IDirectDraw4_Release(ddraw2
);
3181 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3182 w
= GetSystemMetrics(SM_CXSCREEN
);
3183 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
3184 h
= GetSystemMetrics(SM_CYSCREEN
);
3185 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
3187 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3188 ddraw1
= create_ddraw();
3189 hr
= set_display_mode(ddraw1
, 800, 600);
3190 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3191 w
= GetSystemMetrics(SM_CXSCREEN
);
3192 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3193 h
= GetSystemMetrics(SM_CYSCREEN
);
3194 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3196 hr
= IDirectDraw4_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3197 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3199 ddraw2
= create_ddraw();
3200 hr
= set_display_mode(ddraw2
, 640, 480);
3201 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3203 ref
= IDirectDraw4_Release(ddraw1
);
3204 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3205 w
= GetSystemMetrics(SM_CXSCREEN
);
3206 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
3207 h
= GetSystemMetrics(SM_CYSCREEN
);
3208 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
3210 ref
= IDirectDraw4_Release(ddraw2
);
3211 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3212 w
= GetSystemMetrics(SM_CXSCREEN
);
3213 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
3214 h
= GetSystemMetrics(SM_CYSCREEN
);
3215 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
3217 DestroyWindow(window
);
3220 static void test_initialize(void)
3222 IDirectDraw4
*ddraw
;
3225 ddraw
= create_ddraw();
3226 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3228 hr
= IDirectDraw4_Initialize(ddraw
, NULL
);
3229 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3230 IDirectDraw4_Release(ddraw
);
3233 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw4
, (void **)&ddraw
);
3234 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw4 instance, hr %#x.\n", hr
);
3235 hr
= IDirectDraw4_Initialize(ddraw
, NULL
);
3236 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3237 hr
= IDirectDraw4_Initialize(ddraw
, NULL
);
3238 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3239 IDirectDraw4_Release(ddraw
);
3243 static void test_coop_level_surf_create(void)
3245 IDirectDrawSurface4
*surface
;
3246 IDirectDraw4
*ddraw
;
3247 DDSURFACEDESC2 ddsd
;
3250 ddraw
= create_ddraw();
3251 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3253 memset(&ddsd
, 0, sizeof(ddsd
));
3254 ddsd
.dwSize
= sizeof(ddsd
);
3255 ddsd
.dwFlags
= DDSD_CAPS
;
3256 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3257 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3258 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3260 IDirectDraw4_Release(ddraw
);
3263 static void test_vb_discard(void)
3265 static const struct vec4 quad
[] =
3267 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
3268 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
3269 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
3270 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
3273 IDirect3DDevice3
*device
;
3275 IDirect3DVertexBuffer
*buffer
;
3278 D3DVERTEXBUFFERDESC desc
;
3280 static const unsigned int vbsize
= 16;
3283 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3284 0, 0, 640, 480, 0, 0, 0, 0);
3286 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3288 skip("Failed to create a 3D device, skipping test.\n");
3289 DestroyWindow(window
);
3293 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
3294 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
3296 memset(&desc
, 0, sizeof(desc
));
3297 desc
.dwSize
= sizeof(desc
);
3298 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
3299 desc
.dwFVF
= D3DFVF_XYZRHW
;
3300 desc
.dwNumVertices
= vbsize
;
3301 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0, NULL
);
3302 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3304 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3305 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3306 memcpy(data
, quad
, sizeof(quad
));
3307 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
3308 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3310 hr
= IDirect3DDevice3_BeginScene(device
);
3311 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3312 hr
= IDirect3DDevice3_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
3313 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3314 hr
= IDirect3DDevice3_EndScene(device
);
3315 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3317 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3318 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3319 memset(data
, 0xaa, sizeof(struct vec4
) * vbsize
);
3320 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
3321 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3323 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3324 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3325 for (i
= 0; i
< sizeof(struct vec4
) * vbsize
; i
++)
3327 if (data
[i
] != 0xaa)
3329 ok(FALSE
, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i
, data
[i
]);
3333 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
3334 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3336 IDirect3DVertexBuffer_Release(buffer
);
3337 IDirect3D3_Release(d3d
);
3338 IDirect3DDevice3_Release(device
);
3339 DestroyWindow(window
);
3342 static void test_coop_level_multi_window(void)
3344 HWND window1
, window2
;
3345 IDirectDraw4
*ddraw
;
3348 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3349 0, 0, 640, 480, 0, 0, 0, 0);
3350 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3351 0, 0, 640, 480, 0, 0, 0, 0);
3352 ddraw
= create_ddraw();
3353 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3355 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3356 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3357 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3358 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3359 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3360 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3362 IDirectDraw4_Release(ddraw
);
3363 DestroyWindow(window2
);
3364 DestroyWindow(window1
);
3367 static void test_draw_strided(void)
3369 static struct vec3 position
[] =
3376 static DWORD diffuse
[] =
3378 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3380 static WORD indices
[] =
3385 IDirectDrawSurface4
*rt
;
3386 IDirect3DDevice3
*device
;
3390 D3DDRAWPRIMITIVESTRIDEDDATA strided
;
3391 IDirect3DViewport3
*viewport
;
3392 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3394 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3395 0, 0, 640, 480, 0, 0, 0, 0);
3397 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3399 skip("Failed to create a 3D device, skipping test.\n");
3400 DestroyWindow(window
);
3404 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
3405 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3406 viewport
= create_viewport(device
, 0, 0, 640, 480);
3407 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
3408 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
3409 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
3410 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
3412 hr
= IDirect3DDevice3_BeginScene(device
);
3413 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3415 memset(&strided
, 0x55, sizeof(strided
));
3416 strided
.position
.lpvData
= position
;
3417 strided
.position
.dwStride
= sizeof(*position
);
3418 strided
.diffuse
.lpvData
= diffuse
;
3419 strided
.diffuse
.dwStride
= sizeof(*diffuse
);
3420 hr
= IDirect3DDevice3_DrawIndexedPrimitiveStrided(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
3421 &strided
, 4, indices
, 6, 0);
3422 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3424 hr
= IDirect3DDevice3_EndScene(device
);
3425 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3427 color
= get_surface_color(rt
, 320, 240);
3428 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3430 IDirect3DViewport3_Release(viewport
);
3431 IDirectDrawSurface4_Release(rt
);
3432 IDirect3DDevice3_Release(device
);
3433 DestroyWindow(window
);
3436 static void test_clear_rect_count(void)
3438 IDirectDrawSurface4
*rt
;
3439 IDirect3DDevice3
*device
;
3443 IDirect3DViewport3
*viewport
;
3444 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3446 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3447 0, 0, 640, 480, 0, 0, 0, 0);
3448 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3450 skip("Failed to create a 3D device, skipping test.\n");
3451 DestroyWindow(window
);
3455 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
3456 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3458 viewport
= create_viewport(device
, 0, 0, 640, 480);
3459 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
3460 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
3461 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x00ffffff, 0.0f
, 0);
3462 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
3463 hr
= IDirect3DViewport3_Clear2(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
, 0x00ff0000, 0.0f
, 0);
3464 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
3465 hr
= IDirect3DViewport3_Clear2(viewport
, 0, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 0.0f
, 0);
3466 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
3467 hr
= IDirect3DViewport3_Clear2(viewport
, 1, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 0.0f
, 0);
3468 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
3470 color
= get_surface_color(rt
, 320, 240);
3471 ok(compare_color(color
, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", color
);
3473 IDirect3DViewport3_Release(viewport
);
3474 IDirectDrawSurface4_Release(rt
);
3475 IDirect3DDevice3_Release(device
);
3476 DestroyWindow(window
);
3479 static BOOL
test_mode_restored(IDirectDraw4
*ddraw
, HWND window
)
3481 DDSURFACEDESC2 ddsd1
, ddsd2
;
3484 memset(&ddsd1
, 0, sizeof(ddsd1
));
3485 ddsd1
.dwSize
= sizeof(ddsd1
);
3486 hr
= IDirectDraw4_GetDisplayMode(ddraw
, &ddsd1
);
3487 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3489 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3490 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3491 hr
= set_display_mode(ddraw
, 640, 480);
3492 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3493 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3494 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3496 memset(&ddsd2
, 0, sizeof(ddsd2
));
3497 ddsd2
.dwSize
= sizeof(ddsd2
);
3498 hr
= IDirectDraw4_GetDisplayMode(ddraw
, &ddsd2
);
3499 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3500 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
3501 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3503 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
3506 static void test_coop_level_versions(void)
3512 IDirectDrawSurface
*surface
;
3513 IDirectDraw4
*ddraw4
;
3516 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3517 0, 0, 640, 480, 0, 0, 0, 0);
3519 ddraw4
= create_ddraw();
3520 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
3521 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3522 restored
= test_mode_restored(ddraw4
, window
);
3523 ok(restored
, "Display mode not restored in new ddraw object\n");
3525 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3526 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
3527 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3529 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3530 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3531 restored
= test_mode_restored(ddraw4
, window
);
3532 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3534 /* A successful one does */
3535 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3536 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3537 restored
= test_mode_restored(ddraw4
, window
);
3538 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3540 IDirectDraw_Release(ddraw
);
3541 IDirectDraw4_Release(ddraw4
);
3543 ddraw4
= create_ddraw();
3544 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
3545 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
3546 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3548 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
3549 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3550 restored
= test_mode_restored(ddraw4
, window
);
3551 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3553 IDirectDraw_Release(ddraw
);
3554 IDirectDraw4_Release(ddraw4
);
3556 /* A failing call does not restore the ddraw2+ behavior */
3557 ddraw4
= create_ddraw();
3558 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
3559 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
3560 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3562 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3563 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3564 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3565 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3566 restored
= test_mode_restored(ddraw4
, window
);
3567 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3569 IDirectDraw_Release(ddraw
);
3570 IDirectDraw4_Release(ddraw4
);
3572 /* Neither does a sequence of successful calls with the new interface */
3573 ddraw4
= create_ddraw();
3574 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
3575 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
3576 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3578 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3579 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3580 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3581 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3582 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, DDSCL_NORMAL
);
3583 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3585 restored
= test_mode_restored(ddraw4
, window
);
3586 ok(!restored
, "Display mode restored after ddraw1-ddraw4 SetCooperativeLevel() call sequence\n");
3587 IDirectDraw_Release(ddraw
);
3588 IDirectDraw4_Release(ddraw4
);
3590 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3591 ddraw4
= create_ddraw();
3592 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
3593 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
3594 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3596 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, DDSCL_NORMAL
);
3597 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3599 memset(&ddsd
, 0, sizeof(ddsd
));
3600 ddsd
.dwSize
= sizeof(ddsd
);
3601 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
3602 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
3603 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
3604 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3605 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
3606 IDirectDrawSurface_Release(surface
);
3607 restored
= test_mode_restored(ddraw4
, window
);
3608 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
3610 IDirectDraw_Release(ddraw
);
3611 IDirectDraw4_Release(ddraw4
);
3612 DestroyWindow(window
);
3615 static void test_lighting_interface_versions(void)
3617 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3618 IDirect3DMaterial3
*emissive
;
3619 IDirect3DViewport3
*viewport
;
3620 IDirect3DDevice3
*device
;
3621 IDirectDrawSurface4
*rt
;
3625 D3DMATERIALHANDLE mat_handle
;
3629 static D3DVERTEX quad
[] =
3631 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3632 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3633 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3634 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3637 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
3640 struct vec3 position
;
3642 DWORD diffuse
, specular
;
3646 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3647 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3648 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3649 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3652 static D3DLVERTEX lquad
[] =
3654 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3655 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3656 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3657 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3660 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
3663 struct vec3 position
;
3664 DWORD diffuse
, specular
;
3665 struct vec2 texcoord
;
3669 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3670 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3671 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3672 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3675 static D3DTLVERTEX tlquad
[] =
3677 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3678 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3679 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3680 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3687 DWORD d3drs_lighting
, d3drs_specular
;
3693 /* Lighting is enabled when all of these conditions are met:
3694 * 1) No pretransformed position(D3DFVF_XYZRHW)
3695 * 2) Normals are available (D3DFVF_NORMAL)
3696 * 3) D3DDP_DONOTLIGHT is not set.
3698 * D3DRENDERSTATE_LIGHTING is ignored, it is not defined
3699 * in this d3d version */
3702 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x0000ff00},
3703 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
3704 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3705 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3706 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x0000ff00},
3707 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
3708 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3709 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3712 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, 0, 0x0000ff00},
3713 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, 0, 0x0000ff00},
3714 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3715 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3716 /* The specular color in the vertex is ignored because
3717 * D3DRENDERSTATE_COLORVERTEX is not enabled */
3718 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, 0, 0x0000ff00},
3719 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, 0, 0x0000ff00},
3720 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3721 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3724 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
3725 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x00ff0000},
3726 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3727 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3728 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
3729 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x00ff8080},
3730 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3731 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3734 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, 0, 0x00ff0000},
3735 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, 0, 0x00ff0000},
3736 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3737 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3738 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, 0, 0x00ff8080},
3739 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, 0, 0x00ff8080},
3740 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3741 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3744 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
3745 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
3746 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3747 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3748 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
3749 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
3750 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3751 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3754 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3755 0, 0, 640, 480, 0, 0, 0, 0);
3757 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3759 skip("Failed to create a 3D device, skipping test.\n");
3760 DestroyWindow(window
);
3764 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
3765 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3767 viewport
= create_viewport(device
, 0, 0, 640, 480);
3768 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
3769 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3771 emissive
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
3772 hr
= IDirect3DMaterial3_GetHandle(emissive
, device
, &mat_handle
);
3773 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
3774 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
3775 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
3776 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
3777 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
3779 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
3780 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
3781 ok(rs
== FALSE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs
);
3783 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
3785 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff202020, 0.0f
, 0);
3786 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3788 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
3789 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
3790 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
3791 tests
[i
].d3drs_specular
);
3792 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
3794 hr
= IDirect3DDevice3_BeginScene(device
);
3795 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3796 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
3797 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
3798 hr
= IDirect3DDevice3_EndScene(device
);
3799 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3801 color
= get_surface_color(rt
, 320, 240);
3802 ok(compare_color(color
, tests
[i
].color
, 1),
3803 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3804 color
, tests
[i
].color
, i
);
3807 destroy_material(emissive
);
3808 IDirectDrawSurface4_Release(rt
);
3809 ref
= IDirect3DDevice3_Release(device
);
3810 ok(ref
== 0, "Device not properly released, refcount %u.\n", ref
);
3811 DestroyWindow(window
);
3817 IDirectDraw4
*ddraw
;
3820 } activateapp_testdata
;
3822 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
3824 if (message
== WM_ACTIVATEAPP
)
3826 if (activateapp_testdata
.ddraw
)
3829 activateapp_testdata
.received
= FALSE
;
3830 hr
= IDirectDraw4_SetCooperativeLevel(activateapp_testdata
.ddraw
,
3831 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
3832 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
3833 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3835 activateapp_testdata
.received
= TRUE
;
3838 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
3841 static void test_coop_level_activateapp(void)
3843 IDirectDraw4
*ddraw
;
3847 DDSURFACEDESC2 ddsd
;
3848 IDirectDrawSurface4
*surface
;
3850 ddraw
= create_ddraw();
3851 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3853 wc
.lpfnWndProc
= activateapp_test_proc
;
3854 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
3855 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3857 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3858 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3860 /* Exclusive with window already active. */
3861 SetActiveWindow(window
);
3862 activateapp_testdata
.received
= FALSE
;
3863 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3864 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3865 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
3866 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3867 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3869 /* Exclusive with window not active. */
3870 SetActiveWindow(NULL
);
3871 activateapp_testdata
.received
= FALSE
;
3872 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3873 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3874 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3875 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3876 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3878 /* Normal with window not active, then exclusive with the same window. */
3879 SetActiveWindow(NULL
);
3880 activateapp_testdata
.received
= FALSE
;
3881 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3882 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3883 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3884 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3885 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3886 /* Except in the first SetCooperativeLevel call, Windows XP randomly does not send
3887 * WM_ACTIVATEAPP. Windows 7 sends the message reliably. Mark the XP behavior broken. */
3888 ok(activateapp_testdata
.received
|| broken(!activateapp_testdata
.received
),
3889 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3890 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3891 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3893 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3894 SetActiveWindow(NULL
);
3895 activateapp_testdata
.received
= FALSE
;
3896 activateapp_testdata
.ddraw
= ddraw
;
3897 activateapp_testdata
.window
= window
;
3898 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
3899 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3900 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3901 ok(activateapp_testdata
.received
|| broken(!activateapp_testdata
.received
),
3902 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3903 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3904 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3906 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3907 * succeeding. Another switch to exclusive and back to normal is needed to release the
3908 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3909 * WM_ACTIVATEAPP messages. */
3910 activateapp_testdata
.ddraw
= NULL
;
3911 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3912 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3913 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3914 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3916 /* Setting DDSCL_NORMAL with recursive invocation. */
3917 SetActiveWindow(NULL
);
3918 activateapp_testdata
.received
= FALSE
;
3919 activateapp_testdata
.ddraw
= ddraw
;
3920 activateapp_testdata
.window
= window
;
3921 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
3922 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3923 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3924 ok(activateapp_testdata
.received
|| broken(!activateapp_testdata
.received
),
3925 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3927 /* DDraw is in exlusive mode now. */
3928 memset(&ddsd
, 0, sizeof(ddsd
));
3929 ddsd
.dwSize
= sizeof(ddsd
);
3930 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
3931 ddsd
.dwBackBufferCount
= 1;
3932 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
3933 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3934 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3935 IDirectDrawSurface4_Release(surface
);
3937 /* Recover again, just to be sure. */
3938 activateapp_testdata
.ddraw
= NULL
;
3939 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3940 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3941 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3942 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3944 DestroyWindow(window
);
3945 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3946 IDirectDraw4_Release(ddraw
);
3949 static void test_texturemanage(void)
3951 IDirectDraw4
*ddraw
;
3953 DDSURFACEDESC2 ddsd
;
3954 IDirectDrawSurface4
*surface
;
3956 DDCAPS hal_caps
, hel_caps
;
3957 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
3960 DWORD caps_in
, caps2_in
;
3962 DWORD caps_out
, caps2_out
;
3966 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3968 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3970 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3972 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3974 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DD_OK
,
3975 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
},
3976 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DD_OK
,
3977 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
},
3978 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
3979 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_LOCALVIDMEM
, 0},
3980 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
3981 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0},
3983 {0, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3985 {0, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3987 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3989 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3991 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3993 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3995 {DDSCAPS_VIDEOMEMORY
, 0, DD_OK
,
3996 DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
, 0},
3997 {DDSCAPS_SYSTEMMEMORY
, 0, DD_OK
,
3998 DDSCAPS_SYSTEMMEMORY
, 0},
4001 ddraw
= create_ddraw();
4002 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4003 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4004 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4006 memset(&hal_caps
, 0, sizeof(hal_caps
));
4007 hal_caps
.dwSize
= sizeof(hal_caps
);
4008 memset(&hel_caps
, 0, sizeof(hel_caps
));
4009 hel_caps
.dwSize
= sizeof(hel_caps
);
4010 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, &hel_caps
);
4011 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4012 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
4014 skip("Managed textures not supported, skipping managed texture test.\n");
4015 IDirectDraw4_Release(ddraw
);
4019 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4021 memset(&ddsd
, 0, sizeof(ddsd
));
4022 ddsd
.dwSize
= sizeof(ddsd
);
4023 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4024 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps_in
;
4025 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2_in
;
4029 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4030 ok(hr
== tests
[i
].hr
, "Got unexpected, hr %#x, case %u.\n", hr
, i
);
4034 memset(&ddsd
, 0, sizeof(ddsd
));
4035 ddsd
.dwSize
= sizeof(ddsd
);
4036 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
4037 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4039 ok(ddsd
.ddsCaps
.dwCaps
== tests
[i
].caps_out
,
4040 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4041 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps_out
, ddsd
.ddsCaps
.dwCaps
, i
);
4042 ok(ddsd
.ddsCaps
.dwCaps2
== tests
[i
].caps2_out
,
4043 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4044 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps2_out
, ddsd
.ddsCaps
.dwCaps2
, i
);
4046 IDirectDrawSurface4_Release(surface
);
4049 IDirectDraw4_Release(ddraw
);
4052 #define SUPPORT_DXT1 0x01
4053 #define SUPPORT_DXT2 0x02
4054 #define SUPPORT_DXT3 0x04
4055 #define SUPPORT_DXT4 0x08
4056 #define SUPPORT_DXT5 0x10
4057 #define SUPPORT_YUY2 0x20
4058 #define SUPPORT_UYVY 0x40
4060 static HRESULT WINAPI
test_block_formats_creation_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
4062 DWORD
*supported_fmts
= ctx
;
4064 if (!(fmt
->dwFlags
& DDPF_FOURCC
))
4065 return DDENUMRET_OK
;
4067 switch (fmt
->dwFourCC
)
4069 case MAKEFOURCC('D','X','T','1'):
4070 *supported_fmts
|= SUPPORT_DXT1
;
4072 case MAKEFOURCC('D','X','T','2'):
4073 *supported_fmts
|= SUPPORT_DXT2
;
4075 case MAKEFOURCC('D','X','T','3'):
4076 *supported_fmts
|= SUPPORT_DXT3
;
4078 case MAKEFOURCC('D','X','T','4'):
4079 *supported_fmts
|= SUPPORT_DXT4
;
4081 case MAKEFOURCC('D','X','T','5'):
4082 *supported_fmts
|= SUPPORT_DXT5
;
4084 case MAKEFOURCC('Y','U','Y','2'):
4085 *supported_fmts
|= SUPPORT_YUY2
;
4087 case MAKEFOURCC('U','Y','V','Y'):
4088 *supported_fmts
|= SUPPORT_UYVY
;
4094 return DDENUMRET_OK
;
4097 static void test_block_formats_creation(void)
4099 HRESULT hr
, expect_hr
;
4100 unsigned int i
, j
, w
, h
;
4102 IDirectDraw4
*ddraw
;
4104 IDirect3DDevice3
*device
;
4105 IDirectDrawSurface4
*surface
;
4106 DWORD supported_fmts
= 0, supported_overlay_fmts
= 0;
4107 DWORD num_fourcc_codes
= 0, *fourcc_codes
;
4108 DDSURFACEDESC2 ddsd
;
4116 unsigned int block_width
;
4117 unsigned int block_height
;
4118 BOOL create_size_checked
, overlay
;
4122 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1
, 4, 4, TRUE
, FALSE
},
4123 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2
, 4, 4, TRUE
, FALSE
},
4124 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3
, 4, 4, TRUE
, FALSE
},
4125 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4
, 4, 4, TRUE
, FALSE
},
4126 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5
, 4, 4, TRUE
, FALSE
},
4127 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2
, 2, 1, FALSE
, TRUE
},
4128 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY
, 2, 1, FALSE
, TRUE
},
4138 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4139 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4141 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4142 * Other hw / drivers successfully create those surfaces. Ignore them, this
4143 * suggests that no game uses this, otherwise Nvidia would support it. */
4145 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0,
4146 "videomemory texture", FALSE
4149 DDSCAPS_VIDEOMEMORY
| DDSCAPS_OVERLAY
, 0,
4150 "videomemory overlay", TRUE
4153 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0,
4154 "systemmemory texture", FALSE
4157 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
4158 "managed texture", FALSE
4162 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4163 0, 0, 640, 480, 0, 0, 0, 0);
4165 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4167 skip("Failed to create a 3D device, skipping test.\n");
4168 DestroyWindow(window
);
4172 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
4173 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
4174 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **) &ddraw
);
4175 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
4176 IDirect3D3_Release(d3d
);
4178 hr
= IDirect3DDevice3_EnumTextureFormats(device
, test_block_formats_creation_cb
,
4180 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4182 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
4183 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
4184 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
4185 num_fourcc_codes
* sizeof(*fourcc_codes
));
4188 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
4189 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
4190 for (i
= 0; i
< num_fourcc_codes
; i
++)
4192 for (j
= 0; j
< sizeof(formats
) / sizeof(*formats
); j
++)
4194 if (fourcc_codes
[i
] == formats
[j
].fourcc
)
4195 supported_overlay_fmts
|= formats
[j
].support_flag
;
4198 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
4200 memset(&hal_caps
, 0, sizeof(hal_caps
));
4201 hal_caps
.dwSize
= sizeof(hal_caps
);
4202 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
4203 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4205 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
4207 for (j
= 0; j
< sizeof(types
) / sizeof(*types
); j
++)
4211 if (formats
[i
].overlay
!= types
[j
].overlay
4212 || (types
[j
].overlay
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
)))
4215 if (formats
[i
].overlay
)
4216 support
= supported_overlay_fmts
& formats
[i
].support_flag
;
4218 support
= supported_fmts
& formats
[i
].support_flag
;
4220 for (w
= 1; w
<= 8; w
++)
4222 for (h
= 1; h
<= 8; h
++)
4224 BOOL block_aligned
= TRUE
;
4227 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
4228 block_aligned
= FALSE
;
4230 memset(&ddsd
, 0, sizeof(ddsd
));
4231 ddsd
.dwSize
= sizeof(ddsd
);
4232 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4233 ddsd
.ddsCaps
.dwCaps
= types
[j
].caps
;
4234 ddsd
.ddsCaps
.dwCaps2
= types
[j
].caps2
;
4235 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
4236 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
4237 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
4241 /* TODO: Handle power of two limitations. I cannot test the pow2
4242 * behavior on windows because I have no hardware that doesn't at
4243 * least support np2_conditional. There's probably no HW that
4244 * supports DXTN textures but no conditional np2 textures. */
4245 if (!support
&& !(types
[j
].caps
& DDSCAPS_SYSTEMMEMORY
))
4246 expect_hr
= DDERR_INVALIDPARAMS
;
4247 else if (formats
[i
].create_size_checked
&& !block_aligned
)
4249 expect_hr
= DDERR_INVALIDPARAMS
;
4250 if (!(types
[j
].caps
& DDSCAPS_TEXTURE
))
4256 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4258 todo_wine
ok(hr
== expect_hr
,
4259 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4260 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
4263 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4264 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
4267 IDirectDrawSurface4_Release(surface
);
4274 IDirectDraw4_Release(ddraw
);
4275 IDirect3DDevice3_Release(device
);
4276 DestroyWindow(window
);
4279 struct format_support_check
4281 const DDPIXELFORMAT
*format
;
4285 static HRESULT WINAPI
test_unsupported_formats_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
4287 struct format_support_check
*format
= ctx
;
4289 if (!memcmp(format
->format
, fmt
, sizeof(*fmt
)))
4291 format
->supported
= TRUE
;
4292 return DDENUMRET_CANCEL
;
4295 return DDENUMRET_OK
;
4298 static void test_unsupported_formats(void)
4301 BOOL expect_success
;
4303 IDirectDraw4
*ddraw
;
4305 IDirect3DDevice3
*device
;
4306 IDirectDrawSurface4
*surface
;
4307 DDSURFACEDESC2 ddsd
;
4309 DWORD expected_caps
;
4320 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
4321 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
4327 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4328 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
4332 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
4334 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4335 0, 0, 640, 480, 0, 0, 0, 0);
4337 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4339 skip("Failed to create a 3D device, skipping test.\n");
4340 DestroyWindow(window
);
4344 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
4345 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
4346 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **) &ddraw
);
4347 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
4348 IDirect3D3_Release(d3d
);
4350 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
4352 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
4353 hr
= IDirect3DDevice3_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
4354 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4356 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
4358 memset(&ddsd
, 0, sizeof(ddsd
));
4359 ddsd
.dwSize
= sizeof(ddsd
);
4360 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
4361 U4(ddsd
).ddpfPixelFormat
= formats
[i
].fmt
;
4364 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
4366 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
4367 expect_success
= FALSE
;
4369 expect_success
= TRUE
;
4371 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4372 ok(SUCCEEDED(hr
) == expect_success
,
4373 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4374 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
4378 memset(&ddsd
, 0, sizeof(ddsd
));
4379 ddsd
.dwSize
= sizeof(ddsd
);
4380 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
4381 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4383 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
4384 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4385 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
4386 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4387 else if (check
.supported
)
4388 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4390 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4392 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
4393 "Expected capability %#x, format %s, input cap %#x.\n",
4394 expected_caps
, formats
[i
].name
, caps
[j
]);
4396 IDirectDrawSurface4_Release(surface
);
4400 IDirectDraw4_Release(ddraw
);
4401 IDirect3DDevice3_Release(device
);
4402 DestroyWindow(window
);
4405 static void test_rt_caps(void)
4407 PALETTEENTRY palette_entries
[256];
4408 IDirectDrawPalette
*palette
;
4409 IDirectDraw4
*ddraw
;
4410 DDPIXELFORMAT z_fmt
;
4417 static const DDPIXELFORMAT p8_fmt
=
4419 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4420 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4425 const DDPIXELFORMAT
*pf
;
4428 HRESULT create_device_hr
;
4429 HRESULT set_rt_hr
, alternative_set_rt_hr
;
4435 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4436 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4443 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4444 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4451 DDSCAPS_OFFSCREENPLAIN
,
4452 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4459 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4460 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4461 D3DERR_SURFACENOTINVIDMEM
,
4467 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4468 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4475 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4476 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4484 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4492 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4499 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4500 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4501 D3DERR_SURFACENOTINVIDMEM
,
4507 DDSCAPS_SYSTEMMEMORY
,
4508 DDSCAPS_SYSTEMMEMORY
,
4516 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4523 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4525 DDERR_NOPALETTEATTACHED
,
4531 DDSCAPS_OFFSCREENPLAIN
,
4532 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4539 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4540 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4541 DDERR_NOPALETTEATTACHED
,
4547 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4548 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4555 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
4556 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4558 DDERR_INVALIDPIXELFORMAT
,
4563 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4564 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4566 DDERR_INVALIDPIXELFORMAT
,
4572 DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4579 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4580 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4582 DDERR_INVALIDPIXELFORMAT
,
4587 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4588 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4595 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4596 0, 0, 640, 480, 0, 0, 0, 0);
4597 ddraw
= create_ddraw();
4598 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4599 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4600 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4602 if (FAILED(hr
= IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
)))
4604 skip("D3D interface is not available, skipping test.\n");
4608 memset(&z_fmt
, 0, sizeof(z_fmt
));
4609 hr
= IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
4610 if (FAILED(hr
) || !z_fmt
.dwSize
)
4612 skip("No depth buffer formats available, skipping test.\n");
4613 IDirect3D3_Release(d3d
);
4617 memset(palette_entries
, 0, sizeof(palette_entries
));
4618 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
4619 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
4621 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4623 IDirectDrawSurface4
*surface
, *rt
, *expected_rt
, *tmp
;
4624 DDSURFACEDESC2 surface_desc
;
4625 IDirect3DDevice3
*device
;
4627 memset(&surface_desc
, 0, sizeof(surface_desc
));
4628 surface_desc
.dwSize
= sizeof(surface_desc
);
4629 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4630 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4631 if (test_data
[i
].pf
)
4633 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4634 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
4636 surface_desc
.dwWidth
= 640;
4637 surface_desc
.dwHeight
= 480;
4638 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4639 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4640 i
, test_data
[i
].caps_in
, hr
);
4642 memset(&surface_desc
, 0, sizeof(surface_desc
));
4643 surface_desc
.dwSize
= sizeof(surface_desc
);
4644 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
4645 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4646 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
4647 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4648 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4650 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
4651 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4652 i
, hr
, test_data
[i
].create_device_hr
);
4655 if (hr
== DDERR_NOPALETTEATTACHED
)
4657 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
4658 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
4659 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
4660 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
4661 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4663 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4665 IDirectDrawSurface4_Release(surface
);
4667 memset(&surface_desc
, 0, sizeof(surface_desc
));
4668 surface_desc
.dwSize
= sizeof(surface_desc
);
4669 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4670 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
4671 surface_desc
.dwWidth
= 640;
4672 surface_desc
.dwHeight
= 480;
4673 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4674 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
4676 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
4677 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
4680 memset(&surface_desc
, 0, sizeof(surface_desc
));
4681 surface_desc
.dwSize
= sizeof(surface_desc
);
4682 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4683 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4684 if (test_data
[i
].pf
)
4686 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4687 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
4689 surface_desc
.dwWidth
= 640;
4690 surface_desc
.dwHeight
= 480;
4691 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
4692 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4693 i
, test_data
[i
].caps_in
, hr
);
4695 hr
= IDirect3DDevice3_SetRenderTarget(device
, rt
, 0);
4696 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
4697 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4698 i
, hr
, test_data
[i
].set_rt_hr
);
4699 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
4702 expected_rt
= surface
;
4704 hr
= IDirect3DDevice3_GetRenderTarget(device
, &tmp
);
4705 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
4706 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
4708 IDirectDrawSurface4_Release(tmp
);
4709 IDirectDrawSurface4_Release(rt
);
4710 refcount
= IDirect3DDevice3_Release(device
);
4711 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
4712 refcount
= IDirectDrawSurface4_Release(surface
);
4713 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
4716 IDirectDrawPalette_Release(palette
);
4717 IDirect3D3_Release(d3d
);
4720 refcount
= IDirectDraw4_Release(ddraw
);
4721 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4722 DestroyWindow(window
);
4725 static void test_primary_caps(void)
4727 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4728 IDirectDrawSurface4
*surface
;
4729 DDSURFACEDESC2 surface_desc
;
4730 IDirectDraw4
*ddraw
;
4740 DWORD back_buffer_count
;
4748 DDSCAPS_PRIMARYSURFACE
,
4751 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
4755 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
4762 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
4769 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
4776 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
4783 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
4790 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4797 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4804 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4806 DDERR_NOEXCLUSIVEMODE
,
4810 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4811 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4817 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4818 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4821 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
4824 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4825 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
4831 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4832 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
4839 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4840 0, 0, 640, 480, 0, 0, 0, 0);
4841 ddraw
= create_ddraw();
4842 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4844 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4846 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
4847 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4849 memset(&surface_desc
, 0, sizeof(surface_desc
));
4850 surface_desc
.dwSize
= sizeof(surface_desc
);
4851 surface_desc
.dwFlags
= DDSD_CAPS
;
4852 if (test_data
[i
].back_buffer_count
!= ~0u)
4853 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4854 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4855 surface_desc
.dwBackBufferCount
= test_data
[i
].back_buffer_count
;
4856 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4857 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
4861 memset(&surface_desc
, 0, sizeof(surface_desc
));
4862 surface_desc
.dwSize
= sizeof(surface_desc
);
4863 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
4864 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4865 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
4866 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4867 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4869 IDirectDrawSurface4_Release(surface
);
4872 refcount
= IDirectDraw4_Release(ddraw
);
4873 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4874 DestroyWindow(window
);
4877 static void test_surface_lock(void)
4879 IDirectDraw4
*ddraw
;
4880 IDirect3D3
*d3d
= NULL
;
4881 IDirectDrawSurface4
*surface
;
4885 DDSURFACEDESC2 ddsd
;
4887 DDPIXELFORMAT z_fmt
;
4897 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
4899 "videomemory offscreenplain"
4902 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4904 "systemmemory offscreenplain"
4907 DDSCAPS_PRIMARYSURFACE
,
4912 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
4914 "videomemory texture"
4917 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
4919 "opaque videomemory texture"
4922 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
4924 "systemmemory texture"
4928 DDSCAPS2_TEXTUREMANAGE
,
4933 DDSCAPS2_D3DTEXTUREMANAGE
,
4938 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
4939 "opaque managed texture"
4943 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
4944 "opaque managed texture"
4947 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4958 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4959 0, 0, 640, 480, 0, 0, 0, 0);
4960 ddraw
= create_ddraw();
4961 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4962 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4963 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4965 if (FAILED(hr
= IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
)))
4967 skip("D3D interface is not available, skipping test.\n");
4971 memset(&z_fmt
, 0, sizeof(z_fmt
));
4972 hr
= IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
4973 if (FAILED(hr
) || !z_fmt
.dwSize
)
4975 skip("No depth buffer formats available, skipping test.\n");
4979 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4981 memset(&ddsd
, 0, sizeof(ddsd
));
4982 ddsd
.dwSize
= sizeof(ddsd
);
4983 ddsd
.dwFlags
= DDSD_CAPS
;
4984 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4986 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4990 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
4992 ddsd
.dwFlags
|= DDSD_PIXELFORMAT
;
4993 U4(ddsd
).ddpfPixelFormat
= z_fmt
;
4995 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4996 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
4998 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4999 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5001 memset(&ddsd
, 0, sizeof(ddsd
));
5002 ddsd
.dwSize
= sizeof(ddsd
);
5003 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
5004 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5007 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
5008 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5011 IDirectDrawSurface4_Release(surface
);
5016 IDirect3D3_Release(d3d
);
5017 refcount
= IDirectDraw4_Release(ddraw
);
5018 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5019 DestroyWindow(window
);
5022 static void test_surface_discard(void)
5024 IDirect3DDevice3
*device
;
5026 IDirectDraw4
*ddraw
;
5029 DDSURFACEDESC2 ddsd
;
5030 IDirectDrawSurface4
*surface
, *target
;
5039 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
5040 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
5041 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
5042 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
5043 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
},
5044 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
5045 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
},
5046 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
5050 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5051 0, 0, 640, 480, 0, 0, 0, 0);
5053 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5055 skip("Failed to create a 3D device, skipping test.\n");
5056 DestroyWindow(window
);
5059 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
5060 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5061 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
5062 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5063 hr
= IDirect3DDevice3_GetRenderTarget(device
, &target
);
5064 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
5066 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5070 memset(&ddsd
, 0, sizeof(ddsd
));
5071 ddsd
.dwSize
= sizeof(ddsd
);
5072 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5073 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
5074 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
5077 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5078 ok(SUCCEEDED(hr
), "Failed to create offscreen surface, hr %#x, case %u.\n", hr
, i
);
5080 memset(&ddsd
, 0, sizeof(ddsd
));
5081 ddsd
.dwSize
= sizeof(ddsd
);
5082 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
5083 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5084 addr
= ddsd
.lpSurface
;
5085 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
5086 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5088 memset(&ddsd
, 0, sizeof(ddsd
));
5089 ddsd
.dwSize
= sizeof(ddsd
);
5090 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
5091 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5092 discarded
= ddsd
.lpSurface
!= addr
;
5093 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
5094 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5096 hr
= IDirectDrawSurface4_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
5097 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
5099 memset(&ddsd
, 0, sizeof(ddsd
));
5100 ddsd
.dwSize
= sizeof(ddsd
);
5101 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
5102 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5103 discarded
|= ddsd
.lpSurface
!= addr
;
5104 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
5105 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5107 IDirectDrawSurface4_Release(surface
);
5109 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
5110 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
5111 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
5114 IDirectDrawSurface4_Release(target
);
5115 IDirectDraw4_Release(ddraw
);
5116 IDirect3D3_Release(d3d
);
5117 IDirect3DDevice3_Release(device
);
5118 DestroyWindow(window
);
5121 static void test_flip(void)
5123 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
5124 IDirectDrawSurface4
*primary
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
5125 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, 0};
5126 DDSURFACEDESC2 surface_desc
;
5127 BOOL sysmem_primary
;
5128 IDirectDraw4
*ddraw
;
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");
5140 hr
= set_display_mode(ddraw
, 640, 480);
5141 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
5142 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5143 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5145 memset(&surface_desc
, 0, sizeof(surface_desc
));
5146 surface_desc
.dwSize
= sizeof(surface_desc
);
5147 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
5148 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
5149 surface_desc
.dwBackBufferCount
= 3;
5150 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
5151 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5153 memset(&surface_desc
, 0, sizeof(surface_desc
));
5154 surface_desc
.dwSize
= sizeof(surface_desc
);
5155 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &surface_desc
);
5156 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5157 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
)
5158 == (DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
5159 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5160 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
5162 hr
= IDirectDrawSurface4_GetAttachedSurface(primary
, &caps
, &backbuffer1
);
5163 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5164 memset(&surface_desc
, 0, sizeof(surface_desc
));
5165 surface_desc
.dwSize
= sizeof(surface_desc
);
5166 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer1
, &surface_desc
);
5167 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5168 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
5169 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
| DDSCAPS_BACKBUFFER
),
5170 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5172 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
5173 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5174 memset(&surface_desc
, 0, sizeof(surface_desc
));
5175 surface_desc
.dwSize
= sizeof(surface_desc
);
5176 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer2
, &surface_desc
);
5177 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5178 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
5179 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
5180 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5182 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
5183 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5184 memset(&surface_desc
, 0, sizeof(surface_desc
));
5185 surface_desc
.dwSize
= sizeof(surface_desc
);
5186 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer3
, &surface_desc
);
5187 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5188 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
5189 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
5190 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5192 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
5193 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5194 ok(surface
== primary
, "Got unexpected surface %p, expected %p.\n", surface
, primary
);
5195 IDirectDrawSurface4_Release(surface
);
5197 memset(&surface_desc
, 0, sizeof(surface_desc
));
5198 surface_desc
.dwSize
= sizeof(surface_desc
);
5199 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5200 surface_desc
.ddsCaps
.dwCaps
= 0;
5201 surface_desc
.dwWidth
= 640;
5202 surface_desc
.dwHeight
= 480;
5203 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5204 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5205 hr
= IDirectDrawSurface4_Flip(primary
, surface
, DDFLIP_WAIT
);
5206 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
5207 IDirectDrawSurface4_Release(surface
);
5209 hr
= IDirectDrawSurface4_Flip(primary
, primary
, DDFLIP_WAIT
);
5210 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
5211 hr
= IDirectDrawSurface4_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
5212 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
5213 hr
= IDirectDrawSurface4_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
5214 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
5215 hr
= IDirectDrawSurface4_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
5216 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
5218 memset(&fx
, 0, sizeof(fx
));
5219 fx
.dwSize
= sizeof(fx
);
5220 U5(fx
).dwFillColor
= 0xffff0000;
5221 hr
= IDirectDrawSurface4_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5222 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5223 U5(fx
).dwFillColor
= 0xff00ff00;
5224 hr
= IDirectDrawSurface4_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5225 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5226 U5(fx
).dwFillColor
= 0xff0000ff;
5227 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5228 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5230 hr
= IDirectDrawSurface4_Flip(primary
, NULL
, DDFLIP_WAIT
);
5231 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5232 color
= get_surface_color(backbuffer1
, 320, 240);
5233 /* The testbot seems to just copy the contents of one surface to all the
5234 * others, instead of properly flipping. */
5235 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
5236 "Got unexpected color 0x%08x.\n", color
);
5237 color
= get_surface_color(backbuffer2
, 320, 240);
5238 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
5239 U5(fx
).dwFillColor
= 0xffff0000;
5240 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5241 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5243 hr
= IDirectDrawSurface4_Flip(primary
, NULL
, DDFLIP_WAIT
);
5244 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5245 color
= get_surface_color(backbuffer1
, 320, 240);
5246 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
5247 "Got unexpected color 0x%08x.\n", color
);
5248 color
= get_surface_color(backbuffer2
, 320, 240);
5249 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
5250 U5(fx
).dwFillColor
= 0xff00ff00;
5251 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5252 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5254 hr
= IDirectDrawSurface4_Flip(primary
, NULL
, DDFLIP_WAIT
);
5255 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5256 color
= get_surface_color(backbuffer1
, 320, 240);
5257 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
5258 "Got unexpected color 0x%08x.\n", color
);
5259 color
= get_surface_color(backbuffer2
, 320, 240);
5260 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
5261 U5(fx
).dwFillColor
= 0xff0000ff;
5262 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5263 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5265 hr
= IDirectDrawSurface4_Flip(primary
, backbuffer1
, DDFLIP_WAIT
);
5266 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5267 color
= get_surface_color(backbuffer2
, 320, 240);
5268 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
5269 "Got unexpected color 0x%08x.\n", color
);
5270 color
= get_surface_color(backbuffer3
, 320, 240);
5271 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
5272 U5(fx
).dwFillColor
= 0xffff0000;
5273 hr
= IDirectDrawSurface4_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5274 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5276 hr
= IDirectDrawSurface4_Flip(primary
, backbuffer2
, DDFLIP_WAIT
);
5277 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5278 color
= get_surface_color(backbuffer1
, 320, 240);
5279 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
5280 color
= get_surface_color(backbuffer3
, 320, 240);
5281 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
5282 "Got unexpected color 0x%08x.\n", color
);
5283 U5(fx
).dwFillColor
= 0xff00ff00;
5284 hr
= IDirectDrawSurface4_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5285 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5287 hr
= IDirectDrawSurface4_Flip(primary
, backbuffer3
, DDFLIP_WAIT
);
5288 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5289 color
= get_surface_color(backbuffer1
, 320, 240);
5290 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
5291 "Got unexpected color 0x%08x.\n", color
);
5292 color
= get_surface_color(backbuffer2
, 320, 240);
5293 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
5295 IDirectDrawSurface4_Release(backbuffer3
);
5296 IDirectDrawSurface4_Release(backbuffer2
);
5297 IDirectDrawSurface4_Release(backbuffer1
);
5298 IDirectDrawSurface4_Release(primary
);
5299 refcount
= IDirectDraw4_Release(ddraw
);
5300 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5301 DestroyWindow(window
);
5304 static void reset_ddsd(DDSURFACEDESC2
*ddsd
)
5306 memset(ddsd
, 0, sizeof(*ddsd
));
5307 ddsd
->dwSize
= sizeof(*ddsd
);
5310 static void test_set_surface_desc(void)
5312 IDirectDraw4
*ddraw
;
5315 DDSURFACEDESC2 ddsd
;
5316 IDirectDrawSurface4
*surface
;
5326 invalid_caps_tests
[] =
5328 {DDSCAPS_VIDEOMEMORY
, 0, FALSE
, "videomemory plain"},
5329 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, TRUE
, "systemmemory texture"},
5330 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
, "managed texture"},
5331 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
, "managed texture"},
5332 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
, "systemmemory primary"},
5335 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5336 0, 0, 640, 480, 0, 0, 0, 0);
5337 ddraw
= create_ddraw();
5338 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5339 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5340 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5343 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5346 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5347 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5348 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
5349 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5350 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5351 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5352 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5354 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5355 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5358 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5359 ddsd
.lpSurface
= data
;
5360 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5361 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5363 /* Redundantly setting the same lpSurface is not an error. */
5364 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5365 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5366 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
5367 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5368 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5369 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
5371 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
5372 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5373 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5374 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
5375 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
5376 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5379 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5380 ddsd
.lpSurface
= data
;
5381 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 1);
5382 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
5384 ddsd
.lpSurface
= NULL
;
5385 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5386 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
5388 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, NULL
, 0);
5389 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
5391 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
5392 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5393 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5394 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5395 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
5397 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5398 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5399 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
5401 ddsd
.dwFlags
= DDSD_CAPS
;
5402 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5403 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5405 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
5406 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
5407 ddsd
.lpSurface
= data
;
5408 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5409 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5410 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5411 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5412 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5413 ddsd
.ddsCaps
.dwCaps
= 0;
5414 ddsd
.ddsCaps
.dwCaps2
= 0xdeadbeef;
5415 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5416 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5418 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
5419 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5420 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5421 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5422 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
5424 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5426 ddsd
.dwFlags
= DDSD_HEIGHT
;
5428 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5429 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
5431 ddsd
.lpSurface
= data
;
5432 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
5433 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5434 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5437 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5438 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
5441 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
5442 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
5443 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5444 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5446 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0 */
5448 ddsd
.dwFlags
= DDSD_PITCH
;
5449 U1(ddsd
).lPitch
= 8 * 4;
5450 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5451 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
5453 ddsd
.dwFlags
= DDSD_WIDTH
;
5455 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5456 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
5458 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
5459 ddsd
.lpSurface
= data
;
5460 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5461 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
5463 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
5464 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5465 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
5467 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5468 U1(ddsd
).lPitch
= 16 * 4;
5470 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5471 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5474 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
5475 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5476 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5477 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5478 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
5480 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5482 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5483 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5484 U1(ddsd
).lPitch
= 4 * 4;
5485 ddsd
.lpSurface
= data
;
5486 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5487 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5489 U1(ddsd
).lPitch
= 4;
5490 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5491 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5493 U1(ddsd
).lPitch
= 16 * 4 + 1;
5494 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5495 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5497 U1(ddsd
).lPitch
= 16 * 4 + 3;
5498 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5499 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5501 U1(ddsd
).lPitch
= -4;
5502 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5503 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
5505 U1(ddsd
).lPitch
= 16 * 4;
5506 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5507 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5510 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5511 U1(ddsd
).lPitch
= 0;
5513 ddsd
.lpSurface
= data
;
5514 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5515 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
5517 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5518 U1(ddsd
).lPitch
= 16 * 4;
5520 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5521 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
5523 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5524 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
5525 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5526 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5527 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
5528 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5529 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5530 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5531 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5532 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
5534 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
5535 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5536 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5538 /* Can't set color keys. */
5540 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
5541 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
5542 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
5543 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5544 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5546 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
5547 ddsd
.lpSurface
= data
;
5548 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5549 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5551 IDirectDrawSurface4_Release(surface
);
5553 /* SetSurfaceDesc needs systemmemory surfaces.
5555 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5556 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
5559 ddsd
.dwFlags
= DDSD_CAPS
;
5560 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
5561 ddsd
.ddsCaps
.dwCaps2
= invalid_caps_tests
[i
].caps2
;
5562 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5564 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5567 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5568 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5569 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
5570 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5571 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5572 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5575 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5576 ok(SUCCEEDED(hr
) || hr
== DDERR_NODIRECTDRAWHW
, "Failed to create surface, hr %#x.\n", hr
);
5579 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5580 invalid_caps_tests
[i
].name
);
5585 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5586 ddsd
.lpSurface
= data
;
5587 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5588 if (invalid_caps_tests
[i
].supported
)
5590 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5594 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5595 invalid_caps_tests
[i
].name
, hr
);
5597 /* Check priority of error conditions. */
5598 ddsd
.dwFlags
= DDSD_WIDTH
;
5599 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5600 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5601 invalid_caps_tests
[i
].name
, hr
);
5604 IDirectDrawSurface4_Release(surface
);
5608 ref
= IDirectDraw4_Release(ddraw
);
5609 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5610 DestroyWindow(window
);
5613 static void test_user_memory_getdc(void)
5615 IDirectDraw4
*ddraw
;
5618 DDSURFACEDESC2 ddsd
;
5619 IDirectDrawSurface4
*surface
;
5625 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5626 0, 0, 640, 480, 0, 0, 0, 0);
5627 ddraw
= create_ddraw();
5628 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5630 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5631 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5634 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5637 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5638 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5639 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
5640 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5641 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5642 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5643 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5644 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5645 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5647 memset(data
, 0xaa, sizeof(data
));
5649 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5650 ddsd
.lpSurface
= data
;
5651 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5652 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5654 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
5655 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5656 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
5657 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
5658 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
5659 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5661 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
5662 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
5664 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
5665 ddsd
.lpSurface
= data
;
5668 U1(ddsd
).lPitch
= sizeof(*data
);
5669 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
5670 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5672 memset(data
, 0xaa, sizeof(data
));
5673 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
5674 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5675 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
5676 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
5677 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
5678 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5680 for (y
= 0; y
< 4; y
++)
5682 for (x
= 0; x
< 4; x
++)
5684 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
5685 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5688 ok(data
[y
][x
] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
5692 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5694 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5696 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5698 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5701 IDirectDrawSurface4_Release(surface
);
5702 ref
= IDirectDraw4_Release(ddraw
);
5703 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5704 DestroyWindow(window
);
5707 static void test_sysmem_overlay(void)
5709 IDirectDraw4
*ddraw
;
5712 DDSURFACEDESC2 ddsd
;
5713 IDirectDrawSurface4
*surface
;
5716 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5717 0, 0, 640, 480, 0, 0, 0, 0);
5718 ddraw
= create_ddraw();
5719 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5721 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5722 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5725 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
5728 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
5729 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5730 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5731 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
5732 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5733 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5734 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5735 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5736 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
5738 ref
= IDirectDraw4_Release(ddraw
);
5739 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5740 DestroyWindow(window
);
5743 static void test_primary_palette(void)
5745 DDSCAPS2 surface_caps
= {DDSCAPS_FLIP
, 0, 0, 0};
5746 IDirectDrawSurface4
*primary
, *backbuffer
;
5747 PALETTEENTRY palette_entries
[256];
5748 IDirectDrawPalette
*palette
, *tmp
;
5749 DDSURFACEDESC2 surface_desc
;
5750 IDirectDraw4
*ddraw
;
5756 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5757 0, 0, 640, 480, 0, 0, 0, 0);
5758 ddraw
= create_ddraw();
5759 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5760 if (FAILED(hr
= IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
5762 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5763 IDirectDraw4_Release(ddraw
);
5764 DestroyWindow(window
);
5767 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
5768 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5769 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5771 memset(&surface_desc
, 0, sizeof(surface_desc
));
5772 surface_desc
.dwSize
= sizeof(surface_desc
);
5773 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
5774 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
5775 surface_desc
.dwBackBufferCount
= 1;
5776 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
5777 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5778 hr
= IDirectDrawSurface4_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
5779 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5781 memset(palette_entries
, 0, sizeof(palette_entries
));
5782 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
5783 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5784 refcount
= get_refcount((IUnknown
*)palette
);
5785 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5787 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5788 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5789 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5791 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
5792 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5794 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
5795 * and is generally somewhat broken with respect to 8 bpp / palette
5797 if (SUCCEEDED(IDirectDrawSurface4_GetPalette(backbuffer
, &tmp
)))
5799 win_skip("Broken palette handling detected, skipping tests.\n");
5800 IDirectDrawPalette_Release(tmp
);
5801 IDirectDrawPalette_Release(palette
);
5802 /* The Windows 8 testbot keeps extra references to the primary and
5803 * backbuffer while in 8 bpp mode. */
5804 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
5805 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
5809 refcount
= get_refcount((IUnknown
*)palette
);
5810 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5812 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5813 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5814 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
5815 "Got unexpected palette caps %#x.\n", palette_caps
);
5817 hr
= IDirectDrawSurface4_SetPalette(primary
, NULL
);
5818 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5819 refcount
= get_refcount((IUnknown
*)palette
);
5820 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5822 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5823 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5824 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5826 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
5827 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5828 refcount
= get_refcount((IUnknown
*)palette
);
5829 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5831 hr
= IDirectDrawSurface4_GetPalette(primary
, &tmp
);
5832 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
5833 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
5834 IDirectDrawPalette_Release(tmp
);
5835 hr
= IDirectDrawSurface4_GetPalette(backbuffer
, &tmp
);
5836 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5838 refcount
= IDirectDrawPalette_Release(palette
);
5839 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5840 refcount
= IDirectDrawPalette_Release(palette
);
5841 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5843 /* Note that this only seems to work when the palette is attached to the
5844 * primary surface. When attached to a regular surface, attempting to get
5845 * the palette here will cause an access violation. */
5846 hr
= IDirectDrawSurface4_GetPalette(primary
, &tmp
);
5847 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5850 refcount
= IDirectDrawSurface4_Release(backbuffer
);
5851 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5852 refcount
= IDirectDrawSurface4_Release(primary
);
5853 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5854 refcount
= IDirectDraw4_Release(ddraw
);
5855 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5856 DestroyWindow(window
);
5859 static HRESULT WINAPI
surface_counter(IDirectDrawSurface4
*surface
, DDSURFACEDESC2
*desc
, void *context
)
5861 UINT
*surface_count
= context
;
5864 IDirectDrawSurface_Release(surface
);
5866 return DDENUMRET_OK
;
5869 static void test_surface_attachment(void)
5871 IDirectDrawSurface4
*surface1
, *surface2
, *surface3
, *surface4
;
5872 IDirectDrawSurface
*surface1v1
, *surface2v1
;
5873 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, 0};
5874 DDSURFACEDESC2 surface_desc
;
5875 IDirectDraw4
*ddraw
;
5881 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5882 0, 0, 640, 480, 0, 0, 0, 0);
5883 ddraw
= create_ddraw();
5884 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5885 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5886 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5888 memset(&surface_desc
, 0, sizeof(surface_desc
));
5889 surface_desc
.dwSize
= sizeof(surface_desc
);
5890 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
5891 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
5892 U2(surface_desc
).dwMipMapCount
= 3;
5893 surface_desc
.dwWidth
= 128;
5894 surface_desc
.dwHeight
= 128;
5895 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5896 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5898 hr
= IDirectDrawSurface4_GetAttachedSurface(surface1
, &caps
, &surface2
);
5899 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5900 hr
= IDirectDrawSurface4_GetAttachedSurface(surface2
, &caps
, &surface3
);
5901 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5902 hr
= IDirectDrawSurface4_GetAttachedSurface(surface3
, &caps
, &surface4
);
5903 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5906 IDirectDrawSurface4_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
5907 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5909 IDirectDrawSurface4_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
5910 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5912 IDirectDrawSurface4_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
5913 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
5915 memset(&surface_desc
, 0, sizeof(surface_desc
));
5916 surface_desc
.dwSize
= sizeof(surface_desc
);
5917 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5918 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
5919 surface_desc
.dwWidth
= 16;
5920 surface_desc
.dwHeight
= 16;
5921 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5922 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5924 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
);
5925 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5926 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
5927 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5928 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface4
);
5929 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5930 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface3
);
5931 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5932 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface4
);
5933 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5934 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface2
);
5935 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5937 IDirectDrawSurface4_Release(surface4
);
5939 memset(&surface_desc
, 0, sizeof(surface_desc
));
5940 surface_desc
.dwSize
= sizeof(surface_desc
);
5941 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5942 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5943 surface_desc
.dwWidth
= 16;
5944 surface_desc
.dwHeight
= 16;
5945 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5946 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5948 if (SUCCEEDED(hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
)))
5950 skip("Running on refrast, skipping some tests.\n");
5951 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface4
);
5952 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5956 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5957 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
5958 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5959 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface4
);
5960 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5961 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface3
);
5962 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5963 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface4
);
5964 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5965 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface2
);
5966 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5969 IDirectDrawSurface4_Release(surface4
);
5970 IDirectDrawSurface4_Release(surface3
);
5971 IDirectDrawSurface4_Release(surface2
);
5972 IDirectDrawSurface4_Release(surface1
);
5974 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5975 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5977 /* Try a single primary and two offscreen plain surfaces. */
5978 memset(&surface_desc
, 0, sizeof(surface_desc
));
5979 surface_desc
.dwSize
= sizeof(surface_desc
);
5980 surface_desc
.dwFlags
= DDSD_CAPS
;
5981 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
5982 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5983 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5985 memset(&surface_desc
, 0, sizeof(surface_desc
));
5986 surface_desc
.dwSize
= sizeof(surface_desc
);
5987 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5988 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5989 surface_desc
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
5990 surface_desc
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
5991 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5992 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5994 memset(&surface_desc
, 0, sizeof(surface_desc
));
5995 surface_desc
.dwSize
= sizeof(surface_desc
);
5996 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5997 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5998 surface_desc
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
5999 surface_desc
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
6000 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6001 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6003 /* This one has a different size. */
6004 memset(&surface_desc
, 0, sizeof(surface_desc
));
6005 surface_desc
.dwSize
= sizeof(surface_desc
);
6006 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6007 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6008 surface_desc
.dwWidth
= 128;
6009 surface_desc
.dwHeight
= 128;
6010 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6011 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6013 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
6014 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6015 /* Try the reverse without detaching first. */
6016 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface1
);
6017 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
6018 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
6019 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6021 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface1
);
6022 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6023 /* Try to detach reversed. */
6024 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
6025 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6026 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface2
, 0, surface1
);
6027 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6029 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface3
);
6030 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6031 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface2
, 0, surface3
);
6032 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6034 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
);
6035 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6036 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
6037 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6039 IDirectDrawSurface4_Release(surface4
);
6040 IDirectDrawSurface4_Release(surface3
);
6041 IDirectDrawSurface4_Release(surface2
);
6042 IDirectDrawSurface4_Release(surface1
);
6044 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
6045 memset(&surface_desc
, 0, sizeof(surface_desc
));
6046 surface_desc
.dwSize
= sizeof(surface_desc
);
6047 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6048 surface_desc
.dwWidth
= 64;
6049 surface_desc
.dwHeight
= 64;
6050 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
6051 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6052 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
6053 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
6054 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
6055 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
6056 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
6057 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6058 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6059 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6060 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6062 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
6063 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
6064 U1(U4(surface_desc
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
6065 U3(U4(surface_desc
).ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
6066 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
6067 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6069 hr
= IDirectDrawSurface4_QueryInterface(surface1
, &IID_IDirectDrawSurface
, (void **)&surface1v1
);
6070 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
6071 hr
= IDirectDrawSurface4_QueryInterface(surface2
, &IID_IDirectDrawSurface
, (void **)&surface2v1
);
6072 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
6074 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
6075 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6076 refcount
= get_refcount((IUnknown
*)surface2
);
6077 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6078 refcount
= get_refcount((IUnknown
*)surface2v1
);
6079 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6080 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
6081 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
6082 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
6083 todo_wine
ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6084 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
6085 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
6087 /* Attaching while already attached to other surface. */
6088 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface2
);
6089 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6090 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface3
, 0, surface2
);
6091 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6092 IDirectDrawSurface4_Release(surface3
);
6094 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
6095 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6096 refcount
= get_refcount((IUnknown
*)surface2
);
6097 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6098 refcount
= get_refcount((IUnknown
*)surface2v1
);
6099 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6101 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
6102 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
6103 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6104 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
6105 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
6106 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
6107 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6108 refcount
= IDirectDrawSurface4_Release(surface2
);
6109 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6110 refcount
= IDirectDrawSurface4_Release(surface1
);
6111 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6113 /* Automatic detachment on release. */
6114 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
6115 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6116 refcount
= get_refcount((IUnknown
*)surface2v1
);
6117 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6118 refcount
= IDirectDrawSurface_Release(surface1v1
);
6119 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6120 refcount
= IDirectDrawSurface_Release(surface2v1
);
6121 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6122 refcount
= IDirectDraw4_Release(ddraw
);
6123 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6124 DestroyWindow(window
);
6127 static void test_private_data(void)
6129 IDirectDraw4
*ddraw
;
6130 IDirectDrawSurface4
*surface
, *surface2
;
6131 DDSURFACEDESC2 surface_desc
;
6132 ULONG refcount
, refcount2
, refcount3
;
6134 DWORD size
= sizeof(ptr
);
6137 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, 0};
6138 DWORD data
[] = {1, 2, 3, 4};
6140 static const GUID ddraw_private_data_test_guid
=
6145 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
6147 static const GUID ddraw_private_data_test_guid2
=
6152 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
6155 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6156 0, 0, 640, 480, 0, 0, 0, 0);
6157 ddraw
= create_ddraw();
6158 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6159 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6160 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6162 reset_ddsd(&surface_desc
);
6163 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
6164 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
6165 surface_desc
.dwHeight
= 4;
6166 surface_desc
.dwWidth
= 4;
6167 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6168 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6170 /* NULL pointers are not valid, but don't cause a crash. */
6171 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
,
6172 sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
6173 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6174 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 0, 0);
6175 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6176 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 1, 0);
6177 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6179 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
6180 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6181 0, DDSPD_IUNKNOWNPOINTER
);
6182 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6183 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6184 5, DDSPD_IUNKNOWNPOINTER
);
6185 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6186 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6187 sizeof(ddraw
) * 2, DDSPD_IUNKNOWNPOINTER
);
6188 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6190 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
6191 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
6192 * erases the old content and returns an error. This behavior has
6193 * been fixed in d3d8 and d3d9. Unless an application is found
6194 * that depends on this we don't care about this behavior. */
6195 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6196 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
6197 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6198 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6199 0, DDSPD_IUNKNOWNPOINTER
);
6200 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6202 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
6203 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
6204 hr
= IDirectDrawSurface4_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
6205 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
6207 refcount
= get_refcount((IUnknown
*)ddraw
);
6208 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6209 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
6210 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6211 refcount2
= get_refcount((IUnknown
*)ddraw
);
6212 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
6214 hr
= IDirectDrawSurface4_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
6215 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
6216 refcount2
= get_refcount((IUnknown
*)ddraw
);
6217 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
6219 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6220 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
6221 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6222 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, surface
,
6223 sizeof(surface
), DDSPD_IUNKNOWNPOINTER
);
6224 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6225 refcount2
= get_refcount((IUnknown
*)ddraw
);
6226 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
6228 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6229 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
6230 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6231 size
= 2 * sizeof(ptr
);
6232 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
6233 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
6234 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
6235 refcount2
= get_refcount(ptr
);
6236 /* Object is NOT addref'ed by the getter. */
6237 ok(ptr
== (IUnknown
*)ddraw
, "Returned interface pointer is %p, expected %p.\n", ptr
, ddraw
);
6238 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
6240 ptr
= (IUnknown
*)0xdeadbeef;
6242 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
6243 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
6244 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
6245 size
= 2 * sizeof(ptr
);
6246 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
6247 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6248 ok(size
== 2 * sizeof(ptr
), "Got unexpected size %u.\n", size
);
6250 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
6251 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
6252 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
6253 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
6254 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, NULL
, NULL
);
6255 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6257 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, &ptr
, &size
);
6258 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6259 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
6260 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
6261 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, NULL
);
6262 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6264 refcount3
= IDirectDrawSurface4_Release(surface
);
6265 ok(!refcount3
, "Got unexpected refcount %u.\n", refcount3
);
6267 /* Destroying the surface frees the reference held on the private data. It also frees
6268 * the reference the surface is holding on its creating object. */
6269 refcount2
= get_refcount((IUnknown
*)ddraw
);
6270 ok(refcount2
== refcount
- 1, "Got unexpected refcount %u.\n", refcount2
);
6272 memset(&hal_caps
, 0, sizeof(hal_caps
));
6273 hal_caps
.dwSize
= sizeof(hal_caps
);
6274 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
6275 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6276 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) == (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6278 reset_ddsd(&surface_desc
);
6279 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_MIPMAPCOUNT
;
6280 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6281 surface_desc
.dwHeight
= 4;
6282 surface_desc
.dwWidth
= 4;
6283 U2(surface_desc
).dwMipMapCount
= 2;
6284 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6285 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6286 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &surface2
);
6287 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6289 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, data
, sizeof(data
), 0);
6290 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6291 hr
= IDirectDrawSurface4_GetPrivateData(surface2
, &ddraw_private_data_test_guid
, NULL
, NULL
);
6292 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6294 IDirectDrawSurface4_Release(surface2
);
6295 IDirectDrawSurface4_Release(surface
);
6298 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
6300 refcount
= IDirectDraw4_Release(ddraw
);
6301 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6302 DestroyWindow(window
);
6305 static void test_pixel_format(void)
6307 HWND window
, window2
= NULL
;
6308 HDC hdc
, hdc2
= NULL
;
6310 int format
, test_format
;
6311 PIXELFORMATDESCRIPTOR pfd
;
6312 IDirectDraw4
*ddraw
= NULL
;
6313 IDirectDrawClipper
*clipper
= NULL
;
6314 DDSURFACEDESC2 ddsd
;
6315 IDirectDrawSurface4
*primary
= NULL
;
6319 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
6320 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
6323 skip("Failed to create window\n");
6327 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
6328 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
6330 hdc
= GetDC(window
);
6333 skip("Failed to get DC\n");
6338 hdc2
= GetDC(window2
);
6340 gl
= LoadLibraryA("opengl32.dll");
6341 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6343 format
= GetPixelFormat(hdc
);
6344 ok(format
== 0, "new window has pixel format %d\n", format
);
6346 ZeroMemory(&pfd
, sizeof(pfd
));
6347 pfd
.nSize
= sizeof(pfd
);
6349 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
6350 pfd
.iPixelType
= PFD_TYPE_RGBA
;
6351 pfd
.iLayerType
= PFD_MAIN_PLANE
;
6352 format
= ChoosePixelFormat(hdc
, &pfd
);
6355 skip("no pixel format available\n");
6359 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
6361 skip("failed to set pixel format\n");
6365 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
6367 skip("failed to set pixel format on second window\n");
6370 ReleaseDC(window2
, hdc2
);
6375 ddraw
= create_ddraw();
6376 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6378 test_format
= GetPixelFormat(hdc
);
6379 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6381 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6384 skip("Failed to set cooperative level, hr %#x.\n", hr
);
6388 test_format
= GetPixelFormat(hdc
);
6389 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6393 hr
= IDirectDraw4_CreateClipper(ddraw
, 0, &clipper
, NULL
);
6394 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
6395 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
6396 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
6398 test_format
= GetPixelFormat(hdc
);
6399 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6401 test_format
= GetPixelFormat(hdc2
);
6402 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6405 memset(&ddsd
, 0, sizeof(ddsd
));
6406 ddsd
.dwSize
= sizeof(ddsd
);
6407 ddsd
.dwFlags
= DDSD_CAPS
;
6408 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6410 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
6411 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
6413 test_format
= GetPixelFormat(hdc
);
6414 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6418 test_format
= GetPixelFormat(hdc2
);
6419 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6424 hr
= IDirectDrawSurface4_SetClipper(primary
, clipper
);
6425 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
6427 test_format
= GetPixelFormat(hdc
);
6428 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6430 test_format
= GetPixelFormat(hdc2
);
6431 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6434 memset(&fx
, 0, sizeof(fx
));
6435 fx
.dwSize
= sizeof(fx
);
6436 hr
= IDirectDrawSurface4_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6437 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
6439 test_format
= GetPixelFormat(hdc
);
6440 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6444 test_format
= GetPixelFormat(hdc2
);
6445 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6449 if (primary
) IDirectDrawSurface4_Release(primary
);
6450 if (clipper
) IDirectDrawClipper_Release(clipper
);
6451 if (ddraw
) IDirectDraw4_Release(ddraw
);
6452 if (gl
) FreeLibrary(gl
);
6453 if (hdc
) ReleaseDC(window
, hdc
);
6454 if (hdc2
) ReleaseDC(window2
, hdc2
);
6455 if (window
) DestroyWindow(window
);
6456 if (window2
) DestroyWindow(window2
);
6459 static void test_create_surface_pitch(void)
6461 IDirectDrawSurface4
*surface
;
6462 DDSURFACEDESC2 surface_desc
;
6463 IDirectDraw4
*ddraw
;
6481 {DDSCAPS_VIDEOMEMORY
, 0, 0, DD_OK
,
6483 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
6485 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
6487 {DDSCAPS_VIDEOMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
6489 {DDSCAPS_SYSTEMMEMORY
, 0, 0, DD_OK
,
6491 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
6493 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
6495 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
6497 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
6499 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fe, DDERR_INVALIDPARAMS
,
6501 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fc, DD_OK
,
6503 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0f8, DDERR_INVALIDPARAMS
,
6506 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
;
6508 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6509 0, 0, 640, 480, 0, 0, 0, 0);
6510 ddraw
= create_ddraw();
6511 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6512 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6513 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6515 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
6517 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6519 memset(&surface_desc
, 0, sizeof(surface_desc
));
6520 surface_desc
.dwSize
= sizeof(surface_desc
);
6521 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
6522 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| test_data
[i
].placement
;
6523 surface_desc
.dwWidth
= 63;
6524 surface_desc
.dwHeight
= 63;
6525 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
6526 surface_desc
.lpSurface
= mem
;
6527 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6528 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6529 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6530 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6531 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6532 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6533 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6534 ok(hr
== test_data
[i
].hr
|| (test_data
[i
].placement
== DDSCAPS_VIDEOMEMORY
&& hr
== DDERR_NODIRECTDRAWHW
),
6535 "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
6539 memset(&surface_desc
, 0, sizeof(surface_desc
));
6540 surface_desc
.dwSize
= sizeof(surface_desc
);
6541 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
6542 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
6543 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
6544 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6545 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
6546 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out
,
6547 "Test %u: Got unexpected pitch %u, expected %u.\n",
6548 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out
);
6550 IDirectDrawSurface4_Release(surface
);
6553 HeapFree(GetProcessHeap(), 0, mem
);
6554 refcount
= IDirectDraw4_Release(ddraw
);
6555 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6556 DestroyWindow(window
);
6559 static void test_mipmap_lock(void)
6561 IDirectDrawSurface4
*surface
, *surface2
;
6562 DDSURFACEDESC2 surface_desc
;
6563 IDirectDraw4
*ddraw
;
6567 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, 0};
6570 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6571 0, 0, 640, 480, 0, 0, 0, 0);
6572 ddraw
= create_ddraw();
6573 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6574 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6575 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6577 memset(&hal_caps
, 0, sizeof(hal_caps
));
6578 hal_caps
.dwSize
= sizeof(hal_caps
);
6579 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
6580 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6581 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6583 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
6584 IDirectDraw4_Release(ddraw
);
6585 DestroyWindow(window
);
6589 memset(&surface_desc
, 0, sizeof(surface_desc
));
6590 surface_desc
.dwSize
= sizeof(surface_desc
);
6591 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
6592 surface_desc
.dwWidth
= 4;
6593 surface_desc
.dwHeight
= 4;
6594 U2(surface_desc
).dwMipMapCount
= 2;
6595 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
6596 | DDSCAPS_SYSTEMMEMORY
;
6597 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6598 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6599 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &surface2
);
6600 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6602 memset(&surface_desc
, 0, sizeof(surface_desc
));
6603 surface_desc
.dwSize
= sizeof(surface_desc
);
6604 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
6605 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6606 memset(&surface_desc
, 0, sizeof(surface_desc
));
6607 surface_desc
.dwSize
= sizeof(surface_desc
);
6608 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
6609 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6610 IDirectDrawSurface4_Unlock(surface2
, NULL
);
6611 IDirectDrawSurface4_Unlock(surface
, NULL
);
6613 IDirectDrawSurface4_Release(surface2
);
6614 IDirectDrawSurface4_Release(surface
);
6615 refcount
= IDirectDraw4_Release(ddraw
);
6616 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6617 DestroyWindow(window
);
6620 static void test_palette_complex(void)
6622 IDirectDrawSurface4
*surface
, *mipmap
, *tmp
;
6623 DDSURFACEDESC2 surface_desc
;
6624 IDirectDraw4
*ddraw
;
6625 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
6629 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, 0};
6631 PALETTEENTRY palette_entries
[256];
6637 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6638 0, 0, 640, 480, 0, 0, 0, 0);
6639 ddraw
= create_ddraw();
6640 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6641 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6642 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6644 memset(&hal_caps
, 0, sizeof(hal_caps
));
6645 hal_caps
.dwSize
= sizeof(hal_caps
);
6646 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
6647 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6648 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6650 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
6651 IDirectDraw4_Release(ddraw
);
6652 DestroyWindow(window
);
6656 memset(&surface_desc
, 0, sizeof(surface_desc
));
6657 surface_desc
.dwSize
= sizeof(surface_desc
);
6658 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6659 surface_desc
.dwWidth
= 128;
6660 surface_desc
.dwHeight
= 128;
6661 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6662 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6663 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6664 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
6665 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6666 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6668 memset(palette_entries
, 0, sizeof(palette_entries
));
6669 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6670 palette_entries
, &palette
, NULL
);
6671 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6673 memset(palette_entries
, 0, sizeof(palette_entries
));
6674 palette_entries
[1].peRed
= 0xff;
6675 palette_entries
[1].peGreen
= 0x80;
6676 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6677 palette_entries
, &palette_mipmap
, NULL
);
6678 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6680 palette2
= (void *)0xdeadbeef;
6681 hr
= IDirectDrawSurface4_GetPalette(surface
, &palette2
);
6682 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6683 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
6684 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
6685 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6686 hr
= IDirectDrawSurface4_GetPalette(surface
, &palette2
);
6687 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6688 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
6689 IDirectDrawPalette_Release(palette2
);
6692 IDirectDrawSurface4_AddRef(mipmap
);
6693 for (i
= 0; i
< 7; ++i
)
6695 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6696 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
6697 palette2
= (void *)0xdeadbeef;
6698 hr
= IDirectDrawSurface4_GetPalette(tmp
, &palette2
);
6699 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
6700 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
6702 hr
= IDirectDrawSurface4_SetPalette(tmp
, palette_mipmap
);
6703 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
6705 hr
= IDirectDrawSurface4_GetPalette(tmp
, &palette2
);
6706 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
6707 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
6708 IDirectDrawPalette_Release(palette2
);
6710 hr
= IDirectDrawSurface4_GetDC(tmp
, &dc
);
6711 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
6712 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
6713 ok(count
== 1, "Expected count 1, got %u.\n", count
);
6714 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
6715 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
6716 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
6717 hr
= IDirectDrawSurface4_ReleaseDC(tmp
, dc
);
6718 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
6720 IDirectDrawSurface4_Release(mipmap
);
6724 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6725 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6726 IDirectDrawSurface4_Release(mipmap
);
6727 refcount
= IDirectDrawSurface4_Release(surface
);
6728 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6729 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
6730 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6731 refcount
= IDirectDrawPalette_Release(palette
);
6732 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6734 refcount
= IDirectDraw4_Release(ddraw
);
6735 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6736 DestroyWindow(window
);
6739 static void test_p8_rgb_blit(void)
6741 IDirectDrawSurface4
*src
, *dst
;
6742 DDSURFACEDESC2 surface_desc
;
6743 IDirectDraw4
*ddraw
;
6744 IDirectDrawPalette
*palette
;
6748 PALETTEENTRY palette_entries
[256];
6750 static const BYTE src_data
[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
6751 static const D3DCOLOR expected
[] =
6753 0x00000000, 0x00010101, 0x00020202, 0x00030303,
6754 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
6758 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6759 0, 0, 640, 480, 0, 0, 0, 0);
6760 ddraw
= create_ddraw();
6761 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6762 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6763 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6765 memset(palette_entries
, 0, sizeof(palette_entries
));
6766 palette_entries
[0].peRed
= 0xff;
6767 palette_entries
[1].peGreen
= 0xff;
6768 palette_entries
[2].peBlue
= 0xff;
6769 palette_entries
[3].peFlags
= 0xff;
6770 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6771 palette_entries
, &palette
, NULL
);
6772 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6774 memset(&surface_desc
, 0, sizeof(surface_desc
));
6775 surface_desc
.dwSize
= sizeof(surface_desc
);
6776 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6777 surface_desc
.dwWidth
= 8;
6778 surface_desc
.dwHeight
= 1;
6779 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6780 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6781 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6782 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
6783 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
6784 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6786 memset(&surface_desc
, 0, sizeof(surface_desc
));
6787 surface_desc
.dwSize
= sizeof(surface_desc
);
6788 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6789 surface_desc
.dwWidth
= 8;
6790 surface_desc
.dwHeight
= 1;
6791 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6792 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6793 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6794 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6795 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6796 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6797 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6798 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6799 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
6800 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6802 memset(&surface_desc
, 0, sizeof(surface_desc
));
6803 surface_desc
.dwSize
= sizeof(surface_desc
);
6804 hr
= IDirectDrawSurface4_Lock(src
, NULL
, &surface_desc
, 0, NULL
);
6805 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
6806 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
6807 hr
= IDirectDrawSurface4_Unlock(src
, NULL
);
6808 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
6810 hr
= IDirectDrawSurface4_SetPalette(src
, palette
);
6811 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6812 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
6813 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
6814 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
6815 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
6816 "Failed to blit, hr %#x.\n", hr
);
6820 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
6822 color
= get_surface_color(dst
, x
, 0);
6823 todo_wine
ok(compare_color(color
, expected
[x
], 0),
6824 "Pixel %u: Got color %#x, expected %#x.\n",
6825 x
, color
, expected
[x
]);
6829 IDirectDrawSurface4_Release(src
);
6830 IDirectDrawSurface4_Release(dst
);
6831 IDirectDrawPalette_Release(palette
);
6833 refcount
= IDirectDraw4_Release(ddraw
);
6834 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6835 DestroyWindow(window
);
6838 static void test_material(void)
6840 D3DMATERIALHANDLE mat_handle
, tmp
;
6841 IDirect3DMaterial3
*material
;
6842 IDirect3DViewport3
*viewport
;
6843 IDirect3DDevice3
*device
;
6844 IDirectDrawSurface4
*rt
;
6854 struct vec3 position
;
6860 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
6861 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
6862 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
6863 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
6867 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
6868 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
6869 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
6870 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
6876 D3DCOLOR expected_color
;
6880 {quad1
, TRUE
, 0x0000ff00},
6881 {quad2
, TRUE
, 0x0000ff00},
6882 {quad1
, FALSE
, 0x00ffffff},
6883 {quad2
, FALSE
, 0x00ff0000},
6885 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6887 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6888 0, 0, 640, 480, 0, 0, 0, 0);
6889 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
6891 skip("Failed to create a 3D device, skipping test.\n");
6892 DestroyWindow(window
);
6896 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
6897 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6899 viewport
= create_viewport(device
, 0, 0, 640, 480);
6900 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
6901 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6903 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
6904 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
6905 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6907 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6908 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6909 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6910 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6911 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6912 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6913 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6914 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6915 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, 0);
6916 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6917 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6918 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6919 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6921 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6923 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
,
6924 D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
6925 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6927 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
6928 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6930 hr
= IDirect3DDevice3_BeginScene(device
);
6931 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6932 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
6933 D3DFVF_XYZ
| D3DFVF_NORMAL
| D3DFVF_DIFFUSE
, test_data
[i
].data
, 4, 0);
6934 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6935 hr
= IDirect3DDevice3_EndScene(device
);
6936 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6937 color
= get_surface_color(rt
, 320, 240);
6938 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
6939 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
6942 destroy_material(material
);
6943 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
6944 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
6945 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6947 hr
= IDirect3DViewport3_SetBackground(viewport
, mat_handle
);
6948 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
6949 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
6950 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6951 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6952 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6953 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6954 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6955 color
= get_surface_color(rt
, 320, 240);
6956 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6958 hr
= IDirect3DViewport3_SetBackground(viewport
, 0);
6959 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6960 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
6961 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6962 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6963 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6964 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6965 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6966 color
= get_surface_color(rt
, 320, 240);
6967 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6969 destroy_viewport(device
, viewport
);
6970 viewport
= create_viewport(device
, 0, 0, 640, 480);
6972 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
6973 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6974 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6975 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
6976 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6977 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6978 color
= get_surface_color(rt
, 320, 240);
6979 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
6981 destroy_viewport(device
, viewport
);
6982 destroy_material(material
);
6983 IDirectDrawSurface4_Release(rt
);
6984 refcount
= IDirect3DDevice3_Release(device
);
6985 ok(!refcount
, "Device has %u references left.\n", refcount
);
6986 DestroyWindow(window
);
6989 static void test_palette_gdi(void)
6991 IDirectDrawSurface4
*surface
, *primary
;
6992 DDSURFACEDESC2 surface_desc
;
6993 IDirectDraw4
*ddraw
;
6994 IDirectDrawPalette
*palette
, *palette2
;
6998 PALETTEENTRY palette_entries
[256];
7001 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7002 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7003 * not the point of this test. */
7004 static const RGBQUAD expected1
[] =
7006 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7007 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7009 static const RGBQUAD expected2
[] =
7011 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7012 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7014 static const RGBQUAD expected3
[] =
7016 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7017 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7019 HPALETTE ddraw_palette_handle
;
7020 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7021 RGBQUAD rgbquad
[255];
7022 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
7024 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7025 0, 0, 640, 480, 0, 0, 0, 0);
7026 ddraw
= create_ddraw();
7027 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7028 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7029 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7031 memset(&surface_desc
, 0, sizeof(surface_desc
));
7032 surface_desc
.dwSize
= sizeof(surface_desc
);
7033 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7034 surface_desc
.dwWidth
= 16;
7035 surface_desc
.dwHeight
= 16;
7036 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7037 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7038 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7039 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7040 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7041 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7043 /* Avoid colors from the Windows default palette. */
7044 memset(palette_entries
, 0, sizeof(palette_entries
));
7045 palette_entries
[1].peRed
= 0x01;
7046 palette_entries
[2].peGreen
= 0x02;
7047 palette_entries
[3].peBlue
= 0x03;
7048 palette_entries
[4].peRed
= 0x13;
7049 palette_entries
[4].peGreen
= 0x14;
7050 palette_entries
[4].peBlue
= 0x15;
7051 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7052 palette_entries
, &palette
, NULL
);
7053 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7055 /* If there is no palette assigned and the display mode is not 8 bpp, some
7056 * drivers refuse to create a DC while others allow it. If a DC is created,
7057 * the DIB color table is uninitialized and contains random colors. No error
7058 * is generated when trying to read pixels and random garbage is returned.
7060 * The most likely explanation is that if the driver creates a DC, it (or
7061 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7062 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7063 * contains uninitialized garbage. See comments below for the P8 case. */
7065 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
7066 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7067 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
7068 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7069 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7070 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7071 "Got unexpected palette %p, expected %p.\n",
7072 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7074 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7075 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7076 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
7078 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
7079 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7080 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7081 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
7083 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7085 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7086 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7087 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7090 /* Update the palette while the DC is in use. This does not modify the DC. */
7091 palette_entries
[4].peRed
= 0x23;
7092 palette_entries
[4].peGreen
= 0x24;
7093 palette_entries
[4].peBlue
= 0x25;
7094 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
7095 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
7097 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7098 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7099 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7100 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7101 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7102 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7104 /* Neither does re-setting the palette. */
7105 hr
= IDirectDrawSurface4_SetPalette(surface
, NULL
);
7106 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7107 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
7108 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7110 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7111 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7112 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7113 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7114 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7115 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7117 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
7118 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7120 /* Refresh the DC. This updates the palette. */
7121 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
7122 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7123 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7124 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7125 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7127 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7128 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7129 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7130 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7132 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7134 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7135 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7136 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7138 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
7139 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7141 refcount
= IDirectDrawSurface4_Release(surface
);
7142 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7144 if (FAILED(hr
= IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7146 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7147 IDirectDrawPalette_Release(palette
);
7148 IDirectDraw4_Release(ddraw
);
7149 DestroyWindow(window
);
7152 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
7153 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
7154 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7156 memset(&surface_desc
, 0, sizeof(surface_desc
));
7157 surface_desc
.dwSize
= sizeof(surface_desc
);
7158 surface_desc
.dwFlags
= DDSD_CAPS
;
7159 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7160 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
7161 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7163 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
7164 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7165 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
7166 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7167 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7168 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
7169 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
7170 "Got unexpected palette %p, expected %p.\n",
7171 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7172 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
7174 /* The primary uses the system palette. In exclusive mode, the system palette matches
7175 * the ddraw palette attached to the primary, so the result is what you would expect
7176 * from a regular surface. Tests for the interaction between the ddraw palette and
7177 * the system palette are not included pending an application that depends on this.
7178 * The relation between those causes problems on Windows Vista and newer for games
7179 * like Age of Empires or Starcraft. Don't emulate it without a real need. */
7180 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7181 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7182 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7184 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7185 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7186 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7187 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7189 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7191 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7192 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7193 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7195 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
7196 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7198 memset(&surface_desc
, 0, sizeof(surface_desc
));
7199 surface_desc
.dwSize
= sizeof(surface_desc
);
7200 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7201 surface_desc
.dwWidth
= 16;
7202 surface_desc
.dwHeight
= 16;
7203 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7204 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7205 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7207 /* Here the offscreen surface appears to use the primary's palette,
7208 * but in all likelyhood it is actually the system palette. */
7209 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
7210 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7211 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7212 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7213 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7215 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7216 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7217 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7218 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7220 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7222 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7223 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7224 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7226 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
7227 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7229 /* On real hardware a change to the primary surface's palette applies immediately,
7230 * even on device contexts from offscreen surfaces that do not have their own
7231 * palette. On the testbot VMs this is not the case. Don't test this until we
7232 * know of an application that depends on this. */
7234 memset(palette_entries
, 0, sizeof(palette_entries
));
7235 palette_entries
[1].peBlue
= 0x40;
7236 palette_entries
[2].peRed
= 0x40;
7237 palette_entries
[3].peGreen
= 0x40;
7238 palette_entries
[4].peRed
= 0x12;
7239 palette_entries
[4].peGreen
= 0x34;
7240 palette_entries
[4].peBlue
= 0x56;
7241 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7242 palette_entries
, &palette2
, NULL
);
7243 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7244 hr
= IDirectDrawSurface4_SetPalette(surface
, palette2
);
7245 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7247 /* A palette assigned to the offscreen surface overrides the primary / system
7249 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
7250 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7251 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7252 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7253 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
7255 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
7256 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7257 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7258 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
7260 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7262 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7263 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7264 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7266 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
7267 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7269 refcount
= IDirectDrawSurface4_Release(surface
);
7270 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7272 /* The Windows 8 testbot keeps extra references to the primary and
7273 * backbuffer while in 8 bpp mode. */
7274 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
7275 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7277 refcount
= IDirectDrawSurface4_Release(primary
);
7278 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7279 refcount
= IDirectDrawPalette_Release(palette2
);
7280 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7281 refcount
= IDirectDrawPalette_Release(palette
);
7282 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7283 refcount
= IDirectDraw4_Release(ddraw
);
7284 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7285 DestroyWindow(window
);
7288 static void test_palette_alpha(void)
7290 IDirectDrawSurface4
*surface
;
7291 DDSURFACEDESC2 surface_desc
;
7292 IDirectDraw4
*ddraw
;
7293 IDirectDrawPalette
*palette
;
7297 PALETTEENTRY palette_entries
[256];
7302 BOOL attach_allowed
;
7307 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
7308 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
7309 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
7312 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7313 0, 0, 640, 480, 0, 0, 0, 0);
7314 ddraw
= create_ddraw();
7315 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7316 if (FAILED(hr
= IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7318 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7319 IDirectDraw4_Release(ddraw
);
7320 DestroyWindow(window
);
7323 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
7324 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7325 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7327 memset(palette_entries
, 0, sizeof(palette_entries
));
7328 palette_entries
[1].peFlags
= 0x42;
7329 palette_entries
[2].peFlags
= 0xff;
7330 palette_entries
[3].peFlags
= 0x80;
7331 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
7332 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7334 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7335 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7336 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7337 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7338 palette_entries
[0].peFlags
);
7339 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7340 palette_entries
[1].peFlags
);
7341 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7342 palette_entries
[2].peFlags
);
7343 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7344 palette_entries
[3].peFlags
);
7346 IDirectDrawPalette_Release(palette
);
7348 memset(palette_entries
, 0, sizeof(palette_entries
));
7349 palette_entries
[1].peFlags
= 0x42;
7350 palette_entries
[1].peRed
= 0xff;
7351 palette_entries
[2].peFlags
= 0xff;
7352 palette_entries
[3].peFlags
= 0x80;
7353 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
7354 palette_entries
, &palette
, NULL
);
7355 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7357 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7358 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7359 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7360 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7361 palette_entries
[0].peFlags
);
7362 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7363 palette_entries
[1].peFlags
);
7364 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7365 palette_entries
[2].peFlags
);
7366 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7367 palette_entries
[3].peFlags
);
7369 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
7371 memset(&surface_desc
, 0, sizeof(surface_desc
));
7372 surface_desc
.dwSize
= sizeof(surface_desc
);
7373 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
7374 surface_desc
.dwWidth
= 128;
7375 surface_desc
.dwHeight
= 128;
7376 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
7377 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7378 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7380 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
7381 if (test_data
[i
].attach_allowed
)
7382 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7384 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7392 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
7393 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7394 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
7395 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
7396 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
7397 rgbquad
.rgbRed
, test_data
[i
].name
);
7398 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
7399 rgbquad
.rgbGreen
, test_data
[i
].name
);
7400 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
7401 rgbquad
.rgbBlue
, test_data
[i
].name
);
7402 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
7403 rgbquad
.rgbReserved
, test_data
[i
].name
);
7404 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
7405 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7407 IDirectDrawSurface4_Release(surface
);
7410 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
7411 memset(&surface_desc
, 0, sizeof(surface_desc
));
7412 surface_desc
.dwSize
= sizeof(surface_desc
);
7413 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7414 surface_desc
.dwWidth
= 128;
7415 surface_desc
.dwHeight
= 128;
7416 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7417 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7418 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7419 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7420 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7421 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7422 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7423 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7424 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7425 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
7426 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
7427 IDirectDrawSurface4_Release(surface
);
7429 /* The Windows 8 testbot keeps extra references to the primary
7430 * while in 8 bpp mode. */
7431 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
7432 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7434 refcount
= IDirectDrawPalette_Release(palette
);
7435 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7436 refcount
= IDirectDraw4_Release(ddraw
);
7437 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7438 DestroyWindow(window
);
7443 IDirectDraw4
*ddraw
;
7445 if (!(ddraw
= create_ddraw()))
7447 skip("Failed to create a ddraw object, skipping tests.\n");
7450 IDirectDraw4_Release(ddraw
);
7452 test_process_vertices();
7453 test_coop_level_create_device_window();
7455 test_coop_level_d3d_state();
7456 test_surface_interface_mismatch();
7457 test_coop_level_threaded();
7459 test_texture_load_ckey();
7468 test_window_style();
7469 test_redundant_mode_set();
7470 test_coop_level_mode_set();
7471 test_coop_level_mode_set_multi();
7473 test_coop_level_surf_create();
7475 test_coop_level_multi_window();
7476 test_draw_strided();
7477 test_clear_rect_count();
7478 test_coop_level_versions();
7479 test_lighting_interface_versions();
7480 test_coop_level_activateapp();
7481 test_texturemanage();
7482 test_block_formats_creation();
7483 test_unsupported_formats();
7485 test_primary_caps();
7486 test_surface_lock();
7487 test_surface_discard();
7489 test_set_surface_desc();
7490 test_user_memory_getdc();
7491 test_sysmem_overlay();
7492 test_primary_palette();
7493 test_surface_attachment();
7494 test_private_data();
7495 test_pixel_format();
7496 test_create_surface_pitch();
7498 test_palette_complex();
7502 test_palette_alpha();