2 * Copyright 2011-2014 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"
26 static DEVMODEW registry_mode
;
43 struct create_window_thread_param
46 HANDLE window_created
;
47 HANDLE destroy_window
;
51 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
61 if (abs(x
- y
) > ulps
)
67 static BOOL
compare_vec4(struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
69 return compare_float(vec
->x
, x
, ulps
)
70 && compare_float(vec
->y
, y
, ulps
)
71 && compare_float(vec
->z
, z
, ulps
)
72 && compare_float(vec
->w
, w
, ulps
);
75 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
77 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
79 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
81 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
83 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
87 static DWORD WINAPI
create_window_thread_proc(void *param
)
89 struct create_window_thread_param
*p
= param
;
93 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
94 0, 0, 640, 480, 0, 0, 0, 0);
95 ret
= SetEvent(p
->window_created
);
96 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
102 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
103 DispatchMessageA(&msg
);
104 res
= WaitForSingleObject(p
->destroy_window
, 100);
105 if (res
== WAIT_OBJECT_0
)
107 if (res
!= WAIT_TIMEOUT
)
109 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
114 DestroyWindow(p
->window
);
119 static void create_window_thread(struct create_window_thread_param
*p
)
123 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
124 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
125 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
126 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
127 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
128 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
129 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
130 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
133 static void destroy_window_thread(struct create_window_thread_param
*p
)
135 SetEvent(p
->destroy_window
);
136 WaitForSingleObject(p
->thread
, INFINITE
);
137 CloseHandle(p
->destroy_window
);
138 CloseHandle(p
->window_created
);
139 CloseHandle(p
->thread
);
142 static IDirectDrawSurface4
*get_depth_stencil(IDirect3DDevice3
*device
)
144 IDirectDrawSurface4
*rt
, *ret
;
145 DDSCAPS2 caps
= {DDSCAPS_ZBUFFER
, 0, 0, {0}};
148 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
149 ok(SUCCEEDED(hr
), "Failed to get the render target, hr %#x.\n", hr
);
150 hr
= IDirectDrawSurface4_GetAttachedSurface(rt
, &caps
, &ret
);
151 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
152 IDirectDrawSurface4_Release(rt
);
156 static HRESULT
set_display_mode(IDirectDraw4
*ddraw
, DWORD width
, DWORD height
)
158 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
160 return IDirectDraw4_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
163 static D3DCOLOR
get_surface_color(IDirectDrawSurface4
*surface
, UINT x
, UINT y
)
165 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
166 DDSURFACEDESC2 surface_desc
;
170 memset(&surface_desc
, 0, sizeof(surface_desc
));
171 surface_desc
.dwSize
= sizeof(surface_desc
);
173 hr
= IDirectDrawSurface4_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
174 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
178 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
180 hr
= IDirectDrawSurface4_Unlock(surface
, &rect
);
181 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
186 static HRESULT CALLBACK
enum_z_fmt(DDPIXELFORMAT
*format
, void *ctx
)
188 DDPIXELFORMAT
*z_fmt
= ctx
;
190 if (U1(*format
).dwZBufferBitDepth
> U1(*z_fmt
).dwZBufferBitDepth
)
196 static IDirectDraw4
*create_ddraw(void)
198 IDirectDraw4
*ddraw4
;
202 if (FAILED(DirectDrawCreate(NULL
, &ddraw1
, NULL
)))
205 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw4
, (void **)&ddraw4
);
206 IDirectDraw_Release(ddraw1
);
213 static IDirect3DDevice3
*create_device(HWND window
, DWORD coop_level
)
215 IDirectDrawSurface4
*surface
, *ds
;
216 IDirect3DDevice3
*device
= NULL
;
217 DDSURFACEDESC2 surface_desc
;
218 IDirectDraw4
*ddraw4
;
223 if (!(ddraw4
= create_ddraw()))
226 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, coop_level
);
227 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
229 memset(&surface_desc
, 0, sizeof(surface_desc
));
230 surface_desc
.dwSize
= sizeof(surface_desc
);
231 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
232 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
233 surface_desc
.dwWidth
= 640;
234 surface_desc
.dwHeight
= 480;
236 hr
= IDirectDraw4_CreateSurface(ddraw4
, &surface_desc
, &surface
, NULL
);
237 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
239 if (coop_level
& DDSCL_NORMAL
)
241 IDirectDrawClipper
*clipper
;
243 hr
= IDirectDraw4_CreateClipper(ddraw4
, 0, &clipper
, NULL
);
244 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
245 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
246 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
247 hr
= IDirectDrawSurface4_SetClipper(surface
, clipper
);
248 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
249 IDirectDrawClipper_Release(clipper
);
252 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirect3D3
, (void **)&d3d3
);
253 IDirectDraw4_Release(ddraw4
);
256 IDirectDrawSurface4_Release(surface
);
260 memset(&z_fmt
, 0, sizeof(z_fmt
));
261 hr
= IDirect3D3_EnumZBufferFormats(d3d3
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
262 if (FAILED(hr
) || !z_fmt
.dwSize
)
264 IDirect3D3_Release(d3d3
);
265 IDirectDrawSurface4_Release(surface
);
269 memset(&surface_desc
, 0, sizeof(surface_desc
));
270 surface_desc
.dwSize
= sizeof(surface_desc
);
271 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
272 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
273 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
274 surface_desc
.dwWidth
= 640;
275 surface_desc
.dwHeight
= 480;
276 hr
= IDirectDraw4_CreateSurface(ddraw4
, &surface_desc
, &ds
, NULL
);
277 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
280 IDirect3D3_Release(d3d3
);
281 IDirectDrawSurface4_Release(surface
);
285 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
286 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
287 IDirectDrawSurface4_Release(ds
);
290 IDirect3D3_Release(d3d3
);
291 IDirectDrawSurface4_Release(surface
);
295 hr
= IDirect3D3_CreateDevice(d3d3
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
296 IDirect3D3_Release(d3d3
);
297 IDirectDrawSurface4_Release(surface
);
304 static IDirect3DViewport3
*create_viewport(IDirect3DDevice3
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
306 IDirect3DViewport3
*viewport
;
311 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
312 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
313 hr
= IDirect3D3_CreateViewport(d3d
, &viewport
, NULL
);
314 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
315 hr
= IDirect3DDevice3_AddViewport(device
, viewport
);
316 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
317 memset(&vp
, 0, sizeof(vp
));
318 vp
.dwSize
= sizeof(vp
);
325 vp
.dvClipWidth
= 2.0f
;
326 vp
.dvClipHeight
= 2.0f
;
329 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp
);
330 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
331 IDirect3D3_Release(d3d
);
336 static void destroy_viewport(IDirect3DDevice3
*device
, IDirect3DViewport3
*viewport
)
340 hr
= IDirect3DDevice3_DeleteViewport(device
, viewport
);
341 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
342 IDirect3DViewport3_Release(viewport
);
345 static IDirect3DMaterial3
*create_material(IDirect3DDevice3
*device
, D3DMATERIAL
*mat
)
347 IDirect3DMaterial3
*material
;
351 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
352 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
353 hr
= IDirect3D3_CreateMaterial(d3d
, &material
, NULL
);
354 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
355 hr
= IDirect3DMaterial3_SetMaterial(material
, mat
);
356 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
357 IDirect3D3_Release(d3d
);
362 static IDirect3DMaterial3
*create_diffuse_material(IDirect3DDevice3
*device
, float r
, float g
, float b
, float a
)
366 memset(&mat
, 0, sizeof(mat
));
367 mat
.dwSize
= sizeof(mat
);
368 U1(U(mat
).diffuse
).r
= r
;
369 U2(U(mat
).diffuse
).g
= g
;
370 U3(U(mat
).diffuse
).b
= b
;
371 U4(U(mat
).diffuse
).a
= a
;
373 return create_material(device
, &mat
);
376 static IDirect3DMaterial3
*create_specular_material(IDirect3DDevice3
*device
,
377 float r
, float g
, float b
, float a
, float power
)
381 memset(&mat
, 0, sizeof(mat
));
382 mat
.dwSize
= sizeof(mat
);
383 U1(U2(mat
).specular
).r
= r
;
384 U2(U2(mat
).specular
).g
= g
;
385 U3(U2(mat
).specular
).b
= b
;
386 U4(U2(mat
).specular
).a
= a
;
387 U4(mat
).power
= power
;
389 return create_material(device
, &mat
);
392 static IDirect3DMaterial3
*create_emissive_material(IDirect3DDevice3
*device
, float r
, float g
, float b
, float a
)
396 memset(&mat
, 0, sizeof(mat
));
397 mat
.dwSize
= sizeof(mat
);
398 U1(U3(mat
).emissive
).r
= r
;
399 U2(U3(mat
).emissive
).g
= g
;
400 U3(U3(mat
).emissive
).b
= b
;
401 U4(U3(mat
).emissive
).a
= a
;
403 return create_material(device
, &mat
);
406 static void destroy_material(IDirect3DMaterial3
*material
)
408 IDirect3DMaterial3_Release(material
);
415 WPARAM expect_wparam
;
418 static const struct message
*expect_messages
;
420 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
422 if (expect_messages
&& message
== expect_messages
->message
)
424 if (expect_messages
->check_wparam
)
425 ok (wparam
== expect_messages
->expect_wparam
,
426 "Got unexpected wparam %lx for message %x, expected %lx.\n",
427 wparam
, message
, expect_messages
->expect_wparam
);
432 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
435 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
436 * interface. This prevents subsequent SetCooperativeLevel() calls on a
437 * different window from failing with DDERR_HWNDALREADYSET. */
438 static void fix_wndproc(HWND window
, LONG_PTR proc
)
443 if (!(ddraw
= create_ddraw()))
446 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
447 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
448 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
449 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
450 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
452 IDirectDraw4_Release(ddraw
);
455 static void test_process_vertices(void)
457 IDirect3DVertexBuffer
*src_vb
, *dst_vb
;
458 IDirect3DViewport3
*viewport
;
459 D3DVERTEXBUFFERDESC vb_desc
;
460 IDirect3DDevice3
*device
;
461 struct vec3
*src_data
;
462 struct vec4
*dst_data
;
469 static D3DMATRIX identity
=
471 1.0f
, 0.0f
, 0.0f
, 0.0f
,
472 0.0f
, 1.0f
, 0.0f
, 0.0f
,
473 0.0f
, 0.0f
, 1.0f
, 0.0f
,
474 0.0f
, 0.0f
, 0.0f
, 1.0f
,
476 static D3DMATRIX projection
=
478 1.0f
, 0.0f
, 0.0f
, 0.0f
,
479 0.0f
, 1.0f
, 0.0f
, 0.0f
,
480 0.0f
, 0.0f
, 1.0f
, 0.0f
,
481 6.0f
, 7.0f
, 8.0f
, 1.0f
,
484 window
= CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW
,
485 0, 0, 640, 480, 0, 0, 0, 0);
486 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
488 skip("Failed to create a 3D device, skipping test.\n");
489 DestroyWindow(window
);
493 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d3
);
494 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
496 memset(&vb_desc
, 0, sizeof(vb_desc
));
497 vb_desc
.dwSize
= sizeof(vb_desc
);
498 vb_desc
.dwFVF
= D3DFVF_XYZ
;
499 vb_desc
.dwNumVertices
= 3;
500 hr
= IDirect3D3_CreateVertexBuffer(d3d3
, &vb_desc
, &src_vb
, 0, NULL
);
501 ok(SUCCEEDED(hr
), "Failed to create source vertex buffer, hr %#x.\n", hr
);
503 hr
= IDirect3DVertexBuffer_Lock(src_vb
, DDLOCK_WRITEONLY
, (void **)&src_data
, NULL
);
504 ok(SUCCEEDED(hr
), "Failed to lock source vertex buffer, hr %#x.\n", hr
);
505 src_data
[0].x
= -1.0f
;
506 src_data
[0].y
= -1.0f
;
507 src_data
[0].z
= -1.0f
;
508 src_data
[1].x
= 0.0f
;
509 src_data
[1].y
= 0.0f
;
510 src_data
[1].z
= 0.0f
;
511 src_data
[2].x
= 1.0f
;
512 src_data
[2].y
= 1.0f
;
513 src_data
[2].z
= 1.0f
;
514 hr
= IDirect3DVertexBuffer_Unlock(src_vb
);
515 ok(SUCCEEDED(hr
), "Failed to unlock source vertex buffer, hr %#x.\n", hr
);
517 memset(&vb_desc
, 0, sizeof(vb_desc
));
518 vb_desc
.dwSize
= sizeof(vb_desc
);
519 vb_desc
.dwFVF
= D3DFVF_XYZRHW
;
520 vb_desc
.dwNumVertices
= 3;
521 hr
= IDirect3D3_CreateVertexBuffer(d3d3
, &vb_desc
, &dst_vb
, 0, NULL
);
522 ok(SUCCEEDED(hr
), "Failed to create destination vertex buffer, hr %#x.\n", hr
);
524 hr
= IDirect3D3_CreateViewport(d3d3
, &viewport
, NULL
);
525 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
526 hr
= IDirect3DDevice3_AddViewport(device
, viewport
);
527 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
528 vp2
.dwSize
= sizeof(vp2
);
535 vp2
.dvClipWidth
= 4.0f
;
536 vp2
.dvClipHeight
= 5.0f
;
539 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp2
);
540 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
541 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
542 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
544 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &identity
);
545 ok(SUCCEEDED(hr
), "Failed to set world transformation, hr %#x.\n", hr
);
546 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &identity
);
547 ok(SUCCEEDED(hr
), "Failed to set view transformation, hr %#x.\n", hr
);
548 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &identity
);
549 ok(SUCCEEDED(hr
), "Failed to set projection transformation, hr %#x.\n", hr
);
551 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
552 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
554 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
555 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
556 ok(compare_vec4(&dst_data
[0], -6.500e+1f
, +1.800e+2f
, +2.000e-1f
, +1.000e+0f
, 4096),
557 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
558 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
559 ok(compare_vec4(&dst_data
[1], -4.000e+1f
, +1.400e+2f
, +4.000e-1f
, +1.000e+0f
, 4096),
560 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
561 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
562 ok(compare_vec4(&dst_data
[2], -1.500e+1f
, +1.000e+2f
, +6.000e-1f
, +1.000e+0f
, 4096),
563 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
564 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
565 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
566 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
568 hr
= IDirect3DDevice3_MultiplyTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &projection
);
569 ok(SUCCEEDED(hr
), "Failed to set projection transformation, hr %#x.\n", hr
);
571 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
572 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
574 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
575 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
576 ok(compare_vec4(&dst_data
[0], +8.500e+1f
, -1.000e+2f
, +1.800e+0f
, +1.000e+0f
, 4096),
577 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
578 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
579 ok(compare_vec4(&dst_data
[1], +1.100e+2f
, -1.400e+2f
, +2.000e+0f
, +1.000e+0f
, 4096),
580 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
581 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
582 ok(compare_vec4(&dst_data
[2], +1.350e+2f
, -1.800e+2f
, +2.200e+0f
, +1.000e+0f
, 4096),
583 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
584 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
585 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
586 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
588 vp2
.dwSize
= sizeof(vp2
);
595 vp2
.dvClipWidth
= 2.0f
;
596 vp2
.dvClipHeight
= 4.0f
;
599 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp2
);
600 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
602 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
603 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
605 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
606 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
607 ok(compare_vec4(&dst_data
[0], +7.500e+1f
, +4.000e+1f
, -8.000e-1f
, +1.000e+0f
, 4096),
608 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
609 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
610 ok(compare_vec4(&dst_data
[1], +1.200e+2f
, +2.000e+1f
, -1.000e+0f
, +1.000e+0f
, 4096),
611 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
612 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
613 ok(compare_vec4(&dst_data
[2], +1.650e+2f
, +0.000e+0f
, -1.200e+0f
, +1.000e+0f
, 4096),
614 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
615 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
616 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
617 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
619 vp1
.dwSize
= sizeof(vp1
);
630 hr
= IDirect3DViewport3_SetViewport(viewport
, &vp1
);
631 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
633 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
634 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
636 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
637 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
638 ok(compare_vec4(&dst_data
[0], +1.100e+2f
, +6.800e+1f
, +7.000e+0f
, +1.000e+0f
, 4096),
639 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
640 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
641 ok(compare_vec4(&dst_data
[1], +1.170e+2f
, +6.600e+1f
, +8.000e+0f
, +1.000e+0f
, 4096),
642 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
643 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
644 ok(compare_vec4(&dst_data
[2], +1.240e+2f
, +6.400e+1f
, +9.000e+0f
, +1.000e+0f
, 4096),
645 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
646 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
647 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
648 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
650 hr
= IDirect3DDevice3_DeleteViewport(device
, viewport
);
651 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
653 IDirect3DVertexBuffer_Release(dst_vb
);
654 IDirect3DVertexBuffer_Release(src_vb
);
655 IDirect3DViewport3_Release(viewport
);
656 IDirect3D3_Release(d3d3
);
657 IDirect3DDevice3_Release(device
);
658 DestroyWindow(window
);
661 static void test_coop_level_create_device_window(void)
663 HWND focus_window
, device_window
;
667 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
668 0, 0, 640, 480, 0, 0, 0, 0);
669 ddraw
= create_ddraw();
670 ok(!!ddraw
, "Failed to create a ddraw object.\n");
672 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
673 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
674 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
675 ok(!device_window
, "Unexpected device window found.\n");
676 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
677 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
678 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
679 ok(!device_window
, "Unexpected device window found.\n");
680 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
681 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
682 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
683 ok(!device_window
, "Unexpected device window found.\n");
684 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
685 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
686 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
687 ok(!device_window
, "Unexpected device window found.\n");
688 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
689 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
690 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
691 ok(!device_window
, "Unexpected device window found.\n");
693 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
694 if (broken(hr
== DDERR_INVALIDPARAMS
))
696 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
697 IDirectDraw4_Release(ddraw
);
698 DestroyWindow(focus_window
);
702 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
703 ok(hr
== DD_OK
, "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_EXCLUSIVE
| DDSCL_FULLSCREEN
);
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");
711 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
712 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
713 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
714 ok(!device_window
, "Unexpected device window found.\n");
715 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
716 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
717 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
718 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
719 ok(!!device_window
, "Device window not found.\n");
721 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
722 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
723 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
724 ok(!device_window
, "Unexpected device window found.\n");
725 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
726 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
727 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
728 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
729 ok(!!device_window
, "Device window not found.\n");
731 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
732 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
733 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
734 ok(!device_window
, "Unexpected device window found.\n");
735 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
736 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
737 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
738 ok(!device_window
, "Unexpected device window found.\n");
739 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
740 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
741 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
742 ok(!device_window
, "Unexpected device window found.\n");
743 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
744 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
745 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
746 ok(!!device_window
, "Device window not found.\n");
748 IDirectDraw4_Release(ddraw
);
749 DestroyWindow(focus_window
);
752 static void test_clipper_blt(void)
754 IDirectDrawSurface4
*src_surface
, *dst_surface
;
755 RECT client_rect
, src_rect
;
756 IDirectDrawClipper
*clipper
;
757 DDSURFACEDESC2 surface_desc
;
758 unsigned int i
, j
, x
, y
;
770 static const DWORD src_data
[] =
772 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
773 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
774 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
776 static const D3DCOLOR expected1
[] =
778 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
779 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
780 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
781 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
783 /* Nvidia on Windows seems to have an off-by-one error
784 * when processing source rectangles. Our left = 1 and
785 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
786 * read as well, but only for the edge pixels on the
787 * output image. The bug happens on the y axis as well,
788 * but we only read one row there, and all source rows
789 * contain the same data. This bug is not dependent on
790 * the presence of a clipper. */
791 static const D3DCOLOR expected1_broken
[] =
793 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
794 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
795 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
796 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
798 static const D3DCOLOR expected2
[] =
800 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
801 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
802 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
803 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
806 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
807 10, 10, 640, 480, 0, 0, 0, 0);
808 ShowWindow(window
, SW_SHOW
);
809 ddraw
= create_ddraw();
810 ok(!!ddraw
, "Failed to create a ddraw object.\n");
812 ret
= GetClientRect(window
, &client_rect
);
813 ok(ret
, "Failed to get client rect.\n");
814 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
815 ok(ret
, "Failed to map client rect.\n");
817 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
818 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
820 hr
= IDirectDraw4_CreateClipper(ddraw
, 0, &clipper
, NULL
);
821 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
822 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
823 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
824 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
825 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
826 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
827 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
828 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
829 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
830 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
831 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
832 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
833 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
834 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
835 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
836 rgn_data
->rdh
.rcBound
.left
, rgn_data
->rdh
.rcBound
.top
,
837 rgn_data
->rdh
.rcBound
.right
, rgn_data
->rdh
.rcBound
.bottom
,
838 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
839 HeapFree(GetProcessHeap(), 0, rgn_data
);
841 r1
= CreateRectRgn(0, 0, 320, 240);
842 ok(!!r1
, "Failed to create region.\n");
843 r2
= CreateRectRgn(320, 240, 640, 480);
844 ok(!!r2
, "Failed to create region.\n");
845 CombineRgn(r1
, r1
, r2
, RGN_OR
);
846 ret
= GetRegionData(r1
, 0, NULL
);
847 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
848 ret
= GetRegionData(r1
, ret
, rgn_data
);
849 ok(!!ret
, "Failed to get region data.\n");
854 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
855 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
856 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
857 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
858 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
859 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
861 HeapFree(GetProcessHeap(), 0, rgn_data
);
863 memset(&surface_desc
, 0, sizeof(surface_desc
));
864 surface_desc
.dwSize
= sizeof(surface_desc
);
865 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
866 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
867 surface_desc
.dwWidth
= 640;
868 surface_desc
.dwHeight
= 480;
869 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
870 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
871 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
872 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
873 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
874 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
876 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
877 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
878 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
879 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
881 memset(&fx
, 0, sizeof(fx
));
882 fx
.dwSize
= sizeof(fx
);
883 hr
= IDirectDrawSurface4_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
884 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
885 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
886 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
888 hr
= IDirectDrawSurface4_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
889 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
890 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
891 ptr
= surface_desc
.lpSurface
;
892 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
893 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
894 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
895 hr
= IDirectDrawSurface4_Unlock(src_surface
, NULL
);
896 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
898 hr
= IDirectDrawSurface4_SetClipper(dst_surface
, clipper
);
899 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
901 SetRect(&src_rect
, 1, 1, 5, 2);
902 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
903 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
904 for (i
= 0; i
< 4; ++i
)
906 for (j
= 0; j
< 4; ++j
)
908 x
= 80 * ((2 * j
) + 1);
909 y
= 60 * ((2 * i
) + 1);
910 color
= get_surface_color(dst_surface
, x
, y
);
911 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
912 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
913 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
917 U5(fx
).dwFillColor
= 0xff0000ff;
918 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
919 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
920 for (i
= 0; i
< 4; ++i
)
922 for (j
= 0; j
< 4; ++j
)
924 x
= 80 * ((2 * j
) + 1);
925 y
= 60 * ((2 * i
) + 1);
926 color
= get_surface_color(dst_surface
, x
, y
);
927 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
928 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
932 hr
= IDirectDrawSurface4_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
933 ok(hr
== DDERR_BLTFASTCANTCLIP
, "Got unexpected hr %#x.\n", hr
);
935 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
936 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
937 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
938 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
939 DestroyWindow(window
);
940 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
941 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
942 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
943 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
944 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
945 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
946 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
947 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
948 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
949 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
950 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
951 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
953 IDirectDrawSurface4_Release(dst_surface
);
954 IDirectDrawSurface4_Release(src_surface
);
955 refcount
= IDirectDrawClipper_Release(clipper
);
956 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
957 IDirectDraw4_Release(ddraw
);
960 static void test_coop_level_d3d_state(void)
962 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
963 IDirectDrawSurface4
*rt
, *surface
;
964 IDirect3DViewport3
*viewport
;
965 IDirect3DDevice3
*device
;
973 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
974 0, 0, 640, 480, 0, 0, 0, 0);
975 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
977 skip("Failed to create a 3D device, skipping test.\n");
978 DestroyWindow(window
);
982 viewport
= create_viewport(device
, 0, 0, 640, 480);
984 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
985 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
986 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
987 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
988 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
989 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
990 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
991 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
992 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
993 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
994 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
995 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
996 color
= get_surface_color(rt
, 320, 240);
997 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
999 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1000 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1001 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1002 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1003 IDirect3D3_Release(d3d
);
1004 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1005 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1006 hr
= IDirectDrawSurface4_IsLost(rt
);
1007 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
1008 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
1009 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
1010 IDirectDraw4_Release(ddraw
);
1012 hr
= IDirect3DDevice3_GetRenderTarget(device
, &surface
);
1013 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1014 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
1015 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
1016 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1017 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
1018 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
1019 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1020 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
1021 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
1022 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1023 color
= get_surface_color(rt
, 320, 240);
1024 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1026 destroy_viewport(device
, viewport
);
1027 IDirectDrawSurface4_Release(surface
);
1028 IDirectDrawSurface4_Release(rt
);
1029 IDirect3DDevice3_Release(device
);
1030 DestroyWindow(window
);
1033 static void test_surface_interface_mismatch(void)
1035 IDirectDraw4
*ddraw
= NULL
;
1036 IDirect3D3
*d3d
= NULL
;
1037 IDirectDrawSurface4
*surface
= NULL
, *ds
;
1038 IDirectDrawSurface3
*surface3
= NULL
;
1039 IDirect3DDevice3
*device
= NULL
;
1040 IDirect3DViewport3
*viewport
= NULL
;
1041 DDSURFACEDESC2 surface_desc
;
1042 DDPIXELFORMAT z_fmt
;
1047 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1049 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1050 0, 0, 640, 480, 0, 0, 0, 0);
1051 ddraw
= create_ddraw();
1052 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1053 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
1054 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1056 memset(&surface_desc
, 0, sizeof(surface_desc
));
1057 surface_desc
.dwSize
= sizeof(surface_desc
);
1058 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1059 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
1060 surface_desc
.dwWidth
= 640;
1061 surface_desc
.dwHeight
= 480;
1063 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1064 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1066 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
1067 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr
);
1069 if (FAILED(IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
)))
1071 skip("D3D interface is not available, skipping test.\n");
1075 memset(&z_fmt
, 0, sizeof(z_fmt
));
1076 hr
= IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
1077 if (FAILED(hr
) || !z_fmt
.dwSize
)
1079 skip("No depth buffer formats available, skipping test.\n");
1083 memset(&surface_desc
, 0, sizeof(surface_desc
));
1084 surface_desc
.dwSize
= sizeof(surface_desc
);
1085 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
1086 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1087 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
1088 surface_desc
.dwWidth
= 640;
1089 surface_desc
.dwHeight
= 480;
1090 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
1091 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
1095 /* Using a different surface interface version still works */
1096 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
1097 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
1098 refcount
= IDirectDrawSurface4_Release(ds
);
1099 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1104 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface4
*)surface3
, &device
, NULL
);
1105 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
1109 viewport
= create_viewport(device
, 0, 0, 640, 480);
1111 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
1112 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1113 color
= get_surface_color(surface
, 320, 240);
1114 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
1118 destroy_viewport(device
, viewport
);
1119 if (surface3
) IDirectDrawSurface3_Release(surface3
);
1120 if (surface
) IDirectDrawSurface4_Release(surface
);
1121 if (device
) IDirect3DDevice3_Release(device
);
1122 if (d3d
) IDirect3D3_Release(d3d
);
1123 if (ddraw
) IDirectDraw4_Release(ddraw
);
1124 DestroyWindow(window
);
1127 static void test_coop_level_threaded(void)
1129 struct create_window_thread_param p
;
1130 IDirectDraw4
*ddraw
;
1133 ddraw
= create_ddraw();
1134 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1135 create_window_thread(&p
);
1137 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1138 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1140 IDirectDraw4_Release(ddraw
);
1141 destroy_window_thread(&p
);
1144 static void test_depth_blit(void)
1153 { -1.0, 1.0, 0.50f
, 0xff00ff00},
1154 { 1.0, 1.0, 0.50f
, 0xff00ff00},
1155 { -1.0, -1.0, 0.50f
, 0xff00ff00},
1156 { 1.0, -1.0, 0.50f
, 0xff00ff00},
1158 static const D3DCOLOR expected_colors
[4][4] =
1160 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1161 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1162 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1163 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1165 DDSURFACEDESC2 ddsd_new
, ddsd_existing
;
1167 IDirect3DDevice3
*device
;
1168 IDirectDrawSurface4
*ds1
, *ds2
, *ds3
, *rt
;
1169 IDirect3DViewport3
*viewport
;
1170 RECT src_rect
, dst_rect
;
1175 IDirectDraw4
*ddraw
;
1180 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1181 0, 0, 640, 480, 0, 0, 0, 0);
1182 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1184 skip("Failed to create a 3D device, skipping test.\n");
1185 DestroyWindow(window
);
1189 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1190 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
1191 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1192 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
1193 IDirect3D3_Release(d3d
);
1195 ds1
= get_depth_stencil(device
);
1197 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1198 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1199 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1200 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1201 hr
= IDirectDrawSurface4_GetSurfaceDesc(ds1
, &ddsd_existing
);
1202 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
1203 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1204 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1205 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1206 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1207 U4(ddsd_new
).ddpfPixelFormat
= U4(ddsd_existing
).ddpfPixelFormat
;
1208 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1209 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1210 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1211 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1212 IDirectDraw4_Release(ddraw
);
1214 viewport
= create_viewport(device
, 0, 0, ddsd_existing
.dwWidth
, ddsd_existing
.dwHeight
);
1215 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1216 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
1218 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1219 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1220 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1221 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1223 U1(d3drect
).x1
= U2(d3drect
).y1
= 0;
1224 U3(d3drect
).x2
= ddsd_existing
.dwWidth
; U4(d3drect
).y2
= ddsd_existing
.dwHeight
;
1225 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
1226 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1229 SetRect(&src_rect
, 0, 0, 320, 240);
1230 SetRect(&dst_rect
, 0, 0, 320, 240);
1231 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1232 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1233 /* Different locations. */
1234 SetRect(&src_rect
, 0, 0, 320, 240);
1235 SetRect(&dst_rect
, 320, 240, 640, 480);
1236 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1237 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1239 SetRect(&src_rect
, 0, 0, 320, 240);
1240 SetRect(&dst_rect
, 0, 0, 640, 480);
1241 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1242 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1244 SetRect(&src_rect
, 0, 480, 640, 0);
1245 SetRect(&dst_rect
, 0, 0, 640, 480);
1246 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1247 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1248 SetRect(&src_rect
, 0, 0, 640, 480);
1249 SetRect(&dst_rect
, 0, 480, 640, 0);
1250 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1251 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1252 /* Full, explicit. */
1253 SetRect(&src_rect
, 0, 0, 640, 480);
1254 SetRect(&dst_rect
, 0, 0, 640, 480);
1255 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1256 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1257 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1259 /* Depth blit inside a BeginScene / EndScene pair */
1260 hr
= IDirect3DDevice3_BeginScene(device
);
1261 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1262 /* From the current depth stencil */
1263 hr
= IDirectDrawSurface4_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1264 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1265 /* To the current depth stencil */
1266 hr
= IDirectDrawSurface4_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1267 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1268 /* Between unbound surfaces */
1269 hr
= IDirectDrawSurface4_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1270 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1271 hr
= IDirect3DDevice3_EndScene(device
);
1272 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1274 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1275 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1276 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1277 * a reliable result(z = 0.0) */
1278 memset(&fx
, 0, sizeof(fx
));
1279 fx
.dwSize
= sizeof(fx
);
1280 hr
= IDirectDrawSurface4_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1281 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1283 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
, 0xffff0000, 1.0f
, 0);
1284 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1285 SetRect(&dst_rect
, 0, 0, 320, 240);
1286 hr
= IDirectDrawSurface4_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1287 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1288 IDirectDrawSurface4_Release(ds3
);
1289 IDirectDrawSurface4_Release(ds2
);
1290 IDirectDrawSurface4_Release(ds1
);
1292 hr
= IDirect3DDevice3_BeginScene(device
);
1293 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1294 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
1296 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1297 hr
= IDirect3DDevice3_EndScene(device
);
1298 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1300 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1301 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1302 for (i
= 0; i
< 4; ++i
)
1304 for (j
= 0; j
< 4; ++j
)
1306 unsigned int x
= 80 * ((2 * j
) + 1);
1307 unsigned int y
= 60 * ((2 * i
) + 1);
1308 color
= get_surface_color(rt
, x
, y
);
1309 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1310 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1313 IDirectDrawSurface4_Release(rt
);
1315 destroy_viewport(device
, viewport
);
1316 IDirect3DDevice3_Release(device
);
1317 DestroyWindow(window
);
1320 static void test_texture_load_ckey(void)
1322 IDirectDraw4
*ddraw
;
1323 IDirectDrawSurface4
*src
;
1324 IDirectDrawSurface4
*dst
;
1325 IDirect3DTexture2
*src_tex
;
1326 IDirect3DTexture2
*dst_tex
;
1327 DDSURFACEDESC2 ddsd
;
1331 ddraw
= create_ddraw();
1332 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1333 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
1334 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1336 memset(&ddsd
, 0, sizeof(ddsd
));
1337 ddsd
.dwSize
= sizeof(ddsd
);
1338 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1339 ddsd
.dwHeight
= 128;
1341 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1342 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1343 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1344 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1345 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1346 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1348 hr
= IDirectDrawSurface4_QueryInterface(src
, &IID_IDirect3DTexture2
, (void **)&src_tex
);
1349 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr
);
1352 /* 64 bit ddraw does not support d3d */
1353 skip("Could not get Direct3DTexture2 interface, skipping texture::Load color keying tests.\n");
1354 IDirectDrawSurface4_Release(dst
);
1355 IDirectDrawSurface4_Release(src
);
1356 IDirectDraw4_Release(ddraw
);
1359 hr
= IDirectDrawSurface4_QueryInterface(dst
, &IID_IDirect3DTexture2
, (void **)&dst_tex
);
1360 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr
);
1362 /* No surface has a color key */
1363 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1364 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1365 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1366 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1367 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1368 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1369 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1371 /* Source surface has a color key */
1372 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1373 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1374 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1375 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1376 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1377 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1378 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1379 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1380 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1382 /* Both surfaces have a color key: Dest ckey is overwritten */
1383 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1384 hr
= IDirectDrawSurface4_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1385 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1386 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1387 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1388 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1389 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1390 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1391 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1393 /* Only the destination has a color key: It is not deleted */
1394 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1395 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1396 hr
= IDirectDrawSurface4_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1397 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1398 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1399 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1400 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1401 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1402 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1403 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1405 IDirect3DTexture2_Release(dst_tex
);
1406 IDirect3DTexture2_Release(src_tex
);
1407 IDirectDrawSurface4_Release(dst
);
1408 IDirectDrawSurface4_Release(src
);
1409 IDirectDraw4_Release(ddraw
);
1412 static ULONG
get_refcount(IUnknown
*test_iface
)
1414 IUnknown_AddRef(test_iface
);
1415 return IUnknown_Release(test_iface
);
1418 static void test_viewport(void)
1420 IDirectDraw4
*ddraw
;
1422 HRESULT hr
, old_d3d_ref
;
1424 IDirect3DViewport
*viewport
;
1425 IDirect3DViewport2
*viewport2
;
1426 IDirect3DViewport3
*viewport3
, *another_vp
, *test_vp
;
1427 IDirectDrawGammaControl
*gamma
;
1430 IDirect3DDevice3
*device
;
1432 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1433 0, 0, 640, 480, 0, 0, 0, 0);
1434 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1436 skip("Failed to create a 3D device, skipping test.\n");
1437 DestroyWindow(window
);
1440 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1441 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
1442 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1443 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
1444 old_d3d_ref
= get_refcount((IUnknown
*) d3d
);
1446 hr
= IDirect3D3_CreateViewport(d3d
, &viewport3
, NULL
);
1447 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1448 ref
= get_refcount((IUnknown
*)viewport3
);
1449 ok(ref
== 1, "Initial IDirect3DViewport3 refcount is %u\n", ref
);
1450 ref
= get_refcount((IUnknown
*)d3d
);
1451 ok(ref
== old_d3d_ref
, "IDirect3D3 refcount is %u\n", ref
);
1453 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1454 hr
= IDirect3DViewport2_QueryInterface(viewport3
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1455 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
1456 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1457 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1458 /* NULL iid: Segfaults */
1460 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IDirect3DViewport
, (void **)&viewport
);
1461 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport, hr %#x.\n", hr
);
1464 ref
= get_refcount((IUnknown
*)viewport
);
1465 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1466 ref
= get_refcount((IUnknown
*)viewport3
);
1467 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1468 IDirect3DViewport_Release(viewport
);
1472 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IDirect3DViewport3
, (void **)&viewport2
);
1473 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1476 ref
= get_refcount((IUnknown
*)viewport2
);
1477 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1478 ref
= get_refcount((IUnknown
*)viewport3
);
1479 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1480 IDirect3DViewport3_Release(viewport2
);
1483 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IUnknown
, (void **)&unknown
);
1484 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1487 ref
= get_refcount((IUnknown
*)viewport3
);
1488 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1489 ref
= get_refcount(unknown
);
1490 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1491 IUnknown_Release(unknown
);
1494 /* AddViewport(NULL): Segfault */
1495 hr
= IDirect3DDevice3_DeleteViewport(device
, NULL
);
1496 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1497 hr
= IDirect3DDevice3_GetCurrentViewport(device
, NULL
);
1498 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1500 hr
= IDirect3D3_CreateViewport(d3d
, &another_vp
, NULL
);
1501 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1503 /* Setting a viewport not in the viewport list fails */
1504 hr
= IDirect3DDevice3_SetCurrentViewport(device
, another_vp
);
1505 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1507 hr
= IDirect3DDevice3_AddViewport(device
, viewport3
);
1508 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1509 ref
= get_refcount((IUnknown
*) viewport3
);
1510 ok(ref
== 2, "viewport3 refcount is %d\n", ref
);
1511 hr
= IDirect3DDevice3_AddViewport(device
, another_vp
);
1512 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1513 ref
= get_refcount((IUnknown
*) another_vp
);
1514 ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1516 test_vp
= (IDirect3DViewport3
*) 0xbaadc0de;
1517 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1518 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1519 ok(test_vp
== (IDirect3DViewport3
*) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp
);
1521 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport3
);
1522 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1523 ref
= get_refcount((IUnknown
*) viewport3
);
1524 ok(ref
== 3, "viewport3 refcount is %d\n", ref
);
1525 ref
= get_refcount((IUnknown
*) device
);
1526 ok(ref
== 1, "device refcount is %d\n", ref
);
1529 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1530 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1531 ok(test_vp
== viewport3
, "Got unexpected viewport %p\n", test_vp
);
1532 ref
= get_refcount((IUnknown
*) viewport3
);
1533 ok(ref
== 4, "viewport3 refcount is %d\n", ref
);
1534 if(test_vp
) IDirect3DViewport3_Release(test_vp
);
1536 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1538 /* Cannot set the viewport to NULL */
1539 hr
= IDirect3DDevice3_SetCurrentViewport(device
, NULL
);
1540 ok(hr
== DDERR_INVALIDPARAMS
, "Failed to set viewport to NULL, hr %#x.\n", hr
);
1542 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1543 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1544 ok(test_vp
== viewport3
, "Got unexpected viewport %p\n", test_vp
);
1545 if(test_vp
) IDirect3DViewport3_Release(test_vp
);
1547 /* SetCurrentViewport properly releases the old viewport's reference */
1548 hr
= IDirect3DDevice3_SetCurrentViewport(device
, another_vp
);
1549 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1550 ref
= get_refcount((IUnknown
*) viewport3
);
1551 ok(ref
== 2, "viewport3 refcount is %d\n", ref
);
1552 ref
= get_refcount((IUnknown
*) another_vp
);
1553 ok(ref
== 3, "another_vp refcount is %d\n", ref
);
1555 /* Unlike device2::DeleteViewport, device3::DeleteViewport releases the
1556 * reference held by SetCurrentViewport */
1557 hr
= IDirect3DDevice3_DeleteViewport(device
, another_vp
);
1558 ok(SUCCEEDED(hr
), "Failed to delete viewport from device, hr %#x.\n", hr
);
1559 ref
= get_refcount((IUnknown
*) another_vp
);
1560 ok(ref
== 1, "another_vp refcount is %d\n", ref
);
1562 /* GetCurrentViewport still fails */
1564 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1565 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1566 ok(test_vp
== NULL
, "Got unexpected viewport %p\n", test_vp
);
1567 if(test_vp
) IDirect3DViewport3_Release(test_vp
);
1569 /* Setting a different viewport doesn't have any surprises now */
1570 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport3
);
1571 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1572 ref
= get_refcount((IUnknown
*) viewport3
);
1573 ok(ref
== 3, "viewport3 refcount is %d\n", ref
);
1574 ref
= get_refcount((IUnknown
*) another_vp
);
1575 ok(ref
== 1, "another_vp refcount is %d\n", ref
);
1577 /* Destroying the device removes the viewport and releases the reference */
1578 IDirect3DDevice3_Release(device
);
1579 ref
= get_refcount((IUnknown
*) viewport3
);
1580 ok(ref
== 1, "viewport3 refcount is %d\n", ref
);
1582 ref
= IDirect3DViewport3_Release(another_vp
);
1583 ok(ref
== 0, "Got unexpected ref %d\n", ref
);
1584 ref
= IDirect3DViewport3_Release(viewport3
);
1585 ok(ref
== 0, "Got unexpected ref %d\n", ref
);
1586 IDirect3D3_Release(d3d
);
1587 DestroyWindow(window
);
1588 IDirectDraw4_Release(ddraw
);
1591 static void test_zenable(void)
1593 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1596 struct vec4 position
;
1601 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1602 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1603 {{640.0f
, 480.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1604 {{640.0f
, 0.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1606 IDirect3DViewport3
*viewport
;
1607 IDirect3DDevice3
*device
;
1608 IDirectDrawSurface4
*rt
;
1615 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1616 0, 0, 640, 480, 0, 0, 0, 0);
1617 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1619 skip("Failed to create a 3D device, skipping test.\n");
1620 DestroyWindow(window
);
1624 viewport
= create_viewport(device
, 0, 0, 640, 480);
1625 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1626 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1628 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1629 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1631 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 0.0f
, 0);
1632 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1633 hr
= IDirect3DDevice3_BeginScene(device
);
1634 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1635 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, tquad
, 4, 0);
1636 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1637 hr
= IDirect3DDevice3_EndScene(device
);
1638 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1640 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1641 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1642 for (i
= 0; i
< 4; ++i
)
1644 for (j
= 0; j
< 4; ++j
)
1646 x
= 80 * ((2 * j
) + 1);
1647 y
= 60 * ((2 * i
) + 1);
1648 color
= get_surface_color(rt
, x
, y
);
1649 ok(compare_color(color
, 0x0000ff00, 1),
1650 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1653 IDirectDrawSurface4_Release(rt
);
1655 destroy_viewport(device
, viewport
);
1656 IDirect3DDevice3_Release(device
);
1657 DestroyWindow(window
);
1660 static void test_ck_rgba(void)
1662 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1665 struct vec4 position
;
1666 struct vec2 texcoord
;
1670 {{ 0.0f
, 480.0f
, 0.25f
, 1.0f
}, {0.0f
, 0.0f
}},
1671 {{ 0.0f
, 0.0f
, 0.25f
, 1.0f
}, {0.0f
, 1.0f
}},
1672 {{640.0f
, 480.0f
, 0.25f
, 1.0f
}, {1.0f
, 0.0f
}},
1673 {{640.0f
, 0.0f
, 0.25f
, 1.0f
}, {1.0f
, 1.0f
}},
1674 {{ 0.0f
, 480.0f
, 0.75f
, 1.0f
}, {0.0f
, 0.0f
}},
1675 {{ 0.0f
, 0.0f
, 0.75f
, 1.0f
}, {0.0f
, 1.0f
}},
1676 {{640.0f
, 480.0f
, 0.75f
, 1.0f
}, {1.0f
, 0.0f
}},
1677 {{640.0f
, 0.0f
, 0.75f
, 1.0f
}, {1.0f
, 1.0f
}},
1681 D3DCOLOR fill_color
;
1684 D3DCOLOR result1
, result1_broken
;
1685 D3DCOLOR result2
, result2_broken
;
1689 /* r200 on Windows doesn't check the alpha component when applying the color
1690 * key, so the key matches on every texel. */
1691 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1692 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1693 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1694 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1695 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1696 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1697 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1698 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1701 IDirectDrawSurface4
*surface
;
1702 IDirect3DViewport3
*viewport
;
1703 DDSURFACEDESC2 surface_desc
;
1704 IDirect3DTexture2
*texture
;
1705 IDirect3DDevice3
*device
;
1706 IDirectDrawSurface4
*rt
;
1707 IDirectDraw4
*ddraw
;
1715 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1716 0, 0, 640, 480, 0, 0, 0, 0);
1717 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1719 skip("Failed to create a 3D device, skipping test.\n");
1720 DestroyWindow(window
);
1724 viewport
= create_viewport(device
, 0, 0, 640, 480);
1725 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1726 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1728 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1729 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1730 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1731 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1732 IDirect3D3_Release(d3d
);
1734 memset(&surface_desc
, 0, sizeof(surface_desc
));
1735 surface_desc
.dwSize
= sizeof(surface_desc
);
1736 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1737 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1738 surface_desc
.dwWidth
= 256;
1739 surface_desc
.dwHeight
= 256;
1740 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1741 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1742 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1743 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1744 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1745 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1746 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1747 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1748 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1749 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1750 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1751 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1752 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1754 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
1755 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1756 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1757 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1758 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1759 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1761 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1762 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1764 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1766 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1767 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1768 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1769 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1771 memset(&fx
, 0, sizeof(fx
));
1772 fx
.dwSize
= sizeof(fx
);
1773 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1774 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1775 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1777 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
,
1778 D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 1.0f
, 0);
1779 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1780 hr
= IDirect3DDevice3_BeginScene(device
);
1781 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1782 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1783 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1784 hr
= IDirect3DDevice3_EndScene(device
);
1785 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1787 color
= get_surface_color(rt
, 320, 240);
1788 ok(compare_color(color
, tests
[i
].result1
, 1) || compare_color(color
, tests
[i
].result1_broken
, 1),
1789 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1790 tests
[i
].result1
, i
, color
);
1792 U5(fx
).dwFillColor
= 0xff0000ff;
1793 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1794 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1796 hr
= IDirect3DDevice3_BeginScene(device
);
1797 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1798 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[4], 4, 0);
1799 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1800 hr
= IDirect3DDevice3_EndScene(device
);
1801 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1803 /* This tests that fragments that are masked out by the color key are
1804 * discarded, instead of just fully transparent. */
1805 color
= get_surface_color(rt
, 320, 240);
1806 ok(compare_color(color
, tests
[i
].result2
, 1) || compare_color(color
, tests
[i
].result2_broken
, 1),
1807 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1808 tests
[i
].result2
, i
, color
);
1811 IDirectDrawSurface4_Release(rt
);
1812 IDirect3DTexture2_Release(texture
);
1813 IDirectDrawSurface4_Release(surface
);
1814 destroy_viewport(device
, viewport
);
1815 IDirectDraw4_Release(ddraw
);
1816 IDirect3DDevice3_Release(device
);
1817 DestroyWindow(window
);
1820 static void test_ck_default(void)
1822 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1825 struct vec4 position
;
1826 struct vec2 texcoord
;
1830 {{ 0.0f
, 480.0f
, 0.0f
, 1.0f
}, {0.0f
, 0.0f
}},
1831 {{ 0.0f
, 0.0f
, 0.0f
, 1.0f
}, {0.0f
, 1.0f
}},
1832 {{640.0f
, 480.0f
, 0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
1833 {{640.0f
, 0.0f
, 0.0f
, 1.0f
}, {1.0f
, 1.0f
}},
1835 IDirectDrawSurface4
*surface
, *rt
;
1836 IDirect3DViewport3
*viewport
;
1837 DDSURFACEDESC2 surface_desc
;
1838 IDirect3DTexture2
*texture
;
1839 IDirect3DDevice3
*device
;
1840 IDirectDraw4
*ddraw
;
1848 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1849 0, 0, 640, 480, 0, 0, 0, 0);
1851 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1853 skip("Failed to create a 3D device, skipping test.\n");
1854 DestroyWindow(window
);
1858 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1859 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1860 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1861 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1862 IDirect3D3_Release(d3d
);
1864 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1865 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1867 viewport
= create_viewport(device
, 0, 0, 640, 480);
1868 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1869 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1871 memset(&surface_desc
, 0, sizeof(surface_desc
));
1872 surface_desc
.dwSize
= sizeof(surface_desc
);
1873 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1874 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1875 surface_desc
.dwWidth
= 256;
1876 surface_desc
.dwHeight
= 256;
1877 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1878 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1879 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1880 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1881 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1882 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1883 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1884 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1885 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1886 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1887 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1888 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1889 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
1890 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1892 memset(&fx
, 0, sizeof(fx
));
1893 fx
.dwSize
= sizeof(fx
);
1894 U5(fx
).dwFillColor
= 0x000000ff;
1895 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1896 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1898 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1899 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1900 hr
= IDirect3DDevice3_BeginScene(device
);
1901 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1902 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1903 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1904 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1905 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1906 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1907 hr
= IDirect3DDevice3_EndScene(device
);
1908 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1909 color
= get_surface_color(rt
, 320, 240);
1910 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1912 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1913 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1914 hr
= IDirect3DDevice3_BeginScene(device
);
1915 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1916 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1917 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1918 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1919 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1920 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1921 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1922 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1923 hr
= IDirect3DDevice3_EndScene(device
);
1924 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1925 color
= get_surface_color(rt
, 320, 240);
1926 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1928 IDirect3DTexture_Release(texture
);
1929 IDirectDrawSurface4_Release(surface
);
1930 destroy_viewport(device
, viewport
);
1931 IDirectDrawSurface4_Release(rt
);
1932 IDirect3DDevice3_Release(device
);
1933 IDirectDraw4_Release(ddraw
);
1934 DestroyWindow(window
);
1937 static void test_ck_complex(void)
1939 IDirectDrawSurface4
*surface
, *mipmap
, *tmp
;
1940 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
1941 DDSURFACEDESC2 surface_desc
;
1942 IDirect3DDevice3
*device
;
1943 DDCOLORKEY color_key
;
1944 IDirectDraw4
*ddraw
;
1951 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1952 0, 0, 640, 480, 0, 0, 0, 0);
1953 if (!(device
= create_device(window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1955 skip("Failed to create a 3D device, skipping test.\n");
1956 DestroyWindow(window
);
1959 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1960 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1961 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1962 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1963 IDirect3D3_Release(d3d
);
1965 memset(&surface_desc
, 0, sizeof(surface_desc
));
1966 surface_desc
.dwSize
= sizeof(surface_desc
);
1967 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1968 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1969 surface_desc
.dwWidth
= 128;
1970 surface_desc
.dwHeight
= 128;
1971 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1972 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1974 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1975 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1976 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1977 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1978 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1979 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1980 memset(&color_key
, 0, sizeof(color_key
));
1981 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1982 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1983 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1984 color_key
.dwColorSpaceLowValue
);
1985 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1986 color_key
.dwColorSpaceHighValue
);
1989 IDirectDrawSurface_AddRef(mipmap
);
1990 for (i
= 0; i
< 7; ++i
)
1992 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1993 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1995 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1996 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1997 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1998 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1999 hr
= IDirectDrawSurface4_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2000 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x, i %u.\n", hr
, i
);
2001 memset(&color_key
, 0, sizeof(color_key
));
2002 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2003 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x, i %u.\n", hr
, i
);
2004 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
2005 color_key
.dwColorSpaceLowValue
, i
);
2006 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
2007 color_key
.dwColorSpaceHighValue
, i
);
2009 IDirectDrawSurface_Release(mipmap
);
2013 memset(&color_key
, 0, sizeof(color_key
));
2014 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2015 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
2016 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2017 color_key
.dwColorSpaceLowValue
);
2018 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2019 color_key
.dwColorSpaceHighValue
);
2021 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
2022 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
2023 IDirectDrawSurface_Release(mipmap
);
2024 refcount
= IDirectDrawSurface4_Release(surface
);
2025 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2027 memset(&surface_desc
, 0, sizeof(surface_desc
));
2028 surface_desc
.dwSize
= sizeof(surface_desc
);
2029 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
2030 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
2031 U5(surface_desc
).dwBackBufferCount
= 1;
2032 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2033 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2035 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2036 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
2037 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
2038 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
2039 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2040 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
2041 memset(&color_key
, 0, sizeof(color_key
));
2042 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2043 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
2044 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2045 color_key
.dwColorSpaceLowValue
);
2046 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2047 color_key
.dwColorSpaceHighValue
);
2049 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &tmp
);
2050 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
2052 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2053 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
2054 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
2055 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
2056 hr
= IDirectDrawSurface4_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2057 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
2058 memset(&color_key
, 0, sizeof(color_key
));
2059 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2060 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
2061 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2062 color_key
.dwColorSpaceLowValue
);
2063 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2064 color_key
.dwColorSpaceHighValue
);
2066 IDirectDrawSurface_Release(tmp
);
2068 refcount
= IDirectDrawSurface4_Release(surface
);
2069 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2070 IDirectDraw4_Release(ddraw
);
2071 refcount
= IDirect3DDevice3_Release(device
);
2072 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2073 DestroyWindow(window
);
2079 REFIID refcount_iid
;
2083 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
2084 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
2086 ULONG refcount
, expected_refcount
;
2087 IUnknown
*iface1
, *iface2
;
2091 for (i
= 0; i
< entry_count
; ++i
)
2093 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
2094 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
2097 for (j
= 0; j
< entry_count
; ++j
)
2099 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
2100 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
2103 expected_refcount
= 0;
2104 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
2105 ++expected_refcount
;
2106 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
2107 ++expected_refcount
;
2108 refcount
= IUnknown_Release(iface2
);
2109 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2110 refcount
, test_name
, i
, j
, expected_refcount
);
2114 expected_refcount
= 0;
2115 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
2116 ++expected_refcount
;
2117 refcount
= IUnknown_Release(iface1
);
2118 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2119 refcount
, test_name
, i
, expected_refcount
);
2124 static void test_surface_qi(void)
2126 static const struct qi_test tests
[] =
2128 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface4
, S_OK
},
2129 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface4
, S_OK
},
2130 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
2131 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2132 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
2133 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
2134 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
2135 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
2136 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
2137 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
2138 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
2139 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
2140 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
2141 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
2142 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
2143 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
2144 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
2145 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
2146 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
2147 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
2148 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
2149 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
2150 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
2151 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
2152 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
2153 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
2154 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
2155 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
2156 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
2157 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
2158 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
2159 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
2160 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
2161 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
2162 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
2165 IDirectDrawSurface4
*surface
;
2166 DDSURFACEDESC2 surface_desc
;
2167 IDirect3DDevice3
*device
;
2168 IDirectDraw4
*ddraw
;
2172 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2174 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2178 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2179 0, 0, 640, 480, 0, 0, 0, 0);
2180 /* Try to create a D3D device to see if the ddraw implementation supports
2181 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2182 * doesn't support e.g. the IDirect3DTexture interfaces. */
2183 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
2185 skip("Failed to create a 3D device, skipping test.\n");
2186 DestroyWindow(window
);
2189 IDirect3DDevice_Release(device
);
2190 ddraw
= create_ddraw();
2191 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2192 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2193 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
2195 memset(&surface_desc
, 0, sizeof(surface_desc
));
2196 surface_desc
.dwSize
= sizeof(surface_desc
);
2197 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2198 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2199 surface_desc
.dwWidth
= 512;
2200 surface_desc
.dwHeight
= 512;
2201 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2202 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2204 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface4
, tests
, sizeof(tests
) / sizeof(*tests
));
2206 IDirectDrawSurface4_Release(surface
);
2207 IDirectDraw4_Release(ddraw
);
2208 DestroyWindow(window
);
2211 static void test_device_qi(void)
2213 static const struct qi_test tests
[] =
2215 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
2216 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
2217 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
2218 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2219 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
2220 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
2221 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
2222 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
2223 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
2224 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
2225 {&IID_IDirect3DDevice3
, &IID_IDirect3DDevice3
, S_OK
},
2226 {&IID_IDirect3DDevice2
, &IID_IDirect3DDevice3
, S_OK
},
2227 {&IID_IDirect3DDevice
, &IID_IDirect3DDevice3
, S_OK
},
2228 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
2229 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
2230 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
2231 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
2232 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
2233 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
2234 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
2235 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
2236 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
2237 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
2238 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
2239 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
2240 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
2241 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
2242 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
2243 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
2244 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
2245 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
2246 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
2247 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
2248 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
2249 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
2250 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
2251 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
2252 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
2253 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
2254 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
2255 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
2256 {&IID_IUnknown
, &IID_IDirect3DDevice3
, S_OK
},
2259 IDirect3DDevice3
*device
;
2262 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2263 0, 0, 640, 480, 0, 0, 0, 0);
2264 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
2266 skip("Failed to create a 3D device, skipping test.\n");
2267 DestroyWindow(window
);
2271 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice3
, tests
, sizeof(tests
) / sizeof(*tests
));
2273 IDirect3DDevice3_Release(device
);
2274 DestroyWindow(window
);
2277 static void test_wndproc(void)
2279 LONG_PTR proc
, ddraw_proc
;
2280 IDirectDraw4
*ddraw
;
2286 static struct message messages
[] =
2288 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2289 {WM_MOVE
, FALSE
, 0},
2290 {WM_SIZE
, FALSE
, 0},
2291 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2292 {WM_ACTIVATE
, FALSE
, 0},
2293 {WM_SETFOCUS
, FALSE
, 0},
2297 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2298 ddraw
= create_ddraw();
2299 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2301 wc
.lpfnWndProc
= test_proc
;
2302 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2303 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2305 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2306 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2308 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2309 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2310 (LONG_PTR
)test_proc
, proc
);
2311 expect_messages
= messages
;
2312 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2313 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2314 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2315 expect_messages
= NULL
;
2316 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2317 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2318 (LONG_PTR
)test_proc
, proc
);
2319 ref
= IDirectDraw4_Release(ddraw
);
2320 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2321 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2322 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2323 (LONG_PTR
)test_proc
, proc
);
2325 /* DDSCL_NORMAL doesn't. */
2326 ddraw
= create_ddraw();
2327 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2328 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2329 (LONG_PTR
)test_proc
, proc
);
2330 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2331 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2332 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2333 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2334 (LONG_PTR
)test_proc
, proc
);
2335 ref
= IDirectDraw4_Release(ddraw
);
2336 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2337 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2338 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2339 (LONG_PTR
)test_proc
, proc
);
2341 /* The original window proc is only restored by ddraw if the current
2342 * window proc matches the one ddraw set. This also affects switching
2343 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2344 ddraw
= create_ddraw();
2345 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2346 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2347 (LONG_PTR
)test_proc
, proc
);
2348 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2349 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2350 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2351 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2352 (LONG_PTR
)test_proc
, proc
);
2354 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2355 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2356 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2357 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2358 (LONG_PTR
)test_proc
, proc
);
2359 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2360 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2361 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2362 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2363 (LONG_PTR
)test_proc
, proc
);
2364 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2365 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2366 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2367 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2368 (LONG_PTR
)DefWindowProcA
, proc
);
2369 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2370 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2371 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2372 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2373 (LONG_PTR
)DefWindowProcA
, proc
);
2374 ref
= IDirectDraw4_Release(ddraw
);
2375 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2376 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2377 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2378 (LONG_PTR
)test_proc
, proc
);
2380 ddraw
= create_ddraw();
2381 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2382 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2383 (LONG_PTR
)test_proc
, proc
);
2384 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2385 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2386 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2387 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2388 (LONG_PTR
)test_proc
, proc
);
2389 ref
= IDirectDraw4_Release(ddraw
);
2390 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2391 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2392 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2393 (LONG_PTR
)DefWindowProcA
, proc
);
2395 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2396 expect_messages
= NULL
;
2397 DestroyWindow(window
);
2398 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2401 static void test_window_style(void)
2403 LONG style
, exstyle
, tmp
, expected_style
;
2404 RECT fullscreen_rect
, r
;
2405 IDirectDraw4
*ddraw
;
2411 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2412 0, 0, 100, 100, 0, 0, 0, 0);
2413 ddraw
= create_ddraw();
2414 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2416 style
= GetWindowLongA(window
, GWL_STYLE
);
2417 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2418 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2420 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2421 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2423 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2424 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2425 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2426 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2428 GetWindowRect(window
, &r
);
2429 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2430 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2431 r
.left
, r
.top
, r
.right
, r
.bottom
);
2432 GetClientRect(window
, &r
);
2433 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2435 ret
= SetForegroundWindow(GetDesktopWindow());
2436 ok(ret
, "Failed to set foreground window.\n");
2438 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2439 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2440 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2441 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2443 ret
= SetForegroundWindow(window
);
2444 ok(ret
, "Failed to set foreground window.\n");
2445 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2446 * the next tests expect this. */
2447 ShowWindow(window
, SW_HIDE
);
2449 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2450 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2452 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2453 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2454 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2455 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2457 ShowWindow(window
, SW_SHOW
);
2458 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2459 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2461 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2462 expected_style
= style
| WS_VISIBLE
;
2463 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2464 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2465 expected_style
= exstyle
| WS_EX_TOPMOST
;
2466 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2468 ret
= SetForegroundWindow(GetDesktopWindow());
2469 ok(ret
, "Failed to set foreground window.\n");
2470 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2471 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2472 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2473 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2474 expected_style
= exstyle
| WS_EX_TOPMOST
;
2475 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2477 ref
= IDirectDraw4_Release(ddraw
);
2478 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2480 DestroyWindow(window
);
2483 static void test_redundant_mode_set(void)
2485 DDSURFACEDESC2 surface_desc
= {0};
2486 IDirectDraw4
*ddraw
;
2492 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2493 0, 0, 100, 100, 0, 0, 0, 0);
2494 ddraw
= create_ddraw();
2495 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2497 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2498 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2500 surface_desc
.dwSize
= sizeof(surface_desc
);
2501 hr
= IDirectDraw4_GetDisplayMode(ddraw
, &surface_desc
);
2502 ok(SUCCEEDED(hr
), "GetDipslayMode failed, hr %#x.\n", hr
);
2504 hr
= IDirectDraw4_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2505 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2506 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2508 GetWindowRect(window
, &r
);
2511 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2512 GetWindowRect(window
, &s
);
2513 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2514 r
.left
, r
.top
, r
.right
, r
.bottom
,
2515 s
.left
, s
.top
, s
.right
, s
.bottom
);
2517 hr
= IDirectDraw4_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2518 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2519 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2521 GetWindowRect(window
, &s
);
2522 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2523 r
.left
, r
.top
, r
.right
, r
.bottom
,
2524 s
.left
, s
.top
, s
.right
, s
.bottom
);
2526 ref
= IDirectDraw4_Release(ddraw
);
2527 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2529 DestroyWindow(window
);
2532 static SIZE screen_size
, screen_size2
;
2534 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2536 if (message
== WM_SIZE
)
2538 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2539 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2542 return test_proc(hwnd
, message
, wparam
, lparam
);
2545 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2547 if (message
== WM_SIZE
)
2549 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2550 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2553 return test_proc(hwnd
, message
, wparam
, lparam
);
2556 struct test_coop_level_mode_set_enum_param
2558 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2561 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC2
*surface_desc
, void *context
)
2563 struct test_coop_level_mode_set_enum_param
*param
= context
;
2565 if (U1(U4(*surface_desc
).ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2566 return DDENUMRET_OK
;
2567 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2568 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2569 return DDENUMRET_OK
;
2571 if (!param
->ddraw_width
)
2573 param
->ddraw_width
= surface_desc
->dwWidth
;
2574 param
->ddraw_height
= surface_desc
->dwHeight
;
2575 return DDENUMRET_OK
;
2577 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2578 return DDENUMRET_OK
;
2580 param
->user32_width
= surface_desc
->dwWidth
;
2581 param
->user32_height
= surface_desc
->dwHeight
;
2582 return DDENUMRET_CANCEL
;
2585 static void test_coop_level_mode_set(void)
2587 IDirectDrawSurface4
*primary
;
2588 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2589 IDirectDraw4
*ddraw
;
2590 DDSURFACEDESC2 ddsd
;
2592 HWND window
, window2
;
2596 struct test_coop_level_mode_set_enum_param param
;
2601 static const struct message exclusive_messages
[] =
2603 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2604 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2605 {WM_SIZE
, FALSE
, 0},
2606 {WM_DISPLAYCHANGE
, FALSE
, 0},
2609 static const struct message exclusive_focus_loss_messages
[] =
2611 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2612 {WM_DISPLAYCHANGE
, FALSE
, 0},
2613 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2614 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2615 * SW_MINIMIZED, causing a recursive window activation that does not
2616 * produce the same result in Wine yet. Ignore the difference for now.
2617 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2618 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2619 {WM_MOVE
, FALSE
, 0},
2620 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2621 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2624 static const struct message exclusive_focus_restore_messages
[] =
2626 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2627 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2628 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2629 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2630 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2631 /* Native redundantly sets the window size here. */
2632 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2633 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2634 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2635 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2638 static const struct message sc_restore_messages
[] =
2640 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2641 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2642 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2643 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2646 static const struct message sc_minimize_messages
[] =
2648 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2649 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2650 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2651 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2654 static const struct message sc_maximize_messages
[] =
2656 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2657 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2658 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2659 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2663 static const struct message normal_messages
[] =
2665 {WM_DISPLAYCHANGE
, FALSE
, 0},
2669 ddraw
= create_ddraw();
2670 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2672 memset(¶m
, 0, sizeof(param
));
2673 hr
= IDirectDraw4_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2674 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2675 ref
= IDirectDraw4_Release(ddraw
);
2676 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2678 if (!param
.user32_height
)
2680 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2684 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2685 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2686 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2688 memset(&devmode
, 0, sizeof(devmode
));
2689 devmode
.dmSize
= sizeof(devmode
);
2690 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2691 devmode
.dmPelsWidth
= param
.user32_width
;
2692 devmode
.dmPelsHeight
= param
.user32_height
;
2693 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2694 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2696 ddraw
= create_ddraw();
2697 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2699 wc
.lpfnWndProc
= mode_set_proc
;
2700 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2701 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2702 wc
.lpfnWndProc
= mode_set_proc2
;
2703 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2704 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2706 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2707 0, 0, 100, 100, 0, 0, 0, 0);
2708 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2709 0, 0, 100, 100, 0, 0, 0, 0);
2711 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2712 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2714 GetWindowRect(window
, &r
);
2715 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2716 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2717 r
.left
, r
.top
, r
.right
, r
.bottom
);
2719 memset(&ddsd
, 0, sizeof(ddsd
));
2720 ddsd
.dwSize
= sizeof(ddsd
);
2721 ddsd
.dwFlags
= DDSD_CAPS
;
2722 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2724 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2725 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2726 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2727 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2728 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2729 param
.user32_width
, ddsd
.dwWidth
);
2730 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2731 param
.user32_height
, ddsd
.dwHeight
);
2733 GetWindowRect(window
, &r
);
2734 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2735 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2736 r
.left
, r
.top
, r
.right
, r
.bottom
);
2738 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2739 expect_messages
= exclusive_messages
;
2743 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2744 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2746 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2747 expect_messages
= NULL
;
2748 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2749 "Expected screen size %ux%u, got %ux%u.\n",
2750 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2752 GetWindowRect(window
, &r
);
2753 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2754 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2755 r
.left
, r
.top
, r
.right
, r
.bottom
);
2757 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2758 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2759 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2760 param
.user32_width
, ddsd
.dwWidth
);
2761 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2762 param
.user32_height
, ddsd
.dwHeight
);
2763 IDirectDrawSurface4_Release(primary
);
2765 memset(&ddsd
, 0, sizeof(ddsd
));
2766 ddsd
.dwSize
= sizeof(ddsd
);
2767 ddsd
.dwFlags
= DDSD_CAPS
;
2768 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2770 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2771 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2772 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2773 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2774 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2775 param
.ddraw_width
, ddsd
.dwWidth
);
2776 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2777 param
.ddraw_height
, ddsd
.dwHeight
);
2779 GetWindowRect(window
, &r
);
2780 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2781 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2782 r
.left
, r
.top
, r
.right
, r
.bottom
);
2784 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2785 expect_messages
= exclusive_messages
;
2789 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2790 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2792 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2793 expect_messages
= NULL
;
2794 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2795 "Expected screen size %ux%u, got %ux%u.\n",
2796 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2798 GetWindowRect(window
, &r
);
2799 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2800 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2801 r
.left
, r
.top
, r
.right
, r
.bottom
);
2803 expect_messages
= exclusive_focus_loss_messages
;
2804 ret
= SetForegroundWindow(GetDesktopWindow());
2805 ok(ret
, "Failed to set foreground window.\n");
2806 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2807 memset(&devmode
, 0, sizeof(devmode
));
2808 devmode
.dmSize
= sizeof(devmode
);
2809 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2810 ok(ret
, "Failed to get display mode.\n");
2811 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2812 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2813 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2815 expect_messages
= exclusive_focus_restore_messages
;
2816 ShowWindow(window
, SW_RESTORE
);
2817 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2819 GetWindowRect(window
, &r
);
2820 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2821 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2822 r
.left
, r
.top
, r
.right
, r
.bottom
);
2823 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2824 ok(ret
, "Failed to get display mode.\n");
2825 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2826 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2827 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2829 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2830 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2831 /* Normally the primary should be restored here. Unfortunately this causes the
2832 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2833 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2834 * the point of the GetSurfaceDesc call. */
2836 expect_messages
= sc_minimize_messages
;
2837 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2838 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2839 expect_messages
= NULL
;
2841 expect_messages
= sc_restore_messages
;
2842 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2843 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2844 expect_messages
= NULL
;
2846 expect_messages
= sc_maximize_messages
;
2847 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2848 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2849 expect_messages
= NULL
;
2851 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2852 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2854 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2855 expect_messages
= exclusive_messages
;
2859 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
2860 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2862 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2863 expect_messages
= NULL
;
2864 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2865 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2866 "Expected screen size %ux%u, got %ux%u.\n",
2867 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2869 GetWindowRect(window
, &r
);
2870 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2871 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2872 r
.left
, r
.top
, r
.right
, r
.bottom
);
2874 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2875 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2876 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2877 param
.ddraw_width
, ddsd
.dwWidth
);
2878 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2879 param
.ddraw_height
, ddsd
.dwHeight
);
2880 IDirectDrawSurface4_Release(primary
);
2883 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2884 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2886 memset(&ddsd
, 0, sizeof(ddsd
));
2887 ddsd
.dwSize
= sizeof(ddsd
);
2888 ddsd
.dwFlags
= DDSD_CAPS
;
2889 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2891 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2892 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2893 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2894 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2895 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2896 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2897 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2898 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2900 GetWindowRect(window
, &r
);
2901 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2902 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2903 r
.left
, r
.top
, r
.right
, r
.bottom
);
2905 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2906 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2908 GetWindowRect(window
, &r
);
2909 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2910 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2911 r
.left
, r
.top
, r
.right
, r
.bottom
);
2913 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2914 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2915 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2916 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2917 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2918 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2919 IDirectDrawSurface4_Release(primary
);
2921 memset(&ddsd
, 0, sizeof(ddsd
));
2922 ddsd
.dwSize
= sizeof(ddsd
);
2923 ddsd
.dwFlags
= DDSD_CAPS
;
2924 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2926 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2927 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2928 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2929 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2930 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2931 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2932 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2933 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2935 GetWindowRect(window
, &r
);
2936 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2937 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2938 r
.left
, r
.top
, r
.right
, r
.bottom
);
2940 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2941 expect_messages
= normal_messages
;
2945 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2946 devmode
.dmPelsWidth
= param
.user32_width
;
2947 devmode
.dmPelsHeight
= param
.user32_height
;
2948 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2949 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2951 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2952 expect_messages
= NULL
;
2953 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2955 GetWindowRect(window
, &r
);
2956 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2957 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2958 r
.left
, r
.top
, r
.right
, r
.bottom
);
2960 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2961 expect_messages
= normal_messages
;
2965 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2966 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2968 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2969 expect_messages
= NULL
;
2970 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2972 GetWindowRect(window
, &r
);
2973 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2974 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2975 r
.left
, r
.top
, r
.right
, r
.bottom
);
2977 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2978 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2979 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2980 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2981 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2982 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2983 IDirectDrawSurface4_Release(primary
);
2985 memset(&ddsd
, 0, sizeof(ddsd
));
2986 ddsd
.dwSize
= sizeof(ddsd
);
2987 ddsd
.dwFlags
= DDSD_CAPS
;
2988 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2990 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2991 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2992 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2993 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2994 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2995 param
.ddraw_width
, ddsd
.dwWidth
);
2996 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2997 param
.ddraw_height
, ddsd
.dwHeight
);
2999 GetWindowRect(window
, &r
);
3000 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3001 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3002 r
.left
, r
.top
, r
.right
, r
.bottom
);
3004 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3005 expect_messages
= normal_messages
;
3009 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
3010 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3012 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3013 expect_messages
= NULL
;
3014 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3016 GetWindowRect(window
, &r
);
3017 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3018 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3019 r
.left
, r
.top
, r
.right
, r
.bottom
);
3021 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3022 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3023 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3024 param
.ddraw_width
, ddsd
.dwWidth
);
3025 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3026 param
.ddraw_height
, ddsd
.dwHeight
);
3027 IDirectDrawSurface4_Release(primary
);
3029 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3030 ok(ret
, "Failed to get display mode.\n");
3031 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3032 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3033 "Expected resolution %ux%u, got %ux%u.\n",
3034 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3035 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3036 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3037 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3039 memset(&ddsd
, 0, sizeof(ddsd
));
3040 ddsd
.dwSize
= sizeof(ddsd
);
3041 ddsd
.dwFlags
= DDSD_CAPS
;
3042 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3044 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3045 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3046 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3047 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3048 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3049 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3050 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3051 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3053 GetWindowRect(window
, &r
);
3054 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3055 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3056 r
.left
, r
.top
, r
.right
, r
.bottom
);
3058 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
3059 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
3060 * not DDSCL_FULLSCREEN. */
3061 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3062 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3064 GetWindowRect(window
, &r
);
3065 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3066 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3067 r
.left
, r
.top
, r
.right
, r
.bottom
);
3069 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3070 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3071 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3072 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3073 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3074 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3075 IDirectDrawSurface4_Release(primary
);
3077 memset(&ddsd
, 0, sizeof(ddsd
));
3078 ddsd
.dwSize
= sizeof(ddsd
);
3079 ddsd
.dwFlags
= DDSD_CAPS
;
3080 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3082 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3083 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3084 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3085 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3086 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3087 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3088 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3089 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3091 GetWindowRect(window
, &r
);
3092 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3093 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3094 r
.left
, r
.top
, r
.right
, r
.bottom
);
3096 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3097 expect_messages
= normal_messages
;
3101 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
3102 devmode
.dmPelsWidth
= param
.user32_width
;
3103 devmode
.dmPelsHeight
= param
.user32_height
;
3104 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3105 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3107 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3108 expect_messages
= NULL
;
3109 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3111 GetWindowRect(window
, &r
);
3112 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3113 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3114 r
.left
, r
.top
, r
.right
, r
.bottom
);
3116 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3117 expect_messages
= normal_messages
;
3121 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3122 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3124 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3125 expect_messages
= NULL
;
3126 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3128 GetWindowRect(window
, &r
);
3129 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3130 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3131 r
.left
, r
.top
, r
.right
, r
.bottom
);
3133 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3134 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3135 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3136 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3137 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3138 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3139 IDirectDrawSurface4_Release(primary
);
3141 memset(&ddsd
, 0, sizeof(ddsd
));
3142 ddsd
.dwSize
= sizeof(ddsd
);
3143 ddsd
.dwFlags
= DDSD_CAPS
;
3144 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3146 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3147 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3148 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3149 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3150 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3151 param
.ddraw_width
, ddsd
.dwWidth
);
3152 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3153 param
.ddraw_height
, ddsd
.dwHeight
);
3155 GetWindowRect(window
, &r
);
3156 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3157 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3158 r
.left
, r
.top
, r
.right
, r
.bottom
);
3160 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3161 expect_messages
= normal_messages
;
3165 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
3166 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3168 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3169 expect_messages
= NULL
;
3170 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3172 GetWindowRect(window
, &r
);
3173 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3174 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3175 r
.left
, r
.top
, r
.right
, r
.bottom
);
3177 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3178 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3179 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3180 param
.ddraw_width
, ddsd
.dwWidth
);
3181 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3182 param
.ddraw_height
, ddsd
.dwHeight
);
3183 IDirectDrawSurface4_Release(primary
);
3185 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3186 ok(ret
, "Failed to get display mode.\n");
3187 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3188 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3189 "Expected resolution %ux%u, got %ux%u.\n",
3190 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3191 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3192 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3193 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3195 memset(&ddsd
, 0, sizeof(ddsd
));
3196 ddsd
.dwSize
= sizeof(ddsd
);
3197 ddsd
.dwFlags
= DDSD_CAPS
;
3198 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3200 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3201 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3202 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3203 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3204 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3205 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3206 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3207 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3208 IDirectDrawSurface4_Release(primary
);
3210 GetWindowRect(window
, &r
);
3211 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3212 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3213 r
.left
, r
.top
, r
.right
, r
.bottom
);
3215 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3216 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3217 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3218 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3219 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3221 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3222 expect_messages
= exclusive_messages
;
3226 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3227 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3229 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3230 expect_messages
= NULL
;
3231 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
3232 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
3233 "Expected screen size %ux%u, got %ux%u.\n",
3234 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3235 screen_size
.cx
, screen_size
.cy
);
3237 GetWindowRect(window
, &r
);
3238 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3239 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3240 r
.left
, r
.top
, r
.right
, r
.bottom
);
3242 memset(&ddsd
, 0, sizeof(ddsd
));
3243 ddsd
.dwSize
= sizeof(ddsd
);
3244 ddsd
.dwFlags
= DDSD_CAPS
;
3245 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3247 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3248 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3249 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3250 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3251 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3252 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3253 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3254 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3255 IDirectDrawSurface4_Release(primary
);
3257 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3258 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3259 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3260 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3261 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3263 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3264 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3266 memset(&ddsd
, 0, sizeof(ddsd
));
3267 ddsd
.dwSize
= sizeof(ddsd
);
3268 ddsd
.dwFlags
= DDSD_CAPS
;
3269 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3271 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3272 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3273 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3274 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3275 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3276 param
.ddraw_width
, ddsd
.dwWidth
);
3277 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3278 param
.ddraw_height
, ddsd
.dwHeight
);
3279 IDirectDrawSurface4_Release(primary
);
3281 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
3282 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3284 /* If the window is changed at the same time, messages are sent to the new window. */
3285 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3286 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3287 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3288 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3290 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3291 expect_messages
= exclusive_messages
;
3294 screen_size2
.cx
= 0;
3295 screen_size2
.cy
= 0;
3297 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3298 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3300 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3301 expect_messages
= NULL
;
3302 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
3303 screen_size
.cx
, screen_size
.cy
);
3304 ok(screen_size2
.cx
== registry_mode
.dmPelsWidth
&& screen_size2
.cy
== registry_mode
.dmPelsHeight
,
3305 "Expected screen size 2 %ux%u, got %ux%u.\n",
3306 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size2
.cx
, screen_size2
.cy
);
3308 GetWindowRect(window
, &r
);
3309 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3310 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
3311 r
.left
, r
.top
, r
.right
, r
.bottom
);
3312 GetWindowRect(window2
, &r
);
3313 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3314 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3315 r
.left
, r
.top
, r
.right
, r
.bottom
);
3317 memset(&ddsd
, 0, sizeof(ddsd
));
3318 ddsd
.dwSize
= sizeof(ddsd
);
3319 ddsd
.dwFlags
= DDSD_CAPS
;
3320 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3322 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3323 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3324 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3325 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3326 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3327 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3328 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3329 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3330 IDirectDrawSurface4_Release(primary
);
3332 ref
= IDirectDraw4_Release(ddraw
);
3333 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3335 GetWindowRect(window
, &r
);
3336 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3337 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
3338 r
.left
, r
.top
, r
.right
, r
.bottom
);
3340 expect_messages
= NULL
;
3341 DestroyWindow(window
);
3342 DestroyWindow(window2
);
3343 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3344 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3347 static void test_coop_level_mode_set_multi(void)
3349 IDirectDraw4
*ddraw1
, *ddraw2
;
3355 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3356 0, 0, 100, 100, 0, 0, 0, 0);
3357 ddraw1
= create_ddraw();
3358 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3360 /* With just a single ddraw object, the display mode is restored on
3362 hr
= set_display_mode(ddraw1
, 800, 600);
3363 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3364 w
= GetSystemMetrics(SM_CXSCREEN
);
3365 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3366 h
= GetSystemMetrics(SM_CYSCREEN
);
3367 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3369 ref
= IDirectDraw4_Release(ddraw1
);
3370 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3371 w
= GetSystemMetrics(SM_CXSCREEN
);
3372 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3373 h
= GetSystemMetrics(SM_CYSCREEN
);
3374 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3376 /* When there are multiple ddraw objects, the display mode is restored to
3377 * the initial mode, before the first SetDisplayMode() call. */
3378 ddraw1
= create_ddraw();
3379 hr
= set_display_mode(ddraw1
, 800, 600);
3380 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3381 w
= GetSystemMetrics(SM_CXSCREEN
);
3382 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3383 h
= GetSystemMetrics(SM_CYSCREEN
);
3384 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3386 ddraw2
= create_ddraw();
3387 hr
= set_display_mode(ddraw2
, 640, 480);
3388 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3389 w
= GetSystemMetrics(SM_CXSCREEN
);
3390 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3391 h
= GetSystemMetrics(SM_CYSCREEN
);
3392 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3394 ref
= IDirectDraw4_Release(ddraw2
);
3395 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3396 w
= GetSystemMetrics(SM_CXSCREEN
);
3397 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3398 h
= GetSystemMetrics(SM_CYSCREEN
);
3399 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3401 ref
= IDirectDraw4_Release(ddraw1
);
3402 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3403 w
= GetSystemMetrics(SM_CXSCREEN
);
3404 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3405 h
= GetSystemMetrics(SM_CYSCREEN
);
3406 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3408 /* Regardless of release ordering. */
3409 ddraw1
= create_ddraw();
3410 hr
= set_display_mode(ddraw1
, 800, 600);
3411 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3412 w
= GetSystemMetrics(SM_CXSCREEN
);
3413 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3414 h
= GetSystemMetrics(SM_CYSCREEN
);
3415 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3417 ddraw2
= create_ddraw();
3418 hr
= set_display_mode(ddraw2
, 640, 480);
3419 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3420 w
= GetSystemMetrics(SM_CXSCREEN
);
3421 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3422 h
= GetSystemMetrics(SM_CYSCREEN
);
3423 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3425 ref
= IDirectDraw4_Release(ddraw1
);
3426 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3427 w
= GetSystemMetrics(SM_CXSCREEN
);
3428 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3429 h
= GetSystemMetrics(SM_CYSCREEN
);
3430 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3432 ref
= IDirectDraw4_Release(ddraw2
);
3433 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3434 w
= GetSystemMetrics(SM_CXSCREEN
);
3435 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3436 h
= GetSystemMetrics(SM_CYSCREEN
);
3437 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3439 /* But only for ddraw objects that called SetDisplayMode(). */
3440 ddraw1
= create_ddraw();
3441 ddraw2
= create_ddraw();
3442 hr
= set_display_mode(ddraw2
, 640, 480);
3443 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3444 w
= GetSystemMetrics(SM_CXSCREEN
);
3445 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3446 h
= GetSystemMetrics(SM_CYSCREEN
);
3447 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3449 ref
= IDirectDraw4_Release(ddraw1
);
3450 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3451 w
= GetSystemMetrics(SM_CXSCREEN
);
3452 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3453 h
= GetSystemMetrics(SM_CYSCREEN
);
3454 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3456 ref
= IDirectDraw4_Release(ddraw2
);
3457 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3458 w
= GetSystemMetrics(SM_CXSCREEN
);
3459 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3460 h
= GetSystemMetrics(SM_CYSCREEN
);
3461 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3463 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3464 * restoring the display mode. */
3465 ddraw1
= create_ddraw();
3466 hr
= set_display_mode(ddraw1
, 800, 600);
3467 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3468 w
= GetSystemMetrics(SM_CXSCREEN
);
3469 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3470 h
= GetSystemMetrics(SM_CYSCREEN
);
3471 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3473 ddraw2
= create_ddraw();
3474 hr
= set_display_mode(ddraw2
, 640, 480);
3475 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3476 w
= GetSystemMetrics(SM_CXSCREEN
);
3477 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3478 h
= GetSystemMetrics(SM_CYSCREEN
);
3479 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3481 hr
= IDirectDraw4_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3482 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3484 ref
= IDirectDraw4_Release(ddraw1
);
3485 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3486 w
= GetSystemMetrics(SM_CXSCREEN
);
3487 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3488 h
= GetSystemMetrics(SM_CYSCREEN
);
3489 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3491 ref
= IDirectDraw4_Release(ddraw2
);
3492 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3493 w
= GetSystemMetrics(SM_CXSCREEN
);
3494 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3495 h
= GetSystemMetrics(SM_CYSCREEN
);
3496 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3498 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3499 ddraw1
= create_ddraw();
3500 hr
= set_display_mode(ddraw1
, 800, 600);
3501 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3502 w
= GetSystemMetrics(SM_CXSCREEN
);
3503 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3504 h
= GetSystemMetrics(SM_CYSCREEN
);
3505 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3507 hr
= IDirectDraw4_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3508 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3510 ddraw2
= create_ddraw();
3511 hr
= set_display_mode(ddraw2
, 640, 480);
3512 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3514 ref
= IDirectDraw4_Release(ddraw1
);
3515 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3516 w
= GetSystemMetrics(SM_CXSCREEN
);
3517 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3518 h
= GetSystemMetrics(SM_CYSCREEN
);
3519 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3521 ref
= IDirectDraw4_Release(ddraw2
);
3522 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3523 w
= GetSystemMetrics(SM_CXSCREEN
);
3524 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3525 h
= GetSystemMetrics(SM_CYSCREEN
);
3526 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3528 DestroyWindow(window
);
3531 static void test_initialize(void)
3533 IDirectDraw4
*ddraw
;
3536 ddraw
= create_ddraw();
3537 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3539 hr
= IDirectDraw4_Initialize(ddraw
, NULL
);
3540 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3541 IDirectDraw4_Release(ddraw
);
3544 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw4
, (void **)&ddraw
);
3545 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw4 instance, hr %#x.\n", hr
);
3546 hr
= IDirectDraw4_Initialize(ddraw
, NULL
);
3547 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3548 hr
= IDirectDraw4_Initialize(ddraw
, NULL
);
3549 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3550 IDirectDraw4_Release(ddraw
);
3554 static void test_coop_level_surf_create(void)
3556 IDirectDrawSurface4
*surface
;
3557 IDirectDraw4
*ddraw
;
3558 DDSURFACEDESC2 ddsd
;
3561 ddraw
= create_ddraw();
3562 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3564 memset(&ddsd
, 0, sizeof(ddsd
));
3565 ddsd
.dwSize
= sizeof(ddsd
);
3566 ddsd
.dwFlags
= DDSD_CAPS
;
3567 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3568 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3569 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3571 IDirectDraw4_Release(ddraw
);
3574 static void test_vb_discard(void)
3576 static const struct vec4 quad
[] =
3578 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
3579 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
3580 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
3581 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
3584 IDirect3DDevice3
*device
;
3586 IDirect3DVertexBuffer
*buffer
;
3589 D3DVERTEXBUFFERDESC desc
;
3591 static const unsigned int vbsize
= 16;
3594 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3595 0, 0, 640, 480, 0, 0, 0, 0);
3597 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3599 skip("Failed to create a 3D device, skipping test.\n");
3600 DestroyWindow(window
);
3604 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
3605 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
3607 memset(&desc
, 0, sizeof(desc
));
3608 desc
.dwSize
= sizeof(desc
);
3609 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
3610 desc
.dwFVF
= D3DFVF_XYZRHW
;
3611 desc
.dwNumVertices
= vbsize
;
3612 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0, NULL
);
3613 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3615 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3616 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3617 memcpy(data
, quad
, sizeof(quad
));
3618 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
3619 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3621 hr
= IDirect3DDevice3_BeginScene(device
);
3622 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3623 hr
= IDirect3DDevice3_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
3624 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3625 hr
= IDirect3DDevice3_EndScene(device
);
3626 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3628 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3629 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3630 memset(data
, 0xaa, sizeof(struct vec4
) * vbsize
);
3631 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
3632 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3634 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3635 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3636 for (i
= 0; i
< sizeof(struct vec4
) * vbsize
; i
++)
3638 if (data
[i
] != 0xaa)
3640 ok(FALSE
, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i
, data
[i
]);
3644 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
3645 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3647 IDirect3DVertexBuffer_Release(buffer
);
3648 IDirect3D3_Release(d3d
);
3649 IDirect3DDevice3_Release(device
);
3650 DestroyWindow(window
);
3653 static void test_coop_level_multi_window(void)
3655 HWND window1
, window2
;
3656 IDirectDraw4
*ddraw
;
3659 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3660 0, 0, 640, 480, 0, 0, 0, 0);
3661 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3662 0, 0, 640, 480, 0, 0, 0, 0);
3663 ddraw
= create_ddraw();
3664 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3666 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3667 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3668 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3669 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3670 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3671 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3673 IDirectDraw4_Release(ddraw
);
3674 DestroyWindow(window2
);
3675 DestroyWindow(window1
);
3678 static void test_draw_strided(void)
3680 static struct vec3 position
[] =
3687 static DWORD diffuse
[] =
3689 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3691 static WORD indices
[] =
3696 IDirectDrawSurface4
*rt
;
3697 IDirect3DDevice3
*device
;
3701 D3DDRAWPRIMITIVESTRIDEDDATA strided
;
3702 IDirect3DViewport3
*viewport
;
3703 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3705 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3706 0, 0, 640, 480, 0, 0, 0, 0);
3708 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3710 skip("Failed to create a 3D device, skipping test.\n");
3711 DestroyWindow(window
);
3715 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
3716 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3717 viewport
= create_viewport(device
, 0, 0, 640, 480);
3718 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
3719 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
3720 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
3721 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
3723 hr
= IDirect3DDevice3_BeginScene(device
);
3724 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3726 memset(&strided
, 0x55, sizeof(strided
));
3727 strided
.position
.lpvData
= position
;
3728 strided
.position
.dwStride
= sizeof(*position
);
3729 strided
.diffuse
.lpvData
= diffuse
;
3730 strided
.diffuse
.dwStride
= sizeof(*diffuse
);
3731 hr
= IDirect3DDevice3_DrawIndexedPrimitiveStrided(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
3732 &strided
, 4, indices
, 6, 0);
3733 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3735 hr
= IDirect3DDevice3_EndScene(device
);
3736 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3738 color
= get_surface_color(rt
, 320, 240);
3739 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3741 IDirect3DViewport3_Release(viewport
);
3742 IDirectDrawSurface4_Release(rt
);
3743 IDirect3DDevice3_Release(device
);
3744 DestroyWindow(window
);
3747 static void test_lighting(void)
3749 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3750 static D3DMATRIX mat
=
3752 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3753 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3754 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3755 0.0f
, 0.0f
, 0.0f
, 1.0f
,
3759 1.0f
, 0.0f
, 1.0f
, 0.0f
,
3760 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3761 1.0f
, 0.0f
, 1.0f
, 0.0f
,
3762 0.0f
, 0.0f
, 0.5f
, 1.0f
,
3766 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3767 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3768 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
3769 10.f
, 10.0f
, 10.0f
, 1.0f
,
3773 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3774 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3775 0.0f
, 0.0f
, 1.0f
, -1.0f
,
3776 10.f
, 10.0f
, 10.0f
, 0.0f
,
3780 struct vec3 position
;
3785 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
3786 {{-1.0f
, 0.0f
, 0.1f
}, 0xffff0000},
3787 {{ 0.0f
, 0.0f
, 0.1f
}, 0xffff0000},
3788 {{ 0.0f
, -1.0f
, 0.1f
}, 0xffff0000},
3792 {{-1.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
3793 {{-1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
3794 {{ 0.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
3795 {{ 0.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
3799 struct vec3 position
;
3805 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3806 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3807 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3808 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3812 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3813 {{0.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3814 {{1.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3815 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3819 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3820 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3821 {{ 1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3822 {{ 1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3826 {{-10.0f
, -11.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3827 {{-10.0f
, -9.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3828 {{-10.0f
, -9.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3829 {{-10.0f
, -11.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3833 {{-11.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3834 {{-11.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3835 {{ -9.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3836 {{ -9.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3838 static WORD indices
[] = {0, 1, 2, 2, 3, 0};
3841 D3DMATRIX
*world_matrix
;
3844 const char *message
;
3848 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
3849 {&mat_singular
, nquad
, 0x000000b4, "Lit quad with singular world matrix"},
3850 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
3851 {&mat_nonaffine
, translatedquad
, 0x000000ff, "Lit quad with non-affine matrix"},
3856 IDirect3DDevice3
*device
;
3857 IDirectDrawSurface4
*rt
;
3858 IDirect3DViewport3
*viewport
;
3859 IDirect3DMaterial3
*material
;
3860 IDirect3DLight
*light
;
3861 D3DMATERIALHANDLE mat_handle
;
3862 D3DLIGHT2 light_desc
;
3864 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
3865 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
3870 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3871 0, 0, 640, 480, 0, 0, 0, 0);
3872 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3874 skip("Failed to create a 3D device, skipping test.\n");
3875 DestroyWindow(window
);
3879 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
3880 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
3882 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
3883 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3885 viewport
= create_viewport(device
, 0, 0, 640, 480);
3886 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
3887 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3889 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
3890 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3892 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
3893 ok(SUCCEEDED(hr
), "Failed to set world transformation, hr %#x.\n", hr
);
3894 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
3895 ok(SUCCEEDED(hr
), "Failed to set view transformation, hr %#x.\n", hr
);
3896 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
3897 ok(SUCCEEDED(hr
), "Failed to set projection transformation, hr %#x.\n", hr
);
3898 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3899 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
3900 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
3901 ok(SUCCEEDED(hr
), "Failed to disable zbuffer, hr %#x.\n", hr
);
3902 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
3903 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
3904 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
3905 ok(SUCCEEDED(hr
), "Failed to disable stencil buffer, hr %#x.\n", hr
);
3906 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
3907 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
3909 hr
= IDirect3DDevice3_BeginScene(device
);
3910 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3912 /* There is no D3DRENDERSTATE_LIGHTING on ddraw < 7. */
3913 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3914 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3915 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, unlitquad
, 4,
3917 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3919 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
3920 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
3921 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, litquad
, 4,
3923 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3925 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3926 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3927 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, unlitnquad
, 4,
3929 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3931 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
3932 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
3933 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, litnquad
, 4,
3935 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3937 hr
= IDirect3DDevice3_EndScene(device
);
3938 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3940 color
= get_surface_color(rt
, 160, 360);
3941 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color
);
3942 color
= get_surface_color(rt
, 160, 120);
3943 ok(color
== 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color
);
3944 color
= get_surface_color(rt
, 480, 360);
3945 ok(color
== 0x000000ff, "Unlit quad with normals has color 0x%08x.\n", color
);
3946 color
= get_surface_color(rt
, 480, 120);
3947 ok(color
== 0x00ffff00, "Lit quad with normals has color 0x%08x.\n", color
);
3949 material
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
3950 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
3951 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
3952 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
3953 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
3955 hr
= IDirect3D3_CreateLight(d3d
, &light
, NULL
);
3956 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
3957 memset(&light_desc
, 0, sizeof(light_desc
));
3958 light_desc
.dwSize
= sizeof(light_desc
);
3959 light_desc
.dltType
= D3DLIGHT_DIRECTIONAL
;
3960 U1(light_desc
.dcvColor
).r
= 1.0f
;
3961 U2(light_desc
.dcvColor
).g
= 1.0f
;
3962 U3(light_desc
.dcvColor
).b
= 1.0f
;
3963 U4(light_desc
.dcvColor
).a
= 1.0f
;
3964 U3(light_desc
.dvDirection
).z
= 1.0f
;
3965 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
3966 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
3967 hr
= IDirect3DViewport3_AddLight(viewport
, light
);
3968 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
3970 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
3971 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3973 hr
= IDirect3DDevice3_BeginScene(device
);
3974 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3976 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, nquad
,
3978 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3980 hr
= IDirect3DDevice3_EndScene(device
);
3981 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3983 color
= get_surface_color(rt
, 320, 240);
3984 ok(color
== 0x00000000, "Lit quad with no light has color 0x%08x.\n", color
);
3986 light_desc
.dwFlags
= D3DLIGHT_ACTIVE
;
3987 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
3988 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
3990 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
3992 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, tests
[i
].world_matrix
);
3993 ok(SUCCEEDED(hr
), "Failed to set world transformation, hr %#x.\n", hr
);
3995 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
3996 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3998 hr
= IDirect3DDevice3_BeginScene(device
);
3999 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4001 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, tests
[i
].quad
,
4003 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4005 hr
= IDirect3DDevice3_EndScene(device
);
4006 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4008 color
= get_surface_color(rt
, 320, 240);
4009 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
4012 hr
= IDirect3DViewport3_DeleteLight(viewport
, light
);
4013 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
4014 IDirect3DLight_Release(light
);
4015 destroy_material(material
);
4016 IDirect3DViewport3_Release(viewport
);
4017 IDirectDrawSurface4_Release(rt
);
4018 refcount
= IDirect3DDevice3_Release(device
);
4019 ok(!refcount
, "Device has %u references left.\n", refcount
);
4020 IDirect3D3_Release(d3d
);
4021 DestroyWindow(window
);
4024 static void test_specular_lighting(void)
4026 static const unsigned int vertices_side
= 5;
4027 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
4028 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_NORMAL
;
4029 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
4030 static D3DMATRIX mat
=
4032 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4033 0.0f
, 1.0f
, 0.0f
, 0.0f
,
4034 0.0f
, 0.0f
, 1.0f
, 0.0f
,
4035 0.0f
, 0.0f
, 0.0f
, 1.0f
,
4037 static D3DLIGHT2 directional
=
4040 D3DLIGHT_DIRECTIONAL
,
4041 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
4042 {{0.0f
}, {0.0f
}, {0.0f
}},
4043 {{0.0f
}, {0.0f
}, {1.0f
}},
4049 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
4050 {{0.0f
}, {0.0f
}, {0.0f
}},
4051 {{0.0f
}, {0.0f
}, {0.0f
}},
4060 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
4061 {{0.0f
}, {0.0f
}, {0.0f
}},
4062 {{0.0f
}, {0.0f
}, {1.0f
}},
4066 M_PI
/ 12.0f
, M_PI
/ 3.0f
4071 D3DLIGHT_PARALLELPOINT
,
4072 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
4073 {{0.5f
}, {0.0f
}, {-1.0f
}},
4074 {{0.0f
}, {0.0f
}, {0.0f
}},
4076 static const struct expected_color
4081 expected_directional
[] =
4083 {160, 120, 0x003c3c3c},
4084 {320, 120, 0x00717171},
4085 {480, 120, 0x003c3c3c},
4086 {160, 240, 0x00717171},
4087 {320, 240, 0x00ffffff},
4088 {480, 240, 0x00717171},
4089 {160, 360, 0x003c3c3c},
4090 {320, 360, 0x00717171},
4091 {480, 360, 0x003c3c3c},
4095 {160, 120, 0x00000000},
4096 {320, 120, 0x00090909},
4097 {480, 120, 0x00000000},
4098 {160, 240, 0x00090909},
4099 {320, 240, 0x00fafafa},
4100 {480, 240, 0x00090909},
4101 {160, 360, 0x00000000},
4102 {320, 360, 0x00090909},
4103 {480, 360, 0x00000000},
4107 {160, 120, 0x00000000},
4108 {320, 120, 0x00020202},
4109 {480, 120, 0x00000000},
4110 {160, 240, 0x00020202},
4111 {320, 240, 0x00fafafa},
4112 {480, 240, 0x00020202},
4113 {160, 360, 0x00000000},
4114 {320, 360, 0x00020202},
4115 {480, 360, 0x00000000},
4117 expected_parallelpoint
[] =
4119 {160, 120, 0x00050505},
4120 {320, 120, 0x002c2c2c},
4121 {480, 120, 0x006e6e6e},
4122 {160, 240, 0x00090909},
4123 {320, 240, 0x00717171},
4124 {480, 240, 0x00ffffff},
4125 {160, 360, 0x00050505},
4126 {320, 360, 0x002c2c2c},
4127 {480, 360, 0x006e6e6e},
4133 const struct expected_color
*expected
;
4134 unsigned int expected_count
;
4138 /* D3DRENDERSTATE_LOCALVIEWER does not exist in D3D < 7 (the behavior is
4139 * the one you get on newer D3D versions with it set as TRUE). */
4140 {&directional
, FALSE
, expected_directional
,
4141 sizeof(expected_directional
) / sizeof(expected_directional
[0])},
4142 {&directional
, TRUE
, expected_directional
,
4143 sizeof(expected_directional
) / sizeof(expected_directional
[0])},
4144 {&point
, TRUE
, expected_point
,
4145 sizeof(expected_point
) / sizeof(expected_point
[0])},
4146 {&spot
, TRUE
, expected_spot
,
4147 sizeof(expected_spot
) / sizeof(expected_spot
[0])},
4148 {¶llelpoint
, TRUE
, expected_parallelpoint
,
4149 sizeof(expected_parallelpoint
) / sizeof(expected_parallelpoint
[0])},
4152 IDirect3DDevice3
*device
;
4153 IDirectDrawSurface4
*rt
;
4154 IDirect3DViewport3
*viewport
;
4155 IDirect3DMaterial3
*material
;
4156 IDirect3DLight
*light
;
4157 D3DMATERIALHANDLE mat_handle
;
4162 unsigned int i
, j
, x
, y
;
4165 struct vec3 position
;
4170 quad
= HeapAlloc(GetProcessHeap(), 0, vertices_side
* vertices_side
* sizeof(*quad
));
4171 indices
= HeapAlloc(GetProcessHeap(), 0, indices_count
* sizeof(*indices
));
4172 for (i
= 0, y
= 0; y
< vertices_side
; ++y
)
4174 for (x
= 0; x
< vertices_side
; ++x
)
4176 quad
[i
].position
.x
= x
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
4177 quad
[i
].position
.y
= y
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
4178 quad
[i
].position
.z
= 1.0f
;
4179 quad
[i
].normal
.x
= 0.0f
;
4180 quad
[i
].normal
.y
= 0.0f
;
4181 quad
[i
++].normal
.z
= -1.0f
;
4184 for (i
= 0, y
= 0; y
< (vertices_side
- 1); ++y
)
4186 for (x
= 0; x
< (vertices_side
- 1); ++x
)
4188 indices
[i
++] = y
* vertices_side
+ x
+ 1;
4189 indices
[i
++] = y
* vertices_side
+ x
;
4190 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
4191 indices
[i
++] = y
* vertices_side
+ x
+ 1;
4192 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
4193 indices
[i
++] = (y
+ 1) * vertices_side
+ x
+ 1;
4197 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4198 0, 0, 640, 480, 0, 0, 0, 0);
4199 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4201 skip("Failed to create a 3D device, skipping test.\n");
4202 DestroyWindow(window
);
4206 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
4207 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
4209 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
4210 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4212 viewport
= create_viewport(device
, 0, 0, 640, 480);
4213 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
4214 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
4216 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
4217 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
4218 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
4219 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
4220 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
4221 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
4222 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
4223 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
4224 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
4225 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
4226 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
4227 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
4229 material
= create_specular_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 30.0f
);
4230 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
4231 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
4232 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
4233 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
4235 hr
= IDirect3D3_CreateLight(d3d
, &light
, NULL
);
4236 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
4237 hr
= IDirect3DViewport3_AddLight(viewport
, light
);
4238 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
4240 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, TRUE
);
4241 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
4243 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
4245 tests
[i
].light
->dwFlags
= D3DLIGHT_ACTIVE
;
4246 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)tests
[i
].light
);
4247 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
4249 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LOCALVIEWER
, tests
[i
].local_viewer
);
4250 ok(SUCCEEDED(hr
), "Failed to set local viewer state, hr %#x.\n", hr
);
4252 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
4253 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
4255 hr
= IDirect3DDevice3_BeginScene(device
);
4256 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4258 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, quad
,
4259 vertices_side
* vertices_side
, indices
, indices_count
, 0);
4260 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4262 hr
= IDirect3DDevice3_EndScene(device
);
4263 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4265 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
4267 color
= get_surface_color(rt
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
4268 ok(compare_color(color
, tests
[i
].expected
[j
].color
, 1),
4269 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
4270 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
4271 tests
[i
].expected
[j
].y
, color
, i
);
4275 hr
= IDirect3DViewport3_DeleteLight(viewport
, light
);
4276 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
4277 IDirect3DLight_Release(light
);
4278 destroy_material(material
);
4279 IDirect3DViewport3_Release(viewport
);
4280 IDirectDrawSurface4_Release(rt
);
4281 refcount
= IDirect3DDevice3_Release(device
);
4282 ok(!refcount
, "Device has %u references left.\n", refcount
);
4283 IDirect3D3_Release(d3d
);
4284 DestroyWindow(window
);
4285 HeapFree(GetProcessHeap(), 0, indices
);
4286 HeapFree(GetProcessHeap(), 0, quad
);
4289 static void test_clear_rect_count(void)
4291 IDirectDrawSurface4
*rt
;
4292 IDirect3DDevice3
*device
;
4296 IDirect3DViewport3
*viewport
;
4297 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
4299 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4300 0, 0, 640, 480, 0, 0, 0, 0);
4301 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4303 skip("Failed to create a 3D device, skipping test.\n");
4304 DestroyWindow(window
);
4308 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
4309 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4311 viewport
= create_viewport(device
, 0, 0, 640, 480);
4312 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
4313 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
4314 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x00ffffff, 0.0f
, 0);
4315 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
4316 hr
= IDirect3DViewport3_Clear2(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
, 0x00ff0000, 0.0f
, 0);
4317 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
4318 hr
= IDirect3DViewport3_Clear2(viewport
, 0, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 0.0f
, 0);
4319 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
4320 hr
= IDirect3DViewport3_Clear2(viewport
, 1, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 0.0f
, 0);
4321 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
4323 color
= get_surface_color(rt
, 320, 240);
4324 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x000000ff, 1)),
4325 "Got unexpected color 0x%08x.\n", color
);
4327 IDirect3DViewport3_Release(viewport
);
4328 IDirectDrawSurface4_Release(rt
);
4329 IDirect3DDevice3_Release(device
);
4330 DestroyWindow(window
);
4333 static BOOL
test_mode_restored(IDirectDraw4
*ddraw
, HWND window
)
4335 DDSURFACEDESC2 ddsd1
, ddsd2
;
4338 memset(&ddsd1
, 0, sizeof(ddsd1
));
4339 ddsd1
.dwSize
= sizeof(ddsd1
);
4340 hr
= IDirectDraw4_GetDisplayMode(ddraw
, &ddsd1
);
4341 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
4343 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4344 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4345 hr
= set_display_mode(ddraw
, 640, 480);
4346 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
4347 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4348 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4350 memset(&ddsd2
, 0, sizeof(ddsd2
));
4351 ddsd2
.dwSize
= sizeof(ddsd2
);
4352 hr
= IDirectDraw4_GetDisplayMode(ddraw
, &ddsd2
);
4353 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
4354 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
4355 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
4357 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
4360 static void test_coop_level_versions(void)
4366 IDirectDrawSurface
*surface
;
4367 IDirectDraw4
*ddraw4
;
4370 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
4371 0, 0, 640, 480, 0, 0, 0, 0);
4373 ddraw4
= create_ddraw();
4374 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
4375 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
4376 restored
= test_mode_restored(ddraw4
, window
);
4377 ok(restored
, "Display mode not restored in new ddraw object\n");
4379 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
4380 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
4381 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4383 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4384 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
4385 restored
= test_mode_restored(ddraw4
, window
);
4386 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
4388 /* A successful one does */
4389 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4390 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4391 restored
= test_mode_restored(ddraw4
, window
);
4392 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
4394 IDirectDraw_Release(ddraw
);
4395 IDirectDraw4_Release(ddraw4
);
4397 ddraw4
= create_ddraw();
4398 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
4399 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
4400 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4402 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
4403 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4404 restored
= test_mode_restored(ddraw4
, window
);
4405 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
4407 IDirectDraw_Release(ddraw
);
4408 IDirectDraw4_Release(ddraw4
);
4410 /* A failing call does not restore the ddraw2+ behavior */
4411 ddraw4
= create_ddraw();
4412 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
4413 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
4414 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4416 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4417 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4418 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4419 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
4420 restored
= test_mode_restored(ddraw4
, window
);
4421 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
4423 IDirectDraw_Release(ddraw
);
4424 IDirectDraw4_Release(ddraw4
);
4426 /* Neither does a sequence of successful calls with the new interface */
4427 ddraw4
= create_ddraw();
4428 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
4429 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
4430 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4432 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4433 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4434 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4435 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4436 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, DDSCL_NORMAL
);
4437 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4439 restored
= test_mode_restored(ddraw4
, window
);
4440 ok(!restored
, "Display mode restored after ddraw1-ddraw4 SetCooperativeLevel() call sequence\n");
4441 IDirectDraw_Release(ddraw
);
4442 IDirectDraw4_Release(ddraw4
);
4444 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
4445 ddraw4
= create_ddraw();
4446 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
4447 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
4448 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4450 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, DDSCL_NORMAL
);
4451 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4453 memset(&ddsd
, 0, sizeof(ddsd
));
4454 ddsd
.dwSize
= sizeof(ddsd
);
4455 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4456 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4457 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
4458 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4459 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
4460 IDirectDrawSurface_Release(surface
);
4461 restored
= test_mode_restored(ddraw4
, window
);
4462 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
4464 IDirectDraw_Release(ddraw
);
4465 IDirectDraw4_Release(ddraw4
);
4466 DestroyWindow(window
);
4469 static void test_lighting_interface_versions(void)
4471 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
4472 IDirect3DMaterial3
*emissive
;
4473 IDirect3DViewport3
*viewport
;
4474 IDirect3DDevice3
*device
;
4475 IDirectDrawSurface4
*rt
;
4479 D3DMATERIALHANDLE mat_handle
;
4483 static D3DVERTEX quad
[] =
4485 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4486 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4487 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4488 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4491 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
4494 struct vec3 position
;
4496 DWORD diffuse
, specular
;
4500 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4501 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4502 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4503 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4506 static D3DLVERTEX lquad
[] =
4508 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4509 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4510 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4511 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4514 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
4517 struct vec3 position
;
4518 DWORD diffuse
, specular
;
4519 struct vec2 texcoord
;
4523 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4524 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4525 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4526 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4529 static D3DTLVERTEX tlquad
[] =
4531 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4532 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4533 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4534 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4541 DWORD d3drs_lighting
, d3drs_specular
;
4547 /* Lighting is enabled when all of these conditions are met:
4548 * 1) No pretransformed position(D3DFVF_XYZRHW)
4549 * 2) Normals are available (D3DFVF_NORMAL)
4550 * 3) D3DDP_DONOTLIGHT is not set.
4552 * D3DRENDERSTATE_LIGHTING is ignored, it is not defined
4553 * in this d3d version */
4556 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x0000ff00},
4557 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
4558 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4559 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4560 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x0000ff00},
4561 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
4562 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4563 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4566 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, 0, 0x0000ff00},
4567 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, 0, 0x0000ff00},
4568 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4569 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4570 /* The specular color in the vertex is ignored because
4571 * D3DRENDERSTATE_COLORVERTEX is not enabled */
4572 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, 0, 0x0000ff00},
4573 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, 0, 0x0000ff00},
4574 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4575 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4578 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
4579 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x00ff0000},
4580 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4581 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4582 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
4583 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x00ff8080},
4584 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4585 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4588 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, 0, 0x00ff0000},
4589 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, 0, 0x00ff0000},
4590 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4591 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4592 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, 0, 0x00ff8080},
4593 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, 0, 0x00ff8080},
4594 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4595 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4598 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
4599 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
4600 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
4601 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
4602 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
4603 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
4604 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
4605 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
4608 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4609 0, 0, 640, 480, 0, 0, 0, 0);
4611 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4613 skip("Failed to create a 3D device, skipping test.\n");
4614 DestroyWindow(window
);
4618 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
4619 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4621 viewport
= create_viewport(device
, 0, 0, 640, 480);
4622 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
4623 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
4625 emissive
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
4626 hr
= IDirect3DMaterial3_GetHandle(emissive
, device
, &mat_handle
);
4627 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
4628 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
4629 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
4630 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
4631 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
4633 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
4634 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
4635 ok(rs
== FALSE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs
);
4637 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4639 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff202020, 0.0f
, 0);
4640 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
4642 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
4643 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
4644 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
4645 tests
[i
].d3drs_specular
);
4646 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
4648 hr
= IDirect3DDevice3_BeginScene(device
);
4649 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4650 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
4651 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
4652 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4653 hr
= IDirect3DDevice3_EndScene(device
);
4654 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4656 color
= get_surface_color(rt
, 320, 240);
4657 ok(compare_color(color
, tests
[i
].color
, 1),
4658 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
4659 color
, tests
[i
].color
, i
);
4662 destroy_material(emissive
);
4663 IDirectDrawSurface4_Release(rt
);
4664 ref
= IDirect3DDevice3_Release(device
);
4665 ok(ref
== 0, "Device not properly released, refcount %u.\n", ref
);
4666 DestroyWindow(window
);
4672 IDirectDraw4
*ddraw
;
4675 } activateapp_testdata
;
4677 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
4679 if (message
== WM_ACTIVATEAPP
)
4681 if (activateapp_testdata
.ddraw
)
4684 activateapp_testdata
.received
= FALSE
;
4685 hr
= IDirectDraw4_SetCooperativeLevel(activateapp_testdata
.ddraw
,
4686 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
4687 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
4688 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
4690 activateapp_testdata
.received
= TRUE
;
4693 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
4696 static void test_coop_level_activateapp(void)
4698 IDirectDraw4
*ddraw
;
4702 DDSURFACEDESC2 ddsd
;
4703 IDirectDrawSurface4
*surface
;
4705 ddraw
= create_ddraw();
4706 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4708 wc
.lpfnWndProc
= activateapp_test_proc
;
4709 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
4710 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
4712 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
4713 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
4715 /* Exclusive with window already active. */
4716 SetForegroundWindow(window
);
4717 activateapp_testdata
.received
= FALSE
;
4718 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4719 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4720 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
4721 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4722 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4724 /* Exclusive with window not active. */
4725 SetForegroundWindow(GetDesktopWindow());
4726 activateapp_testdata
.received
= FALSE
;
4727 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4728 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4729 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4730 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4731 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4733 /* Normal with window not active, then exclusive with the same window. */
4734 SetForegroundWindow(GetDesktopWindow());
4735 activateapp_testdata
.received
= FALSE
;
4736 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4737 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4738 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
4739 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4740 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4741 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4742 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4743 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4745 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
4746 SetForegroundWindow(GetDesktopWindow());
4747 activateapp_testdata
.received
= FALSE
;
4748 activateapp_testdata
.ddraw
= ddraw
;
4749 activateapp_testdata
.window
= window
;
4750 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
4751 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4752 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4753 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4754 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4755 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4757 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
4758 * succeeding. Another switch to exclusive and back to normal is needed to release the
4759 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
4760 * WM_ACTIVATEAPP messages. */
4761 activateapp_testdata
.ddraw
= NULL
;
4762 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4763 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4764 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4765 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4767 /* Setting DDSCL_NORMAL with recursive invocation. */
4768 SetForegroundWindow(GetDesktopWindow());
4769 activateapp_testdata
.received
= FALSE
;
4770 activateapp_testdata
.ddraw
= ddraw
;
4771 activateapp_testdata
.window
= window
;
4772 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
4773 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4774 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4775 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4777 /* DDraw is in exlusive mode now. */
4778 memset(&ddsd
, 0, sizeof(ddsd
));
4779 ddsd
.dwSize
= sizeof(ddsd
);
4780 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4781 U5(ddsd
).dwBackBufferCount
= 1;
4782 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4783 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4784 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4785 IDirectDrawSurface4_Release(surface
);
4787 /* Recover again, just to be sure. */
4788 activateapp_testdata
.ddraw
= NULL
;
4789 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4790 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4791 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4792 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4794 DestroyWindow(window
);
4795 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
4796 IDirectDraw4_Release(ddraw
);
4799 static void test_texturemanage(void)
4801 IDirectDraw4
*ddraw
;
4803 DDSURFACEDESC2 ddsd
;
4804 IDirectDrawSurface4
*surface
;
4806 DDCAPS hal_caps
, hel_caps
;
4807 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
4810 DWORD caps_in
, caps2_in
;
4812 DWORD caps_out
, caps2_out
;
4816 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4818 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4820 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4822 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4824 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DD_OK
,
4825 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
},
4826 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DD_OK
,
4827 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
},
4828 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
4829 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_LOCALVIDMEM
, 0},
4830 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
4831 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0},
4833 {0, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4835 {0, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4837 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4839 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4841 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4843 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4845 {DDSCAPS_VIDEOMEMORY
, 0, DD_OK
,
4846 DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
, 0},
4847 {DDSCAPS_SYSTEMMEMORY
, 0, DD_OK
,
4848 DDSCAPS_SYSTEMMEMORY
, 0},
4851 ddraw
= create_ddraw();
4852 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4853 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4854 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4856 memset(&hal_caps
, 0, sizeof(hal_caps
));
4857 hal_caps
.dwSize
= sizeof(hal_caps
);
4858 memset(&hel_caps
, 0, sizeof(hel_caps
));
4859 hel_caps
.dwSize
= sizeof(hel_caps
);
4860 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, &hel_caps
);
4861 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4862 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
4864 skip("Managed textures not supported, skipping managed texture test.\n");
4865 IDirectDraw4_Release(ddraw
);
4869 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4871 memset(&ddsd
, 0, sizeof(ddsd
));
4872 ddsd
.dwSize
= sizeof(ddsd
);
4873 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4874 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps_in
;
4875 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2_in
;
4879 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4880 ok(hr
== tests
[i
].hr
, "Got unexpected, hr %#x, case %u.\n", hr
, i
);
4884 memset(&ddsd
, 0, sizeof(ddsd
));
4885 ddsd
.dwSize
= sizeof(ddsd
);
4886 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
4887 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4889 ok(ddsd
.ddsCaps
.dwCaps
== tests
[i
].caps_out
,
4890 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4891 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps_out
, ddsd
.ddsCaps
.dwCaps
, i
);
4892 ok(ddsd
.ddsCaps
.dwCaps2
== tests
[i
].caps2_out
,
4893 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4894 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps2_out
, ddsd
.ddsCaps
.dwCaps2
, i
);
4896 IDirectDrawSurface4_Release(surface
);
4899 IDirectDraw4_Release(ddraw
);
4902 #define SUPPORT_DXT1 0x01
4903 #define SUPPORT_DXT2 0x02
4904 #define SUPPORT_DXT3 0x04
4905 #define SUPPORT_DXT4 0x08
4906 #define SUPPORT_DXT5 0x10
4907 #define SUPPORT_YUY2 0x20
4908 #define SUPPORT_UYVY 0x40
4910 static HRESULT WINAPI
test_block_formats_creation_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
4912 DWORD
*supported_fmts
= ctx
;
4914 if (!(fmt
->dwFlags
& DDPF_FOURCC
))
4915 return DDENUMRET_OK
;
4917 switch (fmt
->dwFourCC
)
4919 case MAKEFOURCC('D','X','T','1'):
4920 *supported_fmts
|= SUPPORT_DXT1
;
4922 case MAKEFOURCC('D','X','T','2'):
4923 *supported_fmts
|= SUPPORT_DXT2
;
4925 case MAKEFOURCC('D','X','T','3'):
4926 *supported_fmts
|= SUPPORT_DXT3
;
4928 case MAKEFOURCC('D','X','T','4'):
4929 *supported_fmts
|= SUPPORT_DXT4
;
4931 case MAKEFOURCC('D','X','T','5'):
4932 *supported_fmts
|= SUPPORT_DXT5
;
4934 case MAKEFOURCC('Y','U','Y','2'):
4935 *supported_fmts
|= SUPPORT_YUY2
;
4937 case MAKEFOURCC('U','Y','V','Y'):
4938 *supported_fmts
|= SUPPORT_UYVY
;
4944 return DDENUMRET_OK
;
4947 static void test_block_formats_creation(void)
4949 HRESULT hr
, expect_hr
;
4950 unsigned int i
, j
, w
, h
;
4952 IDirectDraw4
*ddraw
;
4954 IDirect3DDevice3
*device
;
4955 IDirectDrawSurface4
*surface
;
4956 DWORD supported_fmts
= 0, supported_overlay_fmts
= 0;
4957 DWORD num_fourcc_codes
= 0, *fourcc_codes
;
4958 DDSURFACEDESC2 ddsd
;
4967 unsigned int block_width
;
4968 unsigned int block_height
;
4969 unsigned int block_size
;
4970 BOOL create_size_checked
, overlay
;
4974 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1
, 4, 4, 8, TRUE
, FALSE
},
4975 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2
, 4, 4, 16, TRUE
, FALSE
},
4976 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3
, 4, 4, 16, TRUE
, FALSE
},
4977 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4
, 4, 4, 16, TRUE
, FALSE
},
4978 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5
, 4, 4, 16, TRUE
, FALSE
},
4979 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2
, 2, 1, 4, FALSE
, TRUE
},
4980 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY
, 2, 1, 4, FALSE
, TRUE
},
4990 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4991 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4993 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4994 * Other hw / drivers successfully create those surfaces. Ignore them, this
4995 * suggests that no game uses this, otherwise Nvidia would support it. */
4997 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0,
4998 "videomemory texture", FALSE
5001 DDSCAPS_VIDEOMEMORY
| DDSCAPS_OVERLAY
, 0,
5002 "videomemory overlay", TRUE
5005 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0,
5006 "systemmemory texture", FALSE
5009 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
5010 "managed texture", FALSE
5022 enum size_type size_type
;
5028 {DDSD_LINEARSIZE
, SIZE_TYPE_ZERO
, 0, DD_OK
},
5029 {DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
5030 {DDSD_PITCH
, SIZE_TYPE_ZERO
, 0, DD_OK
},
5031 {DDSD_PITCH
, SIZE_TYPE_PITCH
, 0, DD_OK
},
5032 {DDSD_LPSURFACE
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
5033 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
5034 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_PITCH
, 0, DDERR_INVALIDPARAMS
},
5035 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
5036 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 1, DD_OK
},
5037 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, -1, DDERR_INVALIDPARAMS
},
5038 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_ZERO
, 0, DD_OK
},
5039 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_PITCH
, 0, DD_OK
},
5040 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_SIZE
, 0, DD_OK
},
5041 {DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
5044 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5045 0, 0, 640, 480, 0, 0, 0, 0);
5047 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5049 skip("Failed to create a 3D device, skipping test.\n");
5050 DestroyWindow(window
);
5054 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
5055 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5056 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **) &ddraw
);
5057 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5058 IDirect3D3_Release(d3d
);
5060 hr
= IDirect3DDevice3_EnumTextureFormats(device
, test_block_formats_creation_cb
,
5062 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
5064 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
5065 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
5066 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
5067 num_fourcc_codes
* sizeof(*fourcc_codes
));
5070 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
5071 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
5072 for (i
= 0; i
< num_fourcc_codes
; i
++)
5074 for (j
= 0; j
< sizeof(formats
) / sizeof(*formats
); j
++)
5076 if (fourcc_codes
[i
] == formats
[j
].fourcc
)
5077 supported_overlay_fmts
|= formats
[j
].support_flag
;
5080 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
5082 memset(&hal_caps
, 0, sizeof(hal_caps
));
5083 hal_caps
.dwSize
= sizeof(hal_caps
);
5084 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
5085 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5087 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 2 * 2 * 16 + 1);
5089 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
5091 for (j
= 0; j
< sizeof(types
) / sizeof(*types
); j
++)
5095 if (formats
[i
].overlay
!= types
[j
].overlay
5096 || (types
[j
].overlay
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
)))
5099 if (formats
[i
].overlay
)
5100 support
= supported_overlay_fmts
& formats
[i
].support_flag
;
5102 support
= supported_fmts
& formats
[i
].support_flag
;
5104 for (w
= 1; w
<= 8; w
++)
5106 for (h
= 1; h
<= 8; h
++)
5108 BOOL block_aligned
= TRUE
;
5111 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
5112 block_aligned
= FALSE
;
5114 memset(&ddsd
, 0, sizeof(ddsd
));
5115 ddsd
.dwSize
= sizeof(ddsd
);
5116 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
5117 ddsd
.ddsCaps
.dwCaps
= types
[j
].caps
;
5118 ddsd
.ddsCaps
.dwCaps2
= types
[j
].caps2
;
5119 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5120 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
5121 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
5125 /* TODO: Handle power of two limitations. I cannot test the pow2
5126 * behavior on windows because I have no hardware that doesn't at
5127 * least support np2_conditional. There's probably no HW that
5128 * supports DXTN textures but no conditional np2 textures. */
5129 if (!support
&& !(types
[j
].caps
& DDSCAPS_SYSTEMMEMORY
))
5130 expect_hr
= DDERR_INVALIDPARAMS
;
5131 else if (formats
[i
].create_size_checked
&& !block_aligned
)
5133 expect_hr
= DDERR_INVALIDPARAMS
;
5134 if (!(types
[j
].caps
& DDSCAPS_TEXTURE
))
5140 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5142 todo_wine
ok(hr
== expect_hr
,
5143 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
5144 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
5147 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
5148 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
5151 IDirectDrawSurface4_Release(surface
);
5156 if (formats
[i
].overlay
)
5159 for (j
= 0; j
< sizeof(user_mem_tests
) / sizeof(*user_mem_tests
); ++j
)
5161 memset(&ddsd
, 0, sizeof(ddsd
));
5162 ddsd
.dwSize
= sizeof(ddsd
);
5163 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| user_mem_tests
[j
].flags
;
5164 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
;
5166 switch (user_mem_tests
[j
].size_type
)
5168 case SIZE_TYPE_ZERO
:
5169 U1(ddsd
).dwLinearSize
= 0;
5172 case SIZE_TYPE_PITCH
:
5173 U1(ddsd
).dwLinearSize
= 2 * formats
[i
].block_size
;
5176 case SIZE_TYPE_SIZE
:
5177 U1(ddsd
).dwLinearSize
= 2 * 2 * formats
[i
].block_size
;
5180 U1(ddsd
).dwLinearSize
+= user_mem_tests
[j
].rel_size
;
5182 ddsd
.lpSurface
= mem
;
5183 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5184 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
5185 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
5189 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5190 ok(hr
== user_mem_tests
[j
].hr
, "Test %u: Got unexpected hr %#x, format %s.\n", j
, hr
, formats
[i
].name
);
5195 memset(&ddsd
, 0, sizeof(ddsd
));
5196 ddsd
.dwSize
= sizeof(ddsd
);
5197 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
5198 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", j
, hr
);
5199 ok(ddsd
.dwFlags
== (DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_LINEARSIZE
),
5200 "Test %u: Got unexpected flags %#x.\n", j
, ddsd
.dwFlags
);
5201 if (user_mem_tests
[j
].flags
& DDSD_LPSURFACE
)
5202 ok(U1(ddsd
).dwLinearSize
== ~0u, "Test %u: Got unexpected linear size %#x.\n",
5203 j
, U1(ddsd
).dwLinearSize
);
5205 ok(U1(ddsd
).dwLinearSize
== 2 * 2 * formats
[i
].block_size
,
5206 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
5207 j
, U1(ddsd
).dwLinearSize
, 2 * 2 * formats
[i
].block_size
);
5208 IDirectDrawSurface4_Release(surface
);
5212 HeapFree(GetProcessHeap(), 0, mem
);
5214 IDirectDraw4_Release(ddraw
);
5215 IDirect3DDevice3_Release(device
);
5216 DestroyWindow(window
);
5219 struct format_support_check
5221 const DDPIXELFORMAT
*format
;
5225 static HRESULT WINAPI
test_unsupported_formats_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
5227 struct format_support_check
*format
= ctx
;
5229 if (!memcmp(format
->format
, fmt
, sizeof(*fmt
)))
5231 format
->supported
= TRUE
;
5232 return DDENUMRET_CANCEL
;
5235 return DDENUMRET_OK
;
5238 static void test_unsupported_formats(void)
5241 BOOL expect_success
;
5243 IDirectDraw4
*ddraw
;
5245 IDirect3DDevice3
*device
;
5246 IDirectDrawSurface4
*surface
;
5247 DDSURFACEDESC2 ddsd
;
5249 DWORD expected_caps
;
5260 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
5261 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
5267 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
5268 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
5272 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
5274 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5275 0, 0, 640, 480, 0, 0, 0, 0);
5277 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5279 skip("Failed to create a 3D device, skipping test.\n");
5280 DestroyWindow(window
);
5284 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
5285 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5286 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **) &ddraw
);
5287 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5288 IDirect3D3_Release(d3d
);
5290 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
5292 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
5293 hr
= IDirect3DDevice3_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
5294 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
5296 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
5298 memset(&ddsd
, 0, sizeof(ddsd
));
5299 ddsd
.dwSize
= sizeof(ddsd
);
5300 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5301 U4(ddsd
).ddpfPixelFormat
= formats
[i
].fmt
;
5304 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
5306 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
5307 expect_success
= FALSE
;
5309 expect_success
= TRUE
;
5311 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5312 ok(SUCCEEDED(hr
) == expect_success
,
5313 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
5314 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
5318 memset(&ddsd
, 0, sizeof(ddsd
));
5319 ddsd
.dwSize
= sizeof(ddsd
);
5320 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
5321 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5323 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
5324 expected_caps
= DDSCAPS_VIDEOMEMORY
;
5325 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
5326 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
5327 else if (check
.supported
)
5328 expected_caps
= DDSCAPS_VIDEOMEMORY
;
5330 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
5332 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
5333 "Expected capability %#x, format %s, input cap %#x.\n",
5334 expected_caps
, formats
[i
].name
, caps
[j
]);
5336 IDirectDrawSurface4_Release(surface
);
5340 IDirectDraw4_Release(ddraw
);
5341 IDirect3DDevice3_Release(device
);
5342 DestroyWindow(window
);
5345 static void test_rt_caps(void)
5347 PALETTEENTRY palette_entries
[256];
5348 IDirectDrawPalette
*palette
;
5349 IDirectDraw4
*ddraw
;
5350 DDPIXELFORMAT z_fmt
;
5357 static const DDPIXELFORMAT p8_fmt
=
5359 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
5360 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
5365 const DDPIXELFORMAT
*pf
;
5368 HRESULT create_device_hr
;
5369 HRESULT set_rt_hr
, alternative_set_rt_hr
;
5375 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
5376 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5383 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5384 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5391 DDSCAPS_OFFSCREENPLAIN
,
5392 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5399 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5400 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5401 D3DERR_SURFACENOTINVIDMEM
,
5407 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5408 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5415 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
5416 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5424 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5432 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5439 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5440 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5441 D3DERR_SURFACENOTINVIDMEM
,
5447 DDSCAPS_SYSTEMMEMORY
,
5448 DDSCAPS_SYSTEMMEMORY
,
5456 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5463 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5465 DDERR_NOPALETTEATTACHED
,
5471 DDSCAPS_OFFSCREENPLAIN
,
5472 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5479 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5480 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5481 DDERR_NOPALETTEATTACHED
,
5487 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5488 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5495 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
5496 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5498 DDERR_INVALIDPIXELFORMAT
,
5503 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5504 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5506 DDERR_INVALIDPIXELFORMAT
,
5512 DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5519 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5520 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5522 DDERR_INVALIDPIXELFORMAT
,
5527 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
5528 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
5535 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5536 0, 0, 640, 480, 0, 0, 0, 0);
5537 ddraw
= create_ddraw();
5538 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5539 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5540 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5542 if (FAILED(IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
)))
5544 skip("D3D interface is not available, skipping test.\n");
5548 memset(&z_fmt
, 0, sizeof(z_fmt
));
5549 hr
= IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
5550 if (FAILED(hr
) || !z_fmt
.dwSize
)
5552 skip("No depth buffer formats available, skipping test.\n");
5553 IDirect3D3_Release(d3d
);
5557 memset(palette_entries
, 0, sizeof(palette_entries
));
5558 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
5559 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5561 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5563 IDirectDrawSurface4
*surface
, *rt
, *expected_rt
, *tmp
;
5564 DDSURFACEDESC2 surface_desc
;
5565 IDirect3DDevice3
*device
;
5567 memset(&surface_desc
, 0, sizeof(surface_desc
));
5568 surface_desc
.dwSize
= sizeof(surface_desc
);
5569 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5570 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5571 if (test_data
[i
].pf
)
5573 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5574 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
5576 surface_desc
.dwWidth
= 640;
5577 surface_desc
.dwHeight
= 480;
5578 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5579 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5580 i
, test_data
[i
].caps_in
, hr
);
5582 memset(&surface_desc
, 0, sizeof(surface_desc
));
5583 surface_desc
.dwSize
= sizeof(surface_desc
);
5584 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
5585 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5586 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
5587 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5588 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
5590 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
5591 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
5592 i
, hr
, test_data
[i
].create_device_hr
);
5595 if (hr
== DDERR_NOPALETTEATTACHED
)
5597 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
5598 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
5599 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
5600 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5601 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5603 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5605 IDirectDrawSurface4_Release(surface
);
5607 memset(&surface_desc
, 0, sizeof(surface_desc
));
5608 surface_desc
.dwSize
= sizeof(surface_desc
);
5609 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5610 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5611 surface_desc
.dwWidth
= 640;
5612 surface_desc
.dwHeight
= 480;
5613 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5614 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
5616 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
5617 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
5620 memset(&surface_desc
, 0, sizeof(surface_desc
));
5621 surface_desc
.dwSize
= sizeof(surface_desc
);
5622 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5623 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5624 if (test_data
[i
].pf
)
5626 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5627 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
5629 surface_desc
.dwWidth
= 640;
5630 surface_desc
.dwHeight
= 480;
5631 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
5632 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5633 i
, test_data
[i
].caps_in
, hr
);
5635 hr
= IDirect3DDevice3_SetRenderTarget(device
, rt
, 0);
5636 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
5637 "Test %u: Got unexpected hr %#x, expected %#x.\n",
5638 i
, hr
, test_data
[i
].set_rt_hr
);
5639 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
5642 expected_rt
= surface
;
5644 hr
= IDirect3DDevice3_GetRenderTarget(device
, &tmp
);
5645 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
5646 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
5648 IDirectDrawSurface4_Release(tmp
);
5649 IDirectDrawSurface4_Release(rt
);
5650 refcount
= IDirect3DDevice3_Release(device
);
5651 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
5652 refcount
= IDirectDrawSurface4_Release(surface
);
5653 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
5656 IDirectDrawPalette_Release(palette
);
5657 IDirect3D3_Release(d3d
);
5660 refcount
= IDirectDraw4_Release(ddraw
);
5661 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5662 DestroyWindow(window
);
5665 static void test_primary_caps(void)
5667 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
5668 IDirectDrawSurface4
*surface
;
5669 DDSURFACEDESC2 surface_desc
;
5670 IDirectDraw4
*ddraw
;
5680 DWORD back_buffer_count
;
5688 DDSCAPS_PRIMARYSURFACE
,
5691 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
5695 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
5702 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
5709 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
5716 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
5723 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
5730 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5737 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5744 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5746 DDERR_NOEXCLUSIVEMODE
,
5750 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5751 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5757 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5758 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5761 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
5764 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5765 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
5771 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5772 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
5779 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5780 0, 0, 640, 480, 0, 0, 0, 0);
5781 ddraw
= create_ddraw();
5782 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5784 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5786 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
5787 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5789 memset(&surface_desc
, 0, sizeof(surface_desc
));
5790 surface_desc
.dwSize
= sizeof(surface_desc
);
5791 surface_desc
.dwFlags
= DDSD_CAPS
;
5792 if (test_data
[i
].back_buffer_count
!= ~0u)
5793 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
5794 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5795 U5(surface_desc
).dwBackBufferCount
= test_data
[i
].back_buffer_count
;
5796 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5797 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
5801 memset(&surface_desc
, 0, sizeof(surface_desc
));
5802 surface_desc
.dwSize
= sizeof(surface_desc
);
5803 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
5804 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5805 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
5806 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5807 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
5809 IDirectDrawSurface4_Release(surface
);
5812 refcount
= IDirectDraw4_Release(ddraw
);
5813 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5814 DestroyWindow(window
);
5817 static void test_surface_lock(void)
5819 IDirectDraw4
*ddraw
;
5820 IDirect3D3
*d3d
= NULL
;
5821 IDirectDrawSurface4
*surface
;
5825 DDSURFACEDESC2 ddsd
;
5827 DDPIXELFORMAT z_fmt
;
5837 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
5839 "videomemory offscreenplain"
5842 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5844 "systemmemory offscreenplain"
5847 DDSCAPS_PRIMARYSURFACE
,
5852 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
5854 "videomemory texture"
5857 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
5859 "opaque videomemory texture"
5862 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
5864 "systemmemory texture"
5868 DDSCAPS2_TEXTUREMANAGE
,
5873 DDSCAPS2_D3DTEXTUREMANAGE
,
5878 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
5879 "opaque managed texture"
5883 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
5884 "opaque managed texture"
5887 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5898 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5899 0, 0, 640, 480, 0, 0, 0, 0);
5900 ddraw
= create_ddraw();
5901 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5902 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5903 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5905 if (FAILED(IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
)))
5907 skip("D3D interface is not available, skipping test.\n");
5911 memset(&z_fmt
, 0, sizeof(z_fmt
));
5912 hr
= IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
5913 if (FAILED(hr
) || !z_fmt
.dwSize
)
5915 skip("No depth buffer formats available, skipping test.\n");
5919 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5921 memset(&ddsd
, 0, sizeof(ddsd
));
5922 ddsd
.dwSize
= sizeof(ddsd
);
5923 ddsd
.dwFlags
= DDSD_CAPS
;
5924 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5926 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5930 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
5932 ddsd
.dwFlags
|= DDSD_PIXELFORMAT
;
5933 U4(ddsd
).ddpfPixelFormat
= z_fmt
;
5935 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
5936 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
5938 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5939 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5941 memset(&ddsd
, 0, sizeof(ddsd
));
5942 ddsd
.dwSize
= sizeof(ddsd
);
5943 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
5944 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5947 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
5948 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5951 IDirectDrawSurface4_Release(surface
);
5956 IDirect3D3_Release(d3d
);
5957 refcount
= IDirectDraw4_Release(ddraw
);
5958 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5959 DestroyWindow(window
);
5962 static void test_surface_discard(void)
5964 IDirect3DDevice3
*device
;
5966 IDirectDraw4
*ddraw
;
5969 DDSURFACEDESC2 ddsd
;
5970 IDirectDrawSurface4
*surface
, *target
;
5979 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
5980 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
5981 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
5982 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
5983 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
},
5984 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
5985 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
},
5986 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
5990 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5991 0, 0, 640, 480, 0, 0, 0, 0);
5993 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5995 skip("Failed to create a 3D device, skipping test.\n");
5996 DestroyWindow(window
);
5999 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
6000 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
6001 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
6002 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
6003 hr
= IDirect3DDevice3_GetRenderTarget(device
, &target
);
6004 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6006 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
6010 memset(&ddsd
, 0, sizeof(ddsd
));
6011 ddsd
.dwSize
= sizeof(ddsd
);
6012 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6013 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
6014 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
6017 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6018 ok(SUCCEEDED(hr
), "Failed to create offscreen surface, hr %#x, case %u.\n", hr
, i
);
6020 memset(&ddsd
, 0, sizeof(ddsd
));
6021 ddsd
.dwSize
= sizeof(ddsd
);
6022 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
6023 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6024 addr
= ddsd
.lpSurface
;
6025 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
6026 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6028 memset(&ddsd
, 0, sizeof(ddsd
));
6029 ddsd
.dwSize
= sizeof(ddsd
);
6030 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
6031 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6032 discarded
= ddsd
.lpSurface
!= addr
;
6033 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
6034 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6036 hr
= IDirectDrawSurface4_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
6037 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
6039 memset(&ddsd
, 0, sizeof(ddsd
));
6040 ddsd
.dwSize
= sizeof(ddsd
);
6041 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
6042 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6043 discarded
|= ddsd
.lpSurface
!= addr
;
6044 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
6045 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6047 IDirectDrawSurface4_Release(surface
);
6049 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
6050 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
6051 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
6054 IDirectDrawSurface4_Release(target
);
6055 IDirectDraw4_Release(ddraw
);
6056 IDirect3D3_Release(d3d
);
6057 IDirect3DDevice3_Release(device
);
6058 DestroyWindow(window
);
6061 static void test_flip(void)
6063 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
6064 IDirectDrawSurface4
*primary
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
6065 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
6066 DDSURFACEDESC2 surface_desc
;
6067 BOOL sysmem_primary
;
6068 IDirectDraw4
*ddraw
;
6075 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6076 0, 0, 640, 480, 0, 0, 0, 0);
6077 ddraw
= create_ddraw();
6078 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6080 hr
= set_display_mode(ddraw
, 640, 480);
6081 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
6082 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6083 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6085 memset(&surface_desc
, 0, sizeof(surface_desc
));
6086 surface_desc
.dwSize
= sizeof(surface_desc
);
6087 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6088 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6089 U5(surface_desc
).dwBackBufferCount
= 3;
6090 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6091 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6093 memset(&surface_desc
, 0, sizeof(surface_desc
));
6094 surface_desc
.dwSize
= sizeof(surface_desc
);
6095 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &surface_desc
);
6096 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6097 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
)
6098 == (DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
6099 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6100 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
6102 hr
= IDirectDrawSurface4_GetAttachedSurface(primary
, &caps
, &backbuffer1
);
6103 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6104 memset(&surface_desc
, 0, sizeof(surface_desc
));
6105 surface_desc
.dwSize
= sizeof(surface_desc
);
6106 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer1
, &surface_desc
);
6107 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6108 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
6109 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
| DDSCAPS_BACKBUFFER
),
6110 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6112 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
6113 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6114 memset(&surface_desc
, 0, sizeof(surface_desc
));
6115 surface_desc
.dwSize
= sizeof(surface_desc
);
6116 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer2
, &surface_desc
);
6117 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6118 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
6119 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
6120 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6122 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
6123 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6124 memset(&surface_desc
, 0, sizeof(surface_desc
));
6125 surface_desc
.dwSize
= sizeof(surface_desc
);
6126 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer3
, &surface_desc
);
6127 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6128 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
6129 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
6130 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6132 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
6133 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6134 ok(surface
== primary
, "Got unexpected surface %p, expected %p.\n", surface
, primary
);
6135 IDirectDrawSurface4_Release(surface
);
6137 memset(&surface_desc
, 0, sizeof(surface_desc
));
6138 surface_desc
.dwSize
= sizeof(surface_desc
);
6139 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6140 surface_desc
.ddsCaps
.dwCaps
= 0;
6141 surface_desc
.dwWidth
= 640;
6142 surface_desc
.dwHeight
= 480;
6143 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6144 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6145 hr
= IDirectDrawSurface4_Flip(primary
, surface
, DDFLIP_WAIT
);
6146 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6147 IDirectDrawSurface4_Release(surface
);
6149 hr
= IDirectDrawSurface4_Flip(primary
, primary
, DDFLIP_WAIT
);
6150 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6151 hr
= IDirectDrawSurface4_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
6152 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6153 hr
= IDirectDrawSurface4_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
6154 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6155 hr
= IDirectDrawSurface4_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
6156 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6158 memset(&fx
, 0, sizeof(fx
));
6159 fx
.dwSize
= sizeof(fx
);
6160 U5(fx
).dwFillColor
= 0xffff0000;
6161 hr
= IDirectDrawSurface4_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6162 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6163 U5(fx
).dwFillColor
= 0xff00ff00;
6164 hr
= IDirectDrawSurface4_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6165 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6166 U5(fx
).dwFillColor
= 0xff0000ff;
6167 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6168 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6170 hr
= IDirectDrawSurface4_Flip(primary
, NULL
, DDFLIP_WAIT
);
6171 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6172 color
= get_surface_color(backbuffer1
, 320, 240);
6173 /* The testbot seems to just copy the contents of one surface to all the
6174 * others, instead of properly flipping. */
6175 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6176 "Got unexpected color 0x%08x.\n", color
);
6177 color
= get_surface_color(backbuffer2
, 320, 240);
6178 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
6179 U5(fx
).dwFillColor
= 0xffff0000;
6180 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6181 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6183 hr
= IDirectDrawSurface4_Flip(primary
, NULL
, DDFLIP_WAIT
);
6184 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6185 color
= get_surface_color(backbuffer1
, 320, 240);
6186 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6187 "Got unexpected color 0x%08x.\n", color
);
6188 color
= get_surface_color(backbuffer2
, 320, 240);
6189 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6190 U5(fx
).dwFillColor
= 0xff00ff00;
6191 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6192 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6194 hr
= IDirectDrawSurface4_Flip(primary
, NULL
, DDFLIP_WAIT
);
6195 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6196 color
= get_surface_color(backbuffer1
, 320, 240);
6197 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6198 "Got unexpected color 0x%08x.\n", color
);
6199 color
= get_surface_color(backbuffer2
, 320, 240);
6200 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
6201 U5(fx
).dwFillColor
= 0xff0000ff;
6202 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6203 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6205 hr
= IDirectDrawSurface4_Flip(primary
, backbuffer1
, DDFLIP_WAIT
);
6206 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6207 color
= get_surface_color(backbuffer2
, 320, 240);
6208 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6209 "Got unexpected color 0x%08x.\n", color
);
6210 color
= get_surface_color(backbuffer3
, 320, 240);
6211 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
6212 U5(fx
).dwFillColor
= 0xffff0000;
6213 hr
= IDirectDrawSurface4_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6214 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6216 hr
= IDirectDrawSurface4_Flip(primary
, backbuffer2
, DDFLIP_WAIT
);
6217 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6218 color
= get_surface_color(backbuffer1
, 320, 240);
6219 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6220 color
= get_surface_color(backbuffer3
, 320, 240);
6221 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6222 "Got unexpected color 0x%08x.\n", color
);
6223 U5(fx
).dwFillColor
= 0xff00ff00;
6224 hr
= IDirectDrawSurface4_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6225 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6227 hr
= IDirectDrawSurface4_Flip(primary
, backbuffer3
, DDFLIP_WAIT
);
6228 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6229 color
= get_surface_color(backbuffer1
, 320, 240);
6230 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6231 "Got unexpected color 0x%08x.\n", color
);
6232 color
= get_surface_color(backbuffer2
, 320, 240);
6233 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
6235 IDirectDrawSurface4_Release(backbuffer3
);
6236 IDirectDrawSurface4_Release(backbuffer2
);
6237 IDirectDrawSurface4_Release(backbuffer1
);
6238 IDirectDrawSurface4_Release(primary
);
6239 refcount
= IDirectDraw4_Release(ddraw
);
6240 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
6241 DestroyWindow(window
);
6244 static void reset_ddsd(DDSURFACEDESC2
*ddsd
)
6246 memset(ddsd
, 0, sizeof(*ddsd
));
6247 ddsd
->dwSize
= sizeof(*ddsd
);
6250 static void test_set_surface_desc(void)
6252 IDirectDraw4
*ddraw
;
6255 DDSURFACEDESC2 ddsd
;
6256 IDirectDrawSurface4
*surface
;
6266 invalid_caps_tests
[] =
6268 {DDSCAPS_VIDEOMEMORY
, 0, FALSE
, "videomemory plain"},
6269 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, TRUE
, "systemmemory texture"},
6270 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
, "managed texture"},
6271 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
, "managed texture"},
6272 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
, "systemmemory primary"},
6275 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6276 0, 0, 640, 480, 0, 0, 0, 0);
6277 ddraw
= create_ddraw();
6278 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6279 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6280 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6283 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6286 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6287 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6288 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6289 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6290 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6291 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6292 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6294 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6295 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6298 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6299 ddsd
.lpSurface
= data
;
6300 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6301 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6303 /* Redundantly setting the same lpSurface is not an error. */
6304 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6305 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6306 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6307 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6308 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6309 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
6311 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
6312 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6313 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6314 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
6315 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
6316 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6319 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6320 ddsd
.lpSurface
= data
;
6321 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 1);
6322 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
6324 ddsd
.lpSurface
= NULL
;
6325 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6326 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
6328 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, NULL
, 0);
6329 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
6331 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6332 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6333 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6334 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6335 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6337 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
6338 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6339 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
6341 ddsd
.dwFlags
= DDSD_CAPS
;
6342 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6343 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6345 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
6346 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
6347 ddsd
.lpSurface
= data
;
6348 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6349 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6350 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6351 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6352 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6353 ddsd
.ddsCaps
.dwCaps
= 0;
6354 ddsd
.ddsCaps
.dwCaps2
= 0xdeadbeef;
6355 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6356 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6358 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6359 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6360 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6361 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6362 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6364 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
6366 ddsd
.dwFlags
= DDSD_HEIGHT
;
6368 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6369 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
6371 ddsd
.lpSurface
= data
;
6372 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
6373 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6374 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6377 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6378 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
6381 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6382 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
6383 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6384 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6386 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0 */
6388 ddsd
.dwFlags
= DDSD_PITCH
;
6389 U1(ddsd
).lPitch
= 8 * 4;
6390 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6391 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
6393 ddsd
.dwFlags
= DDSD_WIDTH
;
6395 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6396 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
6398 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
6399 ddsd
.lpSurface
= data
;
6400 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6401 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
6403 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
6404 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6405 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
6407 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6408 U1(ddsd
).lPitch
= 16 * 4;
6410 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6411 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6414 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6415 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6416 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6417 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6418 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
6420 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
6422 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
6423 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6424 U1(ddsd
).lPitch
= 4 * 4;
6425 ddsd
.lpSurface
= data
;
6426 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6427 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6429 U1(ddsd
).lPitch
= 4;
6430 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6431 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6433 U1(ddsd
).lPitch
= 16 * 4 + 1;
6434 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6435 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6437 U1(ddsd
).lPitch
= 16 * 4 + 3;
6438 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6439 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6441 U1(ddsd
).lPitch
= -4;
6442 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6443 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
6445 U1(ddsd
).lPitch
= 16 * 4;
6446 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6447 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6450 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6451 U1(ddsd
).lPitch
= 0;
6453 ddsd
.lpSurface
= data
;
6454 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6455 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
6457 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6458 U1(ddsd
).lPitch
= 16 * 4;
6460 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6461 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
6463 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
6464 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
6465 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6466 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6467 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6468 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6469 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6470 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6471 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6472 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
6474 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
6475 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6476 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6478 /* Can't set color keys. */
6480 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
6481 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
6482 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
6483 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6484 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6486 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
6487 ddsd
.lpSurface
= data
;
6488 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6489 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6491 IDirectDrawSurface4_Release(surface
);
6493 /* SetSurfaceDesc needs systemmemory surfaces.
6495 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
6496 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
6499 ddsd
.dwFlags
= DDSD_CAPS
;
6500 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
6501 ddsd
.ddsCaps
.dwCaps2
= invalid_caps_tests
[i
].caps2
;
6502 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
6504 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6507 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6508 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6509 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6510 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6511 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6512 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6515 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6516 ok(SUCCEEDED(hr
) || hr
== DDERR_NODIRECTDRAWHW
, "Failed to create surface, hr %#x.\n", hr
);
6519 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
6520 invalid_caps_tests
[i
].name
);
6525 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6526 ddsd
.lpSurface
= data
;
6527 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6528 if (invalid_caps_tests
[i
].supported
)
6530 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6534 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6535 invalid_caps_tests
[i
].name
, hr
);
6537 /* Check priority of error conditions. */
6538 ddsd
.dwFlags
= DDSD_WIDTH
;
6539 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6540 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6541 invalid_caps_tests
[i
].name
, hr
);
6544 IDirectDrawSurface4_Release(surface
);
6548 ref
= IDirectDraw4_Release(ddraw
);
6549 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6550 DestroyWindow(window
);
6553 static void test_user_memory_getdc(void)
6555 IDirectDraw4
*ddraw
;
6558 DDSURFACEDESC2 ddsd
;
6559 IDirectDrawSurface4
*surface
;
6565 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6566 0, 0, 640, 480, 0, 0, 0, 0);
6567 ddraw
= create_ddraw();
6568 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6570 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6571 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6574 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6577 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6578 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6579 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6580 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6581 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6582 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6583 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6584 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6585 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6587 memset(data
, 0xaa, sizeof(data
));
6589 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6590 ddsd
.lpSurface
= data
;
6591 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6592 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6594 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
6595 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6596 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
6597 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
6598 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
6599 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6601 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
6602 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
6604 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
6605 ddsd
.lpSurface
= data
;
6608 U1(ddsd
).lPitch
= sizeof(*data
);
6609 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6610 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6612 memset(data
, 0xaa, sizeof(data
));
6613 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
6614 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6615 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
6616 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
6617 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
6618 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6620 for (y
= 0; y
< 4; y
++)
6622 for (x
= 0; x
< 4; x
++)
6624 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
6625 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6628 ok(data
[y
][x
] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6632 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6634 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6636 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6638 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6641 IDirectDrawSurface4_Release(surface
);
6642 ref
= IDirectDraw4_Release(ddraw
);
6643 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6644 DestroyWindow(window
);
6647 static void test_sysmem_overlay(void)
6649 IDirectDraw4
*ddraw
;
6652 DDSURFACEDESC2 ddsd
;
6653 IDirectDrawSurface4
*surface
;
6656 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6657 0, 0, 640, 480, 0, 0, 0, 0);
6658 ddraw
= create_ddraw();
6659 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6661 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6662 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6665 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
6668 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
6669 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6670 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6671 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6672 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6673 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6674 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6675 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6676 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
6678 ref
= IDirectDraw4_Release(ddraw
);
6679 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6680 DestroyWindow(window
);
6683 static void test_primary_palette(void)
6685 DDSCAPS2 surface_caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
6686 IDirectDrawSurface4
*primary
, *backbuffer
;
6687 PALETTEENTRY palette_entries
[256];
6688 IDirectDrawPalette
*palette
, *tmp
;
6689 DDSURFACEDESC2 surface_desc
;
6690 IDirectDraw4
*ddraw
;
6696 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6697 0, 0, 640, 480, 0, 0, 0, 0);
6698 ddraw
= create_ddraw();
6699 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6700 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
6702 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6703 IDirectDraw4_Release(ddraw
);
6704 DestroyWindow(window
);
6707 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6708 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6710 memset(&surface_desc
, 0, sizeof(surface_desc
));
6711 surface_desc
.dwSize
= sizeof(surface_desc
);
6712 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6713 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6714 U5(surface_desc
).dwBackBufferCount
= 1;
6715 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6716 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6717 hr
= IDirectDrawSurface4_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
6718 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6720 memset(palette_entries
, 0, sizeof(palette_entries
));
6721 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
6722 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6723 refcount
= get_refcount((IUnknown
*)palette
);
6724 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6726 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6727 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6728 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6730 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
6731 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6733 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6734 * and is generally somewhat broken with respect to 8 bpp / palette
6736 if (SUCCEEDED(IDirectDrawSurface4_GetPalette(backbuffer
, &tmp
)))
6738 win_skip("Broken palette handling detected, skipping tests.\n");
6739 IDirectDrawPalette_Release(tmp
);
6740 IDirectDrawPalette_Release(palette
);
6741 /* The Windows 8 testbot keeps extra references to the primary and
6742 * backbuffer while in 8 bpp mode. */
6743 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
6744 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
6748 refcount
= get_refcount((IUnknown
*)palette
);
6749 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6751 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6752 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6753 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
6754 "Got unexpected palette caps %#x.\n", palette_caps
);
6756 hr
= IDirectDrawSurface4_SetPalette(primary
, NULL
);
6757 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6758 refcount
= get_refcount((IUnknown
*)palette
);
6759 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6761 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6762 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6763 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6765 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
6766 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6767 refcount
= get_refcount((IUnknown
*)palette
);
6768 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6770 hr
= IDirectDrawSurface4_GetPalette(primary
, &tmp
);
6771 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6772 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
6773 IDirectDrawPalette_Release(tmp
);
6774 hr
= IDirectDrawSurface4_GetPalette(backbuffer
, &tmp
);
6775 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6777 refcount
= IDirectDrawPalette_Release(palette
);
6778 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6779 refcount
= IDirectDrawPalette_Release(palette
);
6780 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6782 /* Note that this only seems to work when the palette is attached to the
6783 * primary surface. When attached to a regular surface, attempting to get
6784 * the palette here will cause an access violation. */
6785 hr
= IDirectDrawSurface4_GetPalette(primary
, &tmp
);
6786 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6789 refcount
= IDirectDrawSurface4_Release(backbuffer
);
6790 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6791 refcount
= IDirectDrawSurface4_Release(primary
);
6792 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6793 refcount
= IDirectDraw4_Release(ddraw
);
6794 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6795 DestroyWindow(window
);
6798 static HRESULT WINAPI
surface_counter(IDirectDrawSurface4
*surface
, DDSURFACEDESC2
*desc
, void *context
)
6800 UINT
*surface_count
= context
;
6803 IDirectDrawSurface_Release(surface
);
6805 return DDENUMRET_OK
;
6808 static void test_surface_attachment(void)
6810 IDirectDrawSurface4
*surface1
, *surface2
, *surface3
, *surface4
;
6811 IDirectDrawSurface
*surface1v1
, *surface2v1
;
6812 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, {0}};
6813 DDSURFACEDESC2 surface_desc
;
6814 IDirectDraw4
*ddraw
;
6820 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6821 0, 0, 640, 480, 0, 0, 0, 0);
6822 ddraw
= create_ddraw();
6823 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6824 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6825 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6827 memset(&surface_desc
, 0, sizeof(surface_desc
));
6828 surface_desc
.dwSize
= sizeof(surface_desc
);
6829 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
6830 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6831 U2(surface_desc
).dwMipMapCount
= 3;
6832 surface_desc
.dwWidth
= 128;
6833 surface_desc
.dwHeight
= 128;
6834 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6835 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6837 hr
= IDirectDrawSurface4_GetAttachedSurface(surface1
, &caps
, &surface2
);
6838 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6839 hr
= IDirectDrawSurface4_GetAttachedSurface(surface2
, &caps
, &surface3
);
6840 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6841 hr
= IDirectDrawSurface4_GetAttachedSurface(surface3
, &caps
, &surface4
);
6842 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6845 IDirectDrawSurface4_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
6846 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6848 IDirectDrawSurface4_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
6849 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6851 IDirectDrawSurface4_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
6852 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
6854 memset(&surface_desc
, 0, sizeof(surface_desc
));
6855 surface_desc
.dwSize
= sizeof(surface_desc
);
6856 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6857 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6858 surface_desc
.dwWidth
= 16;
6859 surface_desc
.dwHeight
= 16;
6860 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6861 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6863 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
);
6864 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6865 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
6866 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6867 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface4
);
6868 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6869 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface3
);
6870 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6871 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface4
);
6872 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6873 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface2
);
6874 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6876 IDirectDrawSurface4_Release(surface4
);
6878 memset(&surface_desc
, 0, sizeof(surface_desc
));
6879 surface_desc
.dwSize
= sizeof(surface_desc
);
6880 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6881 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6882 surface_desc
.dwWidth
= 16;
6883 surface_desc
.dwHeight
= 16;
6884 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6885 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6887 if (SUCCEEDED(hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
)))
6889 skip("Running on refrast, skipping some tests.\n");
6890 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface4
);
6891 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6895 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6896 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
6897 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6898 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface4
);
6899 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6900 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface3
);
6901 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6902 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface4
);
6903 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6904 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface2
);
6905 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6908 IDirectDrawSurface4_Release(surface4
);
6909 IDirectDrawSurface4_Release(surface3
);
6910 IDirectDrawSurface4_Release(surface2
);
6911 IDirectDrawSurface4_Release(surface1
);
6913 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6914 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6916 /* Try a single primary and two offscreen plain surfaces. */
6917 memset(&surface_desc
, 0, sizeof(surface_desc
));
6918 surface_desc
.dwSize
= sizeof(surface_desc
);
6919 surface_desc
.dwFlags
= DDSD_CAPS
;
6920 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6921 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6922 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6924 memset(&surface_desc
, 0, sizeof(surface_desc
));
6925 surface_desc
.dwSize
= sizeof(surface_desc
);
6926 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6927 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6928 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6929 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6930 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
6931 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6933 memset(&surface_desc
, 0, sizeof(surface_desc
));
6934 surface_desc
.dwSize
= sizeof(surface_desc
);
6935 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6936 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6937 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6938 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6939 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6940 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6942 /* This one has a different size. */
6943 memset(&surface_desc
, 0, sizeof(surface_desc
));
6944 surface_desc
.dwSize
= sizeof(surface_desc
);
6945 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6946 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6947 surface_desc
.dwWidth
= 128;
6948 surface_desc
.dwHeight
= 128;
6949 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6950 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6952 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
6953 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6954 /* Try the reverse without detaching first. */
6955 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface1
);
6956 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
6957 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
6958 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6960 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface1
);
6961 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6962 /* Try to detach reversed. */
6963 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
6964 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6965 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface2
, 0, surface1
);
6966 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6968 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface3
);
6969 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6970 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface2
, 0, surface3
);
6971 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6973 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
);
6974 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6975 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
6976 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6978 IDirectDrawSurface4_Release(surface4
);
6979 IDirectDrawSurface4_Release(surface3
);
6980 IDirectDrawSurface4_Release(surface2
);
6981 IDirectDrawSurface4_Release(surface1
);
6983 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
6984 memset(&surface_desc
, 0, sizeof(surface_desc
));
6985 surface_desc
.dwSize
= sizeof(surface_desc
);
6986 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6987 surface_desc
.dwWidth
= 64;
6988 surface_desc
.dwHeight
= 64;
6989 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
6990 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6991 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
6992 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
6993 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
6994 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
6995 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
6996 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6997 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6998 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6999 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7001 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
7002 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
7003 U1(U4(surface_desc
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
7004 U3(U4(surface_desc
).ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
7005 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
7006 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7008 hr
= IDirectDrawSurface4_QueryInterface(surface1
, &IID_IDirectDrawSurface
, (void **)&surface1v1
);
7009 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
7010 hr
= IDirectDrawSurface4_QueryInterface(surface2
, &IID_IDirectDrawSurface
, (void **)&surface2v1
);
7011 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
7013 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7014 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7015 refcount
= get_refcount((IUnknown
*)surface2
);
7016 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
7017 refcount
= get_refcount((IUnknown
*)surface2v1
);
7018 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7019 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7020 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
7021 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7022 todo_wine
ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7023 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
7024 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
7026 /* Attaching while already attached to other surface. */
7027 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface2
);
7028 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7029 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface3
, 0, surface2
);
7030 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7031 IDirectDrawSurface4_Release(surface3
);
7033 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7034 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7035 refcount
= get_refcount((IUnknown
*)surface2
);
7036 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7037 refcount
= get_refcount((IUnknown
*)surface2v1
);
7038 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7040 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
7041 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7042 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7043 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7044 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
7045 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
7046 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7047 refcount
= IDirectDrawSurface4_Release(surface2
);
7048 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7049 refcount
= IDirectDrawSurface4_Release(surface1
);
7050 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7052 /* Automatic detachment on release. */
7053 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7054 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7055 refcount
= get_refcount((IUnknown
*)surface2v1
);
7056 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
7057 refcount
= IDirectDrawSurface_Release(surface1v1
);
7058 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7059 refcount
= IDirectDrawSurface_Release(surface2v1
);
7060 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7061 refcount
= IDirectDraw4_Release(ddraw
);
7062 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7063 DestroyWindow(window
);
7066 static void test_private_data(void)
7068 IDirectDraw4
*ddraw
;
7069 IDirectDrawSurface4
*surface
, *surface2
;
7070 DDSURFACEDESC2 surface_desc
;
7071 ULONG refcount
, refcount2
, refcount3
;
7073 DWORD size
= sizeof(ptr
);
7076 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7077 DWORD data
[] = {1, 2, 3, 4};
7079 static const GUID ddraw_private_data_test_guid
=
7084 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
7086 static const GUID ddraw_private_data_test_guid2
=
7091 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
7094 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7095 0, 0, 640, 480, 0, 0, 0, 0);
7096 ddraw
= create_ddraw();
7097 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7098 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7099 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7101 reset_ddsd(&surface_desc
);
7102 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
7103 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
7104 surface_desc
.dwHeight
= 4;
7105 surface_desc
.dwWidth
= 4;
7106 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7107 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7109 /* NULL pointers are not valid, but don't cause a crash. */
7110 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
,
7111 sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
7112 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7113 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 0, 0);
7114 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7115 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 1, 0);
7116 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7118 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
7119 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7120 0, DDSPD_IUNKNOWNPOINTER
);
7121 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7122 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7123 5, DDSPD_IUNKNOWNPOINTER
);
7124 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7125 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7126 sizeof(ddraw
) * 2, DDSPD_IUNKNOWNPOINTER
);
7127 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7129 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
7130 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
7131 * erases the old content and returns an error. This behavior has
7132 * been fixed in d3d8 and d3d9. Unless an application is found
7133 * that depends on this we don't care about this behavior. */
7134 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7135 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7136 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7137 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7138 0, DDSPD_IUNKNOWNPOINTER
);
7139 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7141 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7142 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7143 hr
= IDirectDrawSurface4_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7144 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7146 refcount
= get_refcount((IUnknown
*)ddraw
);
7147 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7148 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7149 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7150 refcount2
= get_refcount((IUnknown
*)ddraw
);
7151 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7153 hr
= IDirectDrawSurface4_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7154 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7155 refcount2
= get_refcount((IUnknown
*)ddraw
);
7156 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7158 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7159 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7160 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7161 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, surface
,
7162 sizeof(surface
), DDSPD_IUNKNOWNPOINTER
);
7163 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7164 refcount2
= get_refcount((IUnknown
*)ddraw
);
7165 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7167 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7168 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7169 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7170 size
= 2 * sizeof(ptr
);
7171 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7172 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7173 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7174 refcount2
= get_refcount(ptr
);
7175 /* Object is NOT addref'ed by the getter. */
7176 ok(ptr
== (IUnknown
*)ddraw
, "Returned interface pointer is %p, expected %p.\n", ptr
, ddraw
);
7177 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7179 ptr
= (IUnknown
*)0xdeadbeef;
7181 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7182 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7183 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7184 size
= 2 * sizeof(ptr
);
7185 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7186 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7187 ok(size
== 2 * sizeof(ptr
), "Got unexpected size %u.\n", size
);
7189 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7190 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7191 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7192 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7193 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, NULL
, NULL
);
7194 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7196 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, &ptr
, &size
);
7197 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7198 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7199 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
7200 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7201 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7203 refcount3
= IDirectDrawSurface4_Release(surface
);
7204 ok(!refcount3
, "Got unexpected refcount %u.\n", refcount3
);
7206 /* Destroying the surface frees the reference held on the private data. It also frees
7207 * the reference the surface is holding on its creating object. */
7208 refcount2
= get_refcount((IUnknown
*)ddraw
);
7209 ok(refcount2
== refcount
- 1, "Got unexpected refcount %u.\n", refcount2
);
7211 memset(&hal_caps
, 0, sizeof(hal_caps
));
7212 hal_caps
.dwSize
= sizeof(hal_caps
);
7213 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7214 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7215 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) == (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7217 reset_ddsd(&surface_desc
);
7218 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_MIPMAPCOUNT
;
7219 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7220 surface_desc
.dwHeight
= 4;
7221 surface_desc
.dwWidth
= 4;
7222 U2(surface_desc
).dwMipMapCount
= 2;
7223 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7224 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7225 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &surface2
);
7226 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7228 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, data
, sizeof(data
), 0);
7229 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7230 hr
= IDirectDrawSurface4_GetPrivateData(surface2
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7231 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7233 IDirectDrawSurface4_Release(surface2
);
7234 IDirectDrawSurface4_Release(surface
);
7237 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7239 refcount
= IDirectDraw4_Release(ddraw
);
7240 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7241 DestroyWindow(window
);
7244 static void test_pixel_format(void)
7246 HWND window
, window2
= NULL
;
7247 HDC hdc
, hdc2
= NULL
;
7249 int format
, test_format
;
7250 PIXELFORMATDESCRIPTOR pfd
;
7251 IDirectDraw4
*ddraw
= NULL
;
7252 IDirectDrawClipper
*clipper
= NULL
;
7253 DDSURFACEDESC2 ddsd
;
7254 IDirectDrawSurface4
*primary
= NULL
;
7258 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7259 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7262 skip("Failed to create window\n");
7266 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7267 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7269 hdc
= GetDC(window
);
7272 skip("Failed to get DC\n");
7277 hdc2
= GetDC(window2
);
7279 gl
= LoadLibraryA("opengl32.dll");
7280 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7282 format
= GetPixelFormat(hdc
);
7283 ok(format
== 0, "new window has pixel format %d\n", format
);
7285 ZeroMemory(&pfd
, sizeof(pfd
));
7286 pfd
.nSize
= sizeof(pfd
);
7288 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
7289 pfd
.iPixelType
= PFD_TYPE_RGBA
;
7290 pfd
.iLayerType
= PFD_MAIN_PLANE
;
7291 format
= ChoosePixelFormat(hdc
, &pfd
);
7294 skip("no pixel format available\n");
7298 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
7300 skip("failed to set pixel format\n");
7304 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
7306 skip("failed to set pixel format on second window\n");
7309 ReleaseDC(window2
, hdc2
);
7314 ddraw
= create_ddraw();
7315 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7317 test_format
= GetPixelFormat(hdc
);
7318 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7320 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7323 skip("Failed to set cooperative level, hr %#x.\n", hr
);
7327 test_format
= GetPixelFormat(hdc
);
7328 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7332 hr
= IDirectDraw4_CreateClipper(ddraw
, 0, &clipper
, NULL
);
7333 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
7334 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
7335 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
7337 test_format
= GetPixelFormat(hdc
);
7338 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7340 test_format
= GetPixelFormat(hdc2
);
7341 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7344 memset(&ddsd
, 0, sizeof(ddsd
));
7345 ddsd
.dwSize
= sizeof(ddsd
);
7346 ddsd
.dwFlags
= DDSD_CAPS
;
7347 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7349 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
7350 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
7352 test_format
= GetPixelFormat(hdc
);
7353 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7357 test_format
= GetPixelFormat(hdc2
);
7358 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7363 hr
= IDirectDrawSurface4_SetClipper(primary
, clipper
);
7364 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
7366 test_format
= GetPixelFormat(hdc
);
7367 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7369 test_format
= GetPixelFormat(hdc2
);
7370 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7373 memset(&fx
, 0, sizeof(fx
));
7374 fx
.dwSize
= sizeof(fx
);
7375 hr
= IDirectDrawSurface4_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7376 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
7378 test_format
= GetPixelFormat(hdc
);
7379 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7383 test_format
= GetPixelFormat(hdc2
);
7384 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7388 if (primary
) IDirectDrawSurface4_Release(primary
);
7389 if (clipper
) IDirectDrawClipper_Release(clipper
);
7390 if (ddraw
) IDirectDraw4_Release(ddraw
);
7391 if (gl
) FreeLibrary(gl
);
7392 if (hdc
) ReleaseDC(window
, hdc
);
7393 if (hdc2
) ReleaseDC(window2
, hdc2
);
7394 if (window
) DestroyWindow(window
);
7395 if (window2
) DestroyWindow(window2
);
7398 static void test_create_surface_pitch(void)
7400 IDirectDrawSurface4
*surface
;
7401 DDSURFACEDESC2 surface_desc
;
7402 IDirectDraw4
*ddraw
;
7421 {DDSCAPS_VIDEOMEMORY
, 0, 0, DD_OK
,
7422 DDSD_PITCH
, 0x100, 0x100},
7423 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
7424 DDSD_PITCH
, 0x100, 0x100},
7425 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
7426 DDSD_PITCH
, 0x100, 0x100},
7427 {DDSCAPS_VIDEOMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7429 {DDSCAPS_SYSTEMMEMORY
, 0, 0, DD_OK
,
7430 DDSD_PITCH
, 0x100, 0x0fc},
7431 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
7432 DDSD_PITCH
, 0x100, 0x0fc},
7433 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
7434 DDSD_PITCH
, 0x100, 0x0fc},
7435 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
7436 DDSD_PITCH
, 0x100, 0x0fc},
7437 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
7439 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7440 DDSD_PITCH
, 0x100, 0x100},
7441 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fe, DDERR_INVALIDPARAMS
,
7443 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fc, DD_OK
,
7444 DDSD_PITCH
, 0x0fc, 0x0fc},
7445 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0f8, DDERR_INVALIDPARAMS
,
7447 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x100, DDERR_INVALIDPARAMS
,
7449 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x3f00, DDERR_INVALIDPARAMS
,
7451 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, 0x100, DD_OK
,
7452 DDSD_PITCH
, 0x100, 0x100},
7454 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
7456 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7457 0, 0, 640, 480, 0, 0, 0, 0);
7458 ddraw
= create_ddraw();
7459 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7460 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7461 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7463 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
7465 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
7467 memset(&surface_desc
, 0, sizeof(surface_desc
));
7468 surface_desc
.dwSize
= sizeof(surface_desc
);
7469 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
7470 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| test_data
[i
].placement
;
7471 surface_desc
.dwWidth
= 63;
7472 surface_desc
.dwHeight
= 63;
7473 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
7474 surface_desc
.lpSurface
= mem
;
7475 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7476 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7477 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7478 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7479 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7480 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7481 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7482 ok(hr
== test_data
[i
].hr
|| (test_data
[i
].placement
== DDSCAPS_VIDEOMEMORY
&& hr
== DDERR_NODIRECTDRAWHW
),
7483 "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
7487 memset(&surface_desc
, 0, sizeof(surface_desc
));
7488 surface_desc
.dwSize
= sizeof(surface_desc
);
7489 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
7490 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7491 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
7492 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7493 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
7494 if (sizeof(void *) != sizeof(DWORD
) && test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
7495 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
7496 "Test %u: Got unexpected pitch %u, expected %u.\n",
7497 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
7499 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
7500 "Test %u: Got unexpected pitch %u, expected %u.\n",
7501 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
7502 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
7504 IDirectDrawSurface4_Release(surface
);
7507 HeapFree(GetProcessHeap(), 0, mem
);
7508 refcount
= IDirectDraw4_Release(ddraw
);
7509 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7510 DestroyWindow(window
);
7513 static void test_mipmap_lock(void)
7515 IDirectDrawSurface4
*surface
, *surface2
;
7516 DDSURFACEDESC2 surface_desc
;
7517 IDirectDraw4
*ddraw
;
7521 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7524 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7525 0, 0, 640, 480, 0, 0, 0, 0);
7526 ddraw
= create_ddraw();
7527 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7528 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7529 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7531 memset(&hal_caps
, 0, sizeof(hal_caps
));
7532 hal_caps
.dwSize
= sizeof(hal_caps
);
7533 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
7534 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7535 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7537 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
7538 IDirectDraw4_Release(ddraw
);
7539 DestroyWindow(window
);
7543 memset(&surface_desc
, 0, sizeof(surface_desc
));
7544 surface_desc
.dwSize
= sizeof(surface_desc
);
7545 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
7546 surface_desc
.dwWidth
= 4;
7547 surface_desc
.dwHeight
= 4;
7548 U2(surface_desc
).dwMipMapCount
= 2;
7549 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
7550 | DDSCAPS_SYSTEMMEMORY
;
7551 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7552 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7553 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &surface2
);
7554 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7556 memset(&surface_desc
, 0, sizeof(surface_desc
));
7557 surface_desc
.dwSize
= sizeof(surface_desc
);
7558 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7559 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7560 memset(&surface_desc
, 0, sizeof(surface_desc
));
7561 surface_desc
.dwSize
= sizeof(surface_desc
);
7562 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
7563 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7564 IDirectDrawSurface4_Unlock(surface2
, NULL
);
7565 IDirectDrawSurface4_Unlock(surface
, NULL
);
7567 IDirectDrawSurface4_Release(surface2
);
7568 IDirectDrawSurface4_Release(surface
);
7569 refcount
= IDirectDraw4_Release(ddraw
);
7570 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7571 DestroyWindow(window
);
7574 static void test_palette_complex(void)
7576 IDirectDrawSurface4
*surface
, *mipmap
, *tmp
;
7577 DDSURFACEDESC2 surface_desc
;
7578 IDirectDraw4
*ddraw
;
7579 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
7583 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7585 PALETTEENTRY palette_entries
[256];
7591 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7592 0, 0, 640, 480, 0, 0, 0, 0);
7593 ddraw
= create_ddraw();
7594 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7595 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7596 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7598 memset(&hal_caps
, 0, sizeof(hal_caps
));
7599 hal_caps
.dwSize
= sizeof(hal_caps
);
7600 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
7601 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7602 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7604 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7605 IDirectDraw4_Release(ddraw
);
7606 DestroyWindow(window
);
7610 memset(&surface_desc
, 0, sizeof(surface_desc
));
7611 surface_desc
.dwSize
= sizeof(surface_desc
);
7612 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7613 surface_desc
.dwWidth
= 128;
7614 surface_desc
.dwHeight
= 128;
7615 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7616 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7617 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7618 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7619 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7620 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7622 memset(palette_entries
, 0, sizeof(palette_entries
));
7623 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7624 palette_entries
, &palette
, NULL
);
7625 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7627 memset(palette_entries
, 0, sizeof(palette_entries
));
7628 palette_entries
[1].peRed
= 0xff;
7629 palette_entries
[1].peGreen
= 0x80;
7630 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7631 palette_entries
, &palette_mipmap
, NULL
);
7632 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7634 palette2
= (void *)0xdeadbeef;
7635 hr
= IDirectDrawSurface4_GetPalette(surface
, &palette2
);
7636 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
7637 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
7638 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
7639 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7640 hr
= IDirectDrawSurface4_GetPalette(surface
, &palette2
);
7641 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
7642 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
7643 IDirectDrawPalette_Release(palette2
);
7646 IDirectDrawSurface4_AddRef(mipmap
);
7647 for (i
= 0; i
< 7; ++i
)
7649 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7650 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
7651 palette2
= (void *)0xdeadbeef;
7652 hr
= IDirectDrawSurface4_GetPalette(tmp
, &palette2
);
7653 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7654 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
7656 hr
= IDirectDrawSurface4_SetPalette(tmp
, palette_mipmap
);
7657 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
7659 hr
= IDirectDrawSurface4_GetPalette(tmp
, &palette2
);
7660 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
7661 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
7662 IDirectDrawPalette_Release(palette2
);
7664 hr
= IDirectDrawSurface4_GetDC(tmp
, &dc
);
7665 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
7666 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
7667 ok(count
== 1, "Expected count 1, got %u.\n", count
);
7668 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
7669 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
7670 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
7671 hr
= IDirectDrawSurface4_ReleaseDC(tmp
, dc
);
7672 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
7674 IDirectDrawSurface4_Release(mipmap
);
7678 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7679 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7680 IDirectDrawSurface4_Release(mipmap
);
7681 refcount
= IDirectDrawSurface4_Release(surface
);
7682 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7683 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
7684 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7685 refcount
= IDirectDrawPalette_Release(palette
);
7686 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7688 refcount
= IDirectDraw4_Release(ddraw
);
7689 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7690 DestroyWindow(window
);
7693 static void test_p8_rgb_blit(void)
7695 IDirectDrawSurface4
*src
, *dst
;
7696 DDSURFACEDESC2 surface_desc
;
7697 IDirectDraw4
*ddraw
;
7698 IDirectDrawPalette
*palette
;
7702 PALETTEENTRY palette_entries
[256];
7704 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7705 static const D3DCOLOR expected
[] =
7707 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7708 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7712 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7713 0, 0, 640, 480, 0, 0, 0, 0);
7714 ddraw
= create_ddraw();
7715 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7716 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7717 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7719 memset(palette_entries
, 0, sizeof(palette_entries
));
7720 palette_entries
[1].peGreen
= 0xff;
7721 palette_entries
[2].peBlue
= 0xff;
7722 palette_entries
[3].peFlags
= 0xff;
7723 palette_entries
[4].peRed
= 0xff;
7724 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7725 palette_entries
, &palette
, NULL
);
7726 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7728 memset(&surface_desc
, 0, sizeof(surface_desc
));
7729 surface_desc
.dwSize
= sizeof(surface_desc
);
7730 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7731 surface_desc
.dwWidth
= 8;
7732 surface_desc
.dwHeight
= 1;
7733 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7734 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7735 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7736 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7737 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
7738 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7740 memset(&surface_desc
, 0, sizeof(surface_desc
));
7741 surface_desc
.dwSize
= sizeof(surface_desc
);
7742 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7743 surface_desc
.dwWidth
= 8;
7744 surface_desc
.dwHeight
= 1;
7745 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7746 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7747 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
7748 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7749 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7750 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7751 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7752 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
7753 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
7754 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7756 memset(&surface_desc
, 0, sizeof(surface_desc
));
7757 surface_desc
.dwSize
= sizeof(surface_desc
);
7758 hr
= IDirectDrawSurface4_Lock(src
, NULL
, &surface_desc
, 0, NULL
);
7759 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
7760 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
7761 hr
= IDirectDrawSurface4_Unlock(src
, NULL
);
7762 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
7764 hr
= IDirectDrawSurface4_SetPalette(src
, palette
);
7765 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7766 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
7767 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
7768 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
7769 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
7770 "Failed to blit, hr %#x.\n", hr
);
7774 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
7776 color
= get_surface_color(dst
, x
, 0);
7777 todo_wine
ok(compare_color(color
, expected
[x
], 0),
7778 "Pixel %u: Got color %#x, expected %#x.\n",
7779 x
, color
, expected
[x
]);
7783 IDirectDrawSurface4_Release(src
);
7784 IDirectDrawSurface4_Release(dst
);
7785 IDirectDrawPalette_Release(palette
);
7787 refcount
= IDirectDraw4_Release(ddraw
);
7788 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7789 DestroyWindow(window
);
7792 static void test_material(void)
7794 D3DMATERIALHANDLE mat_handle
, tmp
;
7795 IDirect3DMaterial3
*material
;
7796 IDirect3DViewport3
*viewport
;
7797 IDirect3DDevice3
*device
;
7798 IDirectDrawSurface4
*rt
;
7808 struct vec3 position
;
7814 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7815 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7816 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7817 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7821 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7822 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7823 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7824 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7830 D3DCOLOR expected_color
;
7834 {quad1
, TRUE
, 0x0000ff00},
7835 {quad2
, TRUE
, 0x0000ff00},
7836 {quad1
, FALSE
, 0x00ffffff},
7837 {quad2
, FALSE
, 0x00ff0000},
7839 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7841 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7842 0, 0, 640, 480, 0, 0, 0, 0);
7843 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
7845 skip("Failed to create a 3D device, skipping test.\n");
7846 DestroyWindow(window
);
7850 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
7851 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
7853 viewport
= create_viewport(device
, 0, 0, 640, 480);
7854 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
7855 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
7857 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
7858 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
7859 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
7861 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
7862 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
7863 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
7864 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
7865 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
7866 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
7867 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
7868 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
7869 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, 0);
7870 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
7871 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
7872 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
7873 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
7875 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
7877 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
,
7878 D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
7879 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7881 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
7882 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
7884 hr
= IDirect3DDevice3_BeginScene(device
);
7885 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7886 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
7887 D3DFVF_XYZ
| D3DFVF_NORMAL
| D3DFVF_DIFFUSE
, test_data
[i
].data
, 4, 0);
7888 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7889 hr
= IDirect3DDevice3_EndScene(device
);
7890 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7891 color
= get_surface_color(rt
, 320, 240);
7892 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
7893 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
7896 destroy_material(material
);
7897 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
7898 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
7899 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
7901 hr
= IDirect3DViewport3_SetBackground(viewport
, mat_handle
);
7902 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
7903 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
7904 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
7905 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
7906 ok(valid
, "Got unexpected valid %#x.\n", valid
);
7907 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7908 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7909 color
= get_surface_color(rt
, 320, 240);
7910 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
7912 hr
= IDirect3DViewport3_SetBackground(viewport
, 0);
7913 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7914 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
7915 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
7916 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
7917 ok(valid
, "Got unexpected valid %#x.\n", valid
);
7918 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7919 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7920 color
= get_surface_color(rt
, 320, 240);
7921 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
7923 destroy_viewport(device
, viewport
);
7924 viewport
= create_viewport(device
, 0, 0, 640, 480);
7926 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
7927 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
7928 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
7929 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
7930 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7931 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7932 color
= get_surface_color(rt
, 320, 240);
7933 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
7935 destroy_viewport(device
, viewport
);
7936 destroy_material(material
);
7937 IDirectDrawSurface4_Release(rt
);
7938 refcount
= IDirect3DDevice3_Release(device
);
7939 ok(!refcount
, "Device has %u references left.\n", refcount
);
7940 DestroyWindow(window
);
7943 static void test_palette_gdi(void)
7945 IDirectDrawSurface4
*surface
, *primary
;
7946 DDSURFACEDESC2 surface_desc
;
7947 IDirectDraw4
*ddraw
;
7948 IDirectDrawPalette
*palette
, *palette2
;
7952 PALETTEENTRY palette_entries
[256];
7955 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7956 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7957 * not the point of this test. */
7958 static const RGBQUAD expected1
[] =
7960 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7961 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7963 static const RGBQUAD expected2
[] =
7965 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7966 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7968 static const RGBQUAD expected3
[] =
7970 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7971 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7973 HPALETTE ddraw_palette_handle
;
7974 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7975 RGBQUAD rgbquad
[255];
7976 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
7978 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7979 0, 0, 640, 480, 0, 0, 0, 0);
7980 ddraw
= create_ddraw();
7981 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7982 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7983 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7985 memset(&surface_desc
, 0, sizeof(surface_desc
));
7986 surface_desc
.dwSize
= sizeof(surface_desc
);
7987 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7988 surface_desc
.dwWidth
= 16;
7989 surface_desc
.dwHeight
= 16;
7990 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7991 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7992 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7993 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7994 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7995 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7997 /* Avoid colors from the Windows default palette. */
7998 memset(palette_entries
, 0, sizeof(palette_entries
));
7999 palette_entries
[1].peRed
= 0x01;
8000 palette_entries
[2].peGreen
= 0x02;
8001 palette_entries
[3].peBlue
= 0x03;
8002 palette_entries
[4].peRed
= 0x13;
8003 palette_entries
[4].peGreen
= 0x14;
8004 palette_entries
[4].peBlue
= 0x15;
8005 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
8006 palette_entries
, &palette
, NULL
);
8007 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8009 /* If there is no palette assigned and the display mode is not 8 bpp, some
8010 * drivers refuse to create a DC while others allow it. If a DC is created,
8011 * the DIB color table is uninitialized and contains random colors. No error
8012 * is generated when trying to read pixels and random garbage is returned.
8014 * The most likely explanation is that if the driver creates a DC, it (or
8015 * the higher-level runtime) uses GetSystemPaletteEntries to find the
8016 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
8017 * contains uninitialized garbage. See comments below for the P8 case. */
8019 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8020 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8021 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8022 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8023 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
8024 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
8025 "Got unexpected palette %p, expected %p.\n",
8026 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
8028 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8029 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8030 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
8032 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
8033 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8034 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8035 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
8037 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8039 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8040 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8041 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8044 /* Update the palette while the DC is in use. This does not modify the DC. */
8045 palette_entries
[4].peRed
= 0x23;
8046 palette_entries
[4].peGreen
= 0x24;
8047 palette_entries
[4].peBlue
= 0x25;
8048 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
8049 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
8051 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
8052 ok(i
== 1, "Expected count 1, got %u.\n", i
);
8053 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
8054 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8055 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
8056 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
8058 /* Neither does re-setting the palette. */
8059 hr
= IDirectDrawSurface4_SetPalette(surface
, NULL
);
8060 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8061 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8062 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8064 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
8065 ok(i
== 1, "Expected count 1, got %u.\n", i
);
8066 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
8067 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8068 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
8069 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
8071 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8072 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8074 /* Refresh the DC. This updates the palette. */
8075 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8076 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8077 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8078 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8079 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8081 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8082 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8083 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8084 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8086 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8088 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8089 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8090 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8092 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8093 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8095 refcount
= IDirectDrawSurface4_Release(surface
);
8096 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8098 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8100 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8101 IDirectDrawPalette_Release(palette
);
8102 IDirectDraw4_Release(ddraw
);
8103 DestroyWindow(window
);
8106 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
8107 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
8108 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8110 memset(&surface_desc
, 0, sizeof(surface_desc
));
8111 surface_desc
.dwSize
= sizeof(surface_desc
);
8112 surface_desc
.dwFlags
= DDSD_CAPS
;
8113 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8114 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
8115 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8117 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
8118 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8119 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
8120 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8121 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
8122 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
8123 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
8124 "Got unexpected palette %p, expected %p.\n",
8125 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
8126 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
8128 /* The primary uses the system palette. In exclusive mode, the system palette matches
8129 * the ddraw palette attached to the primary, so the result is what you would expect
8130 * from a regular surface. Tests for the interaction between the ddraw palette and
8131 * the system palette are not included pending an application that depends on this.
8132 * The relation between those causes problems on Windows Vista and newer for games
8133 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
8134 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8135 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8136 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8138 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8139 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8140 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8141 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8143 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8145 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8146 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8147 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8149 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
8150 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8152 memset(&surface_desc
, 0, sizeof(surface_desc
));
8153 surface_desc
.dwSize
= sizeof(surface_desc
);
8154 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8155 surface_desc
.dwWidth
= 16;
8156 surface_desc
.dwHeight
= 16;
8157 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8158 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8159 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8161 /* Here the offscreen surface appears to use the primary's palette,
8162 * but in all likelihood it is actually the system palette. */
8163 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8164 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8165 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8166 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8167 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8169 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8170 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8171 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8172 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8174 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8176 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8177 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8178 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8180 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8181 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8183 /* On real hardware a change to the primary surface's palette applies immediately,
8184 * even on device contexts from offscreen surfaces that do not have their own
8185 * palette. On the testbot VMs this is not the case. Don't test this until we
8186 * know of an application that depends on this. */
8188 memset(palette_entries
, 0, sizeof(palette_entries
));
8189 palette_entries
[1].peBlue
= 0x40;
8190 palette_entries
[2].peRed
= 0x40;
8191 palette_entries
[3].peGreen
= 0x40;
8192 palette_entries
[4].peRed
= 0x12;
8193 palette_entries
[4].peGreen
= 0x34;
8194 palette_entries
[4].peBlue
= 0x56;
8195 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
8196 palette_entries
, &palette2
, NULL
);
8197 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8198 hr
= IDirectDrawSurface4_SetPalette(surface
, palette2
);
8199 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8201 /* A palette assigned to the offscreen surface overrides the primary / system
8203 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8204 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8205 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8206 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8207 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
8209 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
8210 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8211 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8212 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
8214 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8216 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8217 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8218 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8220 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8221 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8223 refcount
= IDirectDrawSurface4_Release(surface
);
8224 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8226 /* The Windows 8 testbot keeps extra references to the primary and
8227 * backbuffer while in 8 bpp mode. */
8228 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
8229 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8231 refcount
= IDirectDrawSurface4_Release(primary
);
8232 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8233 refcount
= IDirectDrawPalette_Release(palette2
);
8234 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8235 refcount
= IDirectDrawPalette_Release(palette
);
8236 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8237 refcount
= IDirectDraw4_Release(ddraw
);
8238 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8239 DestroyWindow(window
);
8242 static void test_palette_alpha(void)
8244 IDirectDrawSurface4
*surface
;
8245 DDSURFACEDESC2 surface_desc
;
8246 IDirectDraw4
*ddraw
;
8247 IDirectDrawPalette
*palette
;
8251 PALETTEENTRY palette_entries
[256];
8256 BOOL attach_allowed
;
8261 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
8262 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
8263 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
8266 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8267 0, 0, 640, 480, 0, 0, 0, 0);
8268 ddraw
= create_ddraw();
8269 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8270 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8272 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8273 IDirectDraw4_Release(ddraw
);
8274 DestroyWindow(window
);
8277 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8278 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8280 memset(palette_entries
, 0, sizeof(palette_entries
));
8281 palette_entries
[1].peFlags
= 0x42;
8282 palette_entries
[2].peFlags
= 0xff;
8283 palette_entries
[3].peFlags
= 0x80;
8284 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
8285 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8287 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8288 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8289 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8290 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8291 palette_entries
[0].peFlags
);
8292 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8293 palette_entries
[1].peFlags
);
8294 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8295 palette_entries
[2].peFlags
);
8296 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8297 palette_entries
[3].peFlags
);
8299 IDirectDrawPalette_Release(palette
);
8301 memset(palette_entries
, 0, sizeof(palette_entries
));
8302 palette_entries
[1].peFlags
= 0x42;
8303 palette_entries
[1].peRed
= 0xff;
8304 palette_entries
[2].peFlags
= 0xff;
8305 palette_entries
[3].peFlags
= 0x80;
8306 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
8307 palette_entries
, &palette
, NULL
);
8308 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8310 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8311 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8312 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8313 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8314 palette_entries
[0].peFlags
);
8315 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8316 palette_entries
[1].peFlags
);
8317 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8318 palette_entries
[2].peFlags
);
8319 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8320 palette_entries
[3].peFlags
);
8322 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
8324 memset(&surface_desc
, 0, sizeof(surface_desc
));
8325 surface_desc
.dwSize
= sizeof(surface_desc
);
8326 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
8327 surface_desc
.dwWidth
= 128;
8328 surface_desc
.dwHeight
= 128;
8329 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
8330 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8331 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8333 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8334 if (test_data
[i
].attach_allowed
)
8335 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8337 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8345 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8346 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8347 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
8348 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
8349 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8350 rgbquad
.rgbRed
, test_data
[i
].name
);
8351 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8352 rgbquad
.rgbGreen
, test_data
[i
].name
);
8353 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8354 rgbquad
.rgbBlue
, test_data
[i
].name
);
8355 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8356 rgbquad
.rgbReserved
, test_data
[i
].name
);
8357 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8358 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8360 IDirectDrawSurface4_Release(surface
);
8363 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8364 memset(&surface_desc
, 0, sizeof(surface_desc
));
8365 surface_desc
.dwSize
= sizeof(surface_desc
);
8366 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8367 surface_desc
.dwWidth
= 128;
8368 surface_desc
.dwHeight
= 128;
8369 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8370 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8371 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8372 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
8373 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8374 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8375 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8376 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8377 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8378 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8379 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
8380 IDirectDrawSurface4_Release(surface
);
8382 /* The Windows 8 testbot keeps extra references to the primary
8383 * while in 8 bpp mode. */
8384 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
8385 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8387 refcount
= IDirectDrawPalette_Release(palette
);
8388 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8389 refcount
= IDirectDraw4_Release(ddraw
);
8390 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8391 DestroyWindow(window
);
8394 static void test_vb_writeonly(void)
8396 IDirect3DDevice3
*device
;
8398 IDirect3DVertexBuffer
*buffer
;
8401 D3DVERTEXBUFFERDESC desc
;
8403 static const struct vec4 quad
[] =
8405 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
8406 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
8407 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
8408 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
8411 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8412 0, 0, 640, 480, 0, 0, 0, 0);
8414 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8416 skip("Failed to create a 3D device, skipping test.\n");
8417 DestroyWindow(window
);
8421 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
8422 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
8424 memset(&desc
, 0, sizeof(desc
));
8425 desc
.dwSize
= sizeof(desc
);
8426 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
8427 desc
.dwFVF
= D3DFVF_XYZRHW
;
8428 desc
.dwNumVertices
= sizeof(quad
) / sizeof(*quad
);
8429 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0, NULL
);
8430 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
8432 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, &ptr
, NULL
);
8433 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8434 memcpy(ptr
, quad
, sizeof(quad
));
8435 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8436 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8438 hr
= IDirect3DDevice3_BeginScene(device
);
8439 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8440 hr
= IDirect3DDevice3_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
8441 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8442 hr
= IDirect3DDevice3_EndScene(device
);
8443 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8445 hr
= IDirect3DVertexBuffer_Lock(buffer
, 0, &ptr
, NULL
);
8446 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8447 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8448 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8449 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8451 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_READONLY
, &ptr
, NULL
);
8452 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8453 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8454 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8455 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8457 IDirect3DVertexBuffer_Release(buffer
);
8458 IDirect3D3_Release(d3d
);
8459 IDirect3DDevice3_Release(device
);
8460 DestroyWindow(window
);
8463 static void test_lost_device(void)
8465 IDirectDrawSurface4
*surface
;
8466 DDSURFACEDESC2 surface_desc
;
8467 IDirectDraw4
*ddraw
;
8473 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8474 0, 0, 640, 480, 0, 0, 0, 0);
8475 ddraw
= create_ddraw();
8476 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8477 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8478 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8480 memset(&surface_desc
, 0, sizeof(surface_desc
));
8481 surface_desc
.dwSize
= sizeof(surface_desc
);
8482 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8483 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8484 U5(surface_desc
).dwBackBufferCount
= 1;
8485 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8486 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8488 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8489 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8490 hr
= IDirectDrawSurface4_IsLost(surface
);
8491 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8492 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8493 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8495 ret
= SetForegroundWindow(GetDesktopWindow());
8496 ok(ret
, "Failed to set foreground window.\n");
8497 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8498 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8499 hr
= IDirectDrawSurface4_IsLost(surface
);
8500 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8501 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8502 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8504 ret
= SetForegroundWindow(window
);
8505 ok(ret
, "Failed to set foreground window.\n");
8506 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8507 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8508 hr
= IDirectDrawSurface4_IsLost(surface
);
8509 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8510 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8511 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8513 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
8514 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8515 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8516 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8517 hr
= IDirectDrawSurface4_IsLost(surface
);
8518 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8519 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8520 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8522 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8523 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8524 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8525 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8526 hr
= IDirectDrawSurface4_IsLost(surface
);
8527 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8528 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8529 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8531 /* Trying to restore the primary will crash, probably because flippable
8532 * surfaces can't exist in DDSCL_NORMAL. */
8533 IDirectDrawSurface4_Release(surface
);
8534 memset(&surface_desc
, 0, sizeof(surface_desc
));
8535 surface_desc
.dwSize
= sizeof(surface_desc
);
8536 surface_desc
.dwFlags
= DDSD_CAPS
;
8537 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8538 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8539 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8541 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8542 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8543 hr
= IDirectDrawSurface4_IsLost(surface
);
8544 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8546 ret
= SetForegroundWindow(GetDesktopWindow());
8547 ok(ret
, "Failed to set foreground window.\n");
8548 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8549 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8550 hr
= IDirectDrawSurface4_IsLost(surface
);
8551 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8553 ret
= SetForegroundWindow(window
);
8554 ok(ret
, "Failed to set foreground window.\n");
8555 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8556 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8557 hr
= IDirectDrawSurface4_IsLost(surface
);
8558 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8560 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8561 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8562 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8563 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8564 hr
= IDirectDrawSurface4_IsLost(surface
);
8565 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8567 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
8568 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8569 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8570 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8571 hr
= IDirectDrawSurface4_IsLost(surface
);
8572 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8574 IDirectDrawSurface4_Release(surface
);
8575 refcount
= IDirectDraw4_Release(ddraw
);
8576 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8577 DestroyWindow(window
);
8580 static void test_surface_desc_lock(void)
8582 IDirectDrawSurface4
*surface
;
8583 DDSURFACEDESC2 surface_desc
;
8584 IDirectDraw4
*ddraw
;
8589 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8590 0, 0, 640, 480, 0, 0, 0, 0);
8591 ddraw
= create_ddraw();
8592 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8593 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8594 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8596 memset(&surface_desc
, 0, sizeof(surface_desc
));
8597 surface_desc
.dwSize
= sizeof(surface_desc
);
8598 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8599 surface_desc
.dwWidth
= 16;
8600 surface_desc
.dwHeight
= 16;
8601 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8602 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8603 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8605 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8606 surface_desc
.dwSize
= sizeof(surface_desc
);
8607 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8608 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8609 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8611 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8612 surface_desc
.dwSize
= sizeof(surface_desc
);
8613 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
8614 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8615 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8616 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8617 surface_desc
.dwSize
= sizeof(surface_desc
);
8618 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8619 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8620 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8621 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
8622 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8624 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8625 surface_desc
.dwSize
= sizeof(surface_desc
);
8626 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8627 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8628 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8630 IDirectDrawSurface4_Release(surface
);
8631 refcount
= IDirectDraw4_Release(ddraw
);
8632 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8633 DestroyWindow(window
);
8636 static void test_signed_formats(void)
8639 IDirect3DDevice3
*device
;
8641 IDirectDraw4
*ddraw
;
8642 IDirectDrawSurface4
*surface
, *rt
;
8643 IDirect3DTexture2
*texture
;
8644 IDirect3DViewport3
*viewport
;
8645 DDSURFACEDESC2 surface_desc
;
8648 D3DCOLOR color
, expected_color
;
8652 struct vec3 position
;
8653 struct vec2 texcoord
;
8657 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
8658 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
8659 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
8660 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
8662 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
8663 * of these values. */
8664 static const USHORT content_v8u8
[4][4] =
8666 {0x0000, 0x7f7f, 0x8880, 0x0000},
8667 {0x0080, 0x8000, 0x7f00, 0x007f},
8668 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
8669 {0x4444, 0xc0c0, 0xa066, 0x22e0},
8671 static const DWORD content_x8l8v8u8
[4][4] =
8673 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
8674 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
8675 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
8676 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
8678 static const USHORT content_l6v5u5
[4][4] =
8680 {0x0000, 0xfdef, 0x0230, 0xfc00},
8681 {0x0010, 0x0200, 0x01e0, 0x000f},
8682 {0x4067, 0x53b9, 0x0421, 0xffff},
8683 {0x8108, 0x0318, 0xc28c, 0x909c},
8688 const void *content
;
8691 unsigned int slop
, slop_broken
;
8692 DDPIXELFORMAT format
;
8697 "D3DFMT_V8U8", content_v8u8
, sizeof(WORD
), FALSE
, 1, 0,
8699 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
, 0,
8700 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
8704 "D3DFMT_X8L8V8U8", content_x8l8v8u8
, sizeof(DWORD
), TRUE
, 1, 0,
8706 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
8707 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
8711 "D3DFMT_L6V5U5", content_l6v5u5
, sizeof(WORD
), TRUE
, 4, 7,
8713 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
8714 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
8718 /* No V16U16 or Q8W8V8U8 support in ddraw. */
8720 static const D3DCOLOR expected_colors
[4][4] =
8722 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
8723 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
8724 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
8725 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
8727 unsigned int i
, width
, x
, y
;
8728 D3DDEVICEDESC device_desc
, hel_desc
;
8730 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8731 0, 0, 640, 480, 0, 0, 0, 0);
8733 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8735 skip("Failed to create a 3D device, skipping test.\n");
8736 DestroyWindow(window
);
8740 memset(&device_desc
, 0, sizeof(device_desc
));
8741 device_desc
.dwSize
= sizeof(device_desc
);
8742 memset(&hel_desc
, 0, sizeof(hel_desc
));
8743 hel_desc
.dwSize
= sizeof(hel_desc
);
8744 hr
= IDirect3DDevice3_GetCaps(device
, &device_desc
, &hel_desc
);
8745 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8746 if (!(device_desc
.dwTextureOpCaps
& D3DTEXOPCAPS_BLENDFACTORALPHA
))
8748 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
8752 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
8753 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
8754 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
8755 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
8756 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
8757 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8759 memset(&surface_desc
, 0, sizeof(surface_desc
));
8760 surface_desc
.dwSize
= sizeof(surface_desc
);
8761 hr
= IDirectDrawSurface4_GetSurfaceDesc(rt
, &surface_desc
);
8762 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8763 viewport
= create_viewport(device
, 0, 0, surface_desc
.dwWidth
, surface_desc
.dwHeight
);
8764 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
8765 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
8766 U1(clear_rect
).x1
= 0;
8767 U2(clear_rect
).y1
= 0;
8768 U3(clear_rect
).x2
= surface_desc
.dwWidth
;
8769 U4(clear_rect
).y2
= surface_desc
.dwHeight
;
8771 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8772 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8774 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
8775 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x80ffffff);
8776 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8777 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BLENDFACTORALPHA
);
8778 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
8779 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
8780 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
8781 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
8782 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
8784 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
8786 for (width
= 1; width
< 5; width
+= 3)
8788 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
8789 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8791 memset(&surface_desc
, 0, sizeof(surface_desc
));
8792 surface_desc
.dwSize
= sizeof(surface_desc
);
8793 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
8794 surface_desc
.dwWidth
= width
;
8795 surface_desc
.dwHeight
= 4;
8796 U4(surface_desc
).ddpfPixelFormat
= formats
[i
].format
;
8797 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
8798 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8801 skip("%s textures not supported, skipping.\n", formats
[i
].name
);
8804 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
8806 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8807 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture2 interface, hr %#x, format %s.\n",
8808 hr
, formats
[i
].name
);
8809 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
8810 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
8811 IDirect3DTexture2_Release(texture
);
8813 memset(&surface_desc
, 0, sizeof(surface_desc
));
8814 surface_desc
.dwSize
= sizeof(surface_desc
);
8815 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
8816 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
8817 for (y
= 0; y
< 4; y
++)
8819 memcpy((char *)surface_desc
.lpSurface
+ y
* U1(surface_desc
).lPitch
,
8820 (char *)formats
[i
].content
+ y
* 4 * formats
[i
].pixel_size
,
8821 width
* formats
[i
].pixel_size
);
8823 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
8824 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
8826 hr
= IDirect3DDevice3_BeginScene(device
);
8827 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8828 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
8829 D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
8830 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8831 hr
= IDirect3DDevice3_EndScene(device
);
8832 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8834 for (y
= 0; y
< 4; y
++)
8836 for (x
= 0; x
< width
; x
++)
8838 expected_color
= expected_colors
[y
][x
];
8839 if (!formats
[i
].blue
)
8840 expected_color
|= 0x000000ff;
8842 color
= get_surface_color(rt
, 80 + 160 * x
, 60 + 120 * y
);
8843 ok(compare_color(color
, expected_color
, formats
[i
].slop
)
8844 || broken(compare_color(color
, expected_color
, formats
[i
].slop_broken
)),
8845 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
8846 expected_color
, color
, formats
[i
].name
, x
, y
);
8850 IDirectDrawSurface4_Release(surface
);
8854 destroy_viewport(device
, viewport
);
8855 IDirectDrawSurface4_Release(rt
);
8856 IDirectDraw4_Release(ddraw
);
8857 IDirect3D3_Release(d3d
);
8860 refcount
= IDirect3DDevice3_Release(device
);
8861 ok(!refcount
, "Device has %u references left.\n", refcount
);
8862 DestroyWindow(window
);
8865 static void test_color_fill(void)
8868 IDirect3DDevice3
*device
;
8870 IDirectDraw4
*ddraw
;
8871 IDirectDrawSurface4
*surface
, *surface2
;
8872 DDSURFACEDESC2 surface_desc
;
8873 DDPIXELFORMAT z_fmt
;
8878 RECT rect
= {5, 5, 7, 7};
8880 DWORD supported_fmts
= 0, num_fourcc_codes
, *fourcc_codes
;
8885 HRESULT colorfill_hr
, depthfill_hr
;
8890 DDPIXELFORMAT format
;
8895 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
8896 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8898 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8899 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8903 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
8904 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8906 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8907 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8911 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
8912 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
8914 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8915 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8919 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
8920 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
8922 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8923 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8927 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
8928 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "managed texture RGB", 0xdeadbeef, TRUE
,
8930 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8931 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8935 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
, 0,
8936 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
8937 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
8940 DDSCAPS_ZBUFFER
| DDSCAPS_SYSTEMMEMORY
, 0,
8941 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "sysmem zbuffer", 0, FALSE
,
8942 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
8945 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
8946 * different afterwards. DX9+ GPUs set one of the two luminance values
8947 * in each block, but AMD and Nvidia GPUs disagree on which luminance
8948 * value they set. r200 (dx8) just sets the entire block to the clear
8950 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
8951 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
8953 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8954 {0}, {0}, {0}, {0}, {0}
8958 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
8959 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
8961 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8962 {0}, {0}, {0}, {0}, {0}
8966 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
8967 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
8969 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8970 {0}, {0}, {0}, {0}, {0}
8974 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
8975 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
8977 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8978 {0}, {0}, {0}, {0}, {0}
8982 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
8983 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
8985 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8986 {0}, {0}, {0}, {0}, {0}
8990 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
8991 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
8993 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8994 {0}, {0}, {0}, {0}, {0}
8998 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
8999 * surface works, presumably because it is handled by the runtime instead of
9001 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9002 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
9004 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9005 {8}, {0}, {0}, {0}, {0}
9009 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9010 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
9012 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9013 {8}, {0}, {0}, {0}, {0}
9025 {SRCCOPY
, "SRCCOPY", DD_OK
},
9026 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
9027 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
9028 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
9029 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
9030 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
9031 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
9032 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
9033 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
9034 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
9035 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
9036 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
9037 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
9038 {BLACKNESS
, "BLACKNESS", DD_OK
},
9039 {WHITENESS
, "WHITENESS", DD_OK
},
9040 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
9043 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9044 0, 0, 640, 480, 0, 0, 0, 0);
9046 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9048 skip("Failed to create a 3D device, skipping test.\n");
9049 DestroyWindow(window
);
9053 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9054 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9055 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9056 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9058 memset(&z_fmt
, 0, sizeof(z_fmt
));
9059 IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
9061 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9063 IDirect3DDevice3_EnumTextureFormats(device
, test_block_formats_creation_cb
, &supported_fmts
);
9064 if (!(supported_fmts
& SUPPORT_DXT1
))
9065 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9067 IDirect3D3_Release(d3d
);
9069 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
9070 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9071 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
9072 num_fourcc_codes
* sizeof(*fourcc_codes
));
9075 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
9076 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9077 for (i
= 0; i
< num_fourcc_codes
; i
++)
9079 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9080 supported_fmts
|= SUPPORT_YUY2
;
9081 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9082 supported_fmts
|= SUPPORT_UYVY
;
9084 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
9086 memset(&hal_caps
, 0, sizeof(hal_caps
));
9087 hal_caps
.dwSize
= sizeof(hal_caps
);
9088 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
9089 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9091 if (!(supported_fmts
& (SUPPORT_YUY2
| SUPPORT_UYVY
)) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9092 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9094 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
9096 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9097 memset(&fx
, 0, sizeof(fx
));
9098 fx
.dwSize
= sizeof(fx
);
9099 U5(fx
).dwFillColor
= 0xdeadbeef;
9101 memset(&surface_desc
, 0, sizeof(surface_desc
));
9102 surface_desc
.dwSize
= sizeof(surface_desc
);
9103 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9104 surface_desc
.dwWidth
= 64;
9105 surface_desc
.dwHeight
= 64;
9106 U4(surface_desc
).ddpfPixelFormat
= tests
[i
].format
;
9107 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
9108 surface_desc
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
9110 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('D','X','T','1') && !(supported_fmts
& SUPPORT_DXT1
))
9112 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !(supported_fmts
& SUPPORT_YUY2
))
9114 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !(supported_fmts
& SUPPORT_UYVY
))
9116 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9119 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
9124 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9127 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9128 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9130 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9131 if (tests
[i
].format
.dwFourCC
)
9132 todo_wine
ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9133 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9135 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9136 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9138 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9139 if (tests
[i
].format
.dwFourCC
)
9140 todo_wine
ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9141 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9143 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9144 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9146 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9148 memset(&surface_desc
, 0, sizeof(surface_desc
));
9149 surface_desc
.dwSize
= sizeof(surface_desc
);
9150 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9151 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9152 color
= surface_desc
.lpSurface
;
9153 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9154 *color
, tests
[i
].result
, tests
[i
].name
);
9155 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9156 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9159 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9160 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9161 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9162 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9163 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9164 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9166 U5(fx
).dwFillColor
= 0xdeadbeef;
9167 fx
.dwROP
= BLACKNESS
;
9168 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9169 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9170 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9171 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9172 U5(fx
).dwFillColor
, tests
[i
].name
);
9174 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9176 memset(&surface_desc
, 0, sizeof(surface_desc
));
9177 surface_desc
.dwSize
= sizeof(surface_desc
);
9178 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9179 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9180 color
= surface_desc
.lpSurface
;
9181 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9182 *color
, tests
[i
].name
);
9183 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9184 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9187 fx
.dwROP
= WHITENESS
;
9188 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9189 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9190 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9191 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9192 U5(fx
).dwFillColor
, tests
[i
].name
);
9194 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9196 memset(&surface_desc
, 0, sizeof(surface_desc
));
9197 surface_desc
.dwSize
= sizeof(surface_desc
);
9198 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9199 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9200 color
= surface_desc
.lpSurface
;
9201 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9202 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9203 *color
, tests
[i
].name
);
9204 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9205 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9208 IDirectDrawSurface4_Release(surface
);
9211 memset(&fx
, 0, sizeof(fx
));
9212 fx
.dwSize
= sizeof(fx
);
9213 U5(fx
).dwFillColor
= 0xdeadbeef;
9214 fx
.dwROP
= WHITENESS
;
9216 memset(&surface_desc
, 0, sizeof(surface_desc
));
9217 surface_desc
.dwSize
= sizeof(surface_desc
);
9218 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9219 surface_desc
.dwWidth
= 64;
9220 surface_desc
.dwHeight
= 64;
9221 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9222 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9223 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9224 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9225 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9226 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9227 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
9228 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9229 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9230 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9231 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9234 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
9235 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9236 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
9237 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9239 /* Unused source rectangle. */
9240 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9241 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9242 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9243 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9245 /* Unused source surface. */
9246 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9247 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9248 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9249 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9250 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9251 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9252 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9253 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9255 /* Inverted destination or source rectangle. */
9256 SetRect(&rect
, 5, 7, 7, 5);
9257 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9258 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9259 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9260 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9261 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9262 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9263 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9264 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9265 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9266 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9268 /* Negative rectangle. */
9269 SetRect(&rect
, -1, -1, 5, 5);
9270 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9271 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9272 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9273 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9274 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9275 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9276 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9277 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9278 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9279 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9281 /* Out of bounds rectangle. */
9282 SetRect(&rect
, 0, 0, 65, 65);
9283 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9284 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9285 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9286 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9288 /* Combine multiple flags. */
9289 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9290 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9291 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9292 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9293 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9294 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9296 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
9298 fx
.dwROP
= rops
[i
].rop
;
9299 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9300 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
9303 IDirectDrawSurface4_Release(surface2
);
9304 IDirectDrawSurface4_Release(surface
);
9309 memset(&surface_desc
, 0, sizeof(surface_desc
));
9310 surface_desc
.dwSize
= sizeof(surface_desc
);
9311 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9312 surface_desc
.dwWidth
= 64;
9313 surface_desc
.dwHeight
= 64;
9314 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9315 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
9316 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9317 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9318 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9319 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9322 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
9323 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9325 /* Unused source rectangle. */
9326 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9327 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9329 /* Unused source surface. */
9330 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9331 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9332 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9333 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9335 /* Inverted destination or source rectangle. */
9336 SetRect(&rect
, 5, 7, 7, 5);
9337 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9338 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9339 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9340 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9341 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9342 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9343 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9344 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9346 /* Negative rectangle. */
9347 SetRect(&rect
, -1, -1, 5, 5);
9348 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9349 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9350 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9351 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9352 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9353 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9354 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9355 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9357 /* Out of bounds rectangle. */
9358 SetRect(&rect
, 0, 0, 65, 65);
9359 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9360 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9362 /* Combine multiple flags. */
9363 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9364 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9366 IDirectDrawSurface4_Release(surface2
);
9367 IDirectDrawSurface4_Release(surface
);
9370 IDirectDraw4_Release(ddraw
);
9371 refcount
= IDirect3DDevice3_Release(device
);
9372 ok(!refcount
, "Device has %u references left.\n", refcount
);
9373 DestroyWindow(window
);
9376 static void test_texcoordindex(void)
9381 struct vec2 texcoord1
;
9382 struct vec2 texcoord2
;
9383 struct vec2 texcoord3
;
9387 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}, {0.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9388 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}, {0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
9389 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9390 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 0.0f
}},
9392 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_TEX3
;
9393 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9394 IDirect3DDevice3
*device
;
9396 IDirectDraw4
*ddraw
;
9397 IDirectDrawSurface4
*rt
;
9398 IDirect3DViewport3
*viewport
;
9401 IDirectDrawSurface4
*surface1
, *surface2
;
9402 IDirect3DTexture2
*texture1
, *texture2
;
9403 DDSURFACEDESC2 surface_desc
;
9408 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9409 0, 0, 640, 480, 0, 0, 0, 0);
9410 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9412 skip("Failed to create a 3D device, skipping test.\n");
9413 DestroyWindow(window
);
9417 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9418 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
9419 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9420 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
9421 IDirect3D3_Release(d3d
);
9423 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
9424 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9426 memset(&surface_desc
, 0, sizeof(surface_desc
));
9427 surface_desc
.dwSize
= sizeof(surface_desc
);
9428 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9429 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9430 surface_desc
.dwWidth
= 2;
9431 surface_desc
.dwHeight
= 2;
9432 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9433 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
9434 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9435 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9436 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9437 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9438 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
9439 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
9440 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9441 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9442 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9444 memset(&surface_desc
, 0, sizeof(surface_desc
));
9445 surface_desc
.dwSize
= sizeof(surface_desc
);
9446 hr
= IDirectDrawSurface4_Lock(surface1
, 0, &surface_desc
, 0, NULL
);
9447 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9448 ptr
= surface_desc
.lpSurface
;
9449 ptr
[0] = 0xff000000;
9450 ptr
[1] = 0xff00ff00;
9451 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9452 ptr
[0] = 0xff0000ff;
9453 ptr
[1] = 0xff00ffff;
9454 hr
= IDirectDrawSurface4_Unlock(surface1
, NULL
);
9455 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9457 memset(&surface_desc
, 0, sizeof(surface_desc
));
9458 surface_desc
.dwSize
= sizeof(surface_desc
);
9459 hr
= IDirectDrawSurface4_Lock(surface2
, 0, &surface_desc
, 0, NULL
);
9460 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9461 ptr
= surface_desc
.lpSurface
;
9462 ptr
[0] = 0xff000000;
9463 ptr
[1] = 0xff0000ff;
9464 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9465 ptr
[0] = 0xffff0000;
9466 ptr
[1] = 0xffff00ff;
9467 hr
= IDirectDrawSurface4_Unlock(surface2
, 0);
9468 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9470 viewport
= create_viewport(device
, 0, 0, 640, 480);
9471 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
9472 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
9474 hr
= IDirectDrawSurface4_QueryInterface(surface1
, &IID_IDirect3DTexture2
, (void **)&texture1
);
9475 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9476 hr
= IDirectDrawSurface4_QueryInterface(surface2
, &IID_IDirect3DTexture2
, (void **)&texture2
);
9477 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9478 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture1
);
9479 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9480 hr
= IDirect3DDevice3_SetTexture(device
, 1, texture2
);
9481 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9482 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9483 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9484 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
9485 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9486 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9487 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9488 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_ADD
);
9489 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9490 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9491 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9492 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
9493 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9494 hr
= IDirect3DDevice3_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
9495 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9497 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_TEXCOORDINDEX
, 1);
9498 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9499 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 0);
9500 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9502 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
9503 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9505 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9506 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9508 hr
= IDirect3DDevice3_BeginScene(device
);
9509 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9510 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9511 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9512 hr
= IDirect3DDevice3_EndScene(device
);
9513 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9515 color
= get_surface_color(rt
, 160, 120);
9516 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9517 color
= get_surface_color(rt
, 480, 120);
9518 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9519 color
= get_surface_color(rt
, 160, 360);
9520 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
9521 color
= get_surface_color(rt
, 480, 360);
9522 ok(compare_color(color
, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color
);
9524 /* D3DTSS_TEXTURETRANSFORMFLAGS was introduced in D3D7, can't test it here. */
9526 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 2);
9527 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9529 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9530 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9532 hr
= IDirect3DDevice3_BeginScene(device
);
9533 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9534 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9535 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9536 hr
= IDirect3DDevice3_EndScene(device
);
9537 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9539 color
= get_surface_color(rt
, 160, 120);
9540 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9541 color
= get_surface_color(rt
, 480, 120);
9542 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9543 color
= get_surface_color(rt
, 160, 360);
9544 ok(compare_color(color
, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color
);
9545 color
= get_surface_color(rt
, 480, 360);
9546 ok(compare_color(color
, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color
);
9548 IDirectDrawSurface7_Release(texture1
);
9549 IDirectDrawSurface7_Release(texture2
);
9551 IDirectDrawSurface7_Release(rt
);
9552 IDirectDraw_Release(ddraw
);
9553 refcount
= IDirect3DDevice3_Release(device
);
9554 ok(!refcount
, "Device has %u references left.\n", refcount
);
9555 DestroyWindow(window
);
9558 static void test_colorkey_precision(void)
9563 struct vec2 texcoord
;
9567 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9568 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
9569 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9570 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
9572 IDirect3DDevice3
*device
;
9574 IDirectDraw4
*ddraw
;
9575 IDirectDrawSurface4
*rt
;
9576 IDirect3DViewport3
*viewport
;
9579 IDirectDrawSurface4
*src
, *dst
, *texture
;
9580 IDirect3DTexture2
*d3d_texture
;
9581 DDSURFACEDESC2 surface_desc
, lock_desc
;
9587 DWORD data
[4] = {0}, color_mask
;
9588 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9589 D3DDEVICEDESC device_desc
, hel_desc
;
9593 unsigned int max
, shift
, bpp
, clear
;
9600 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8",
9602 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9603 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
9608 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel",
9610 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9611 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9616 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel",
9618 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9619 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9624 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4",
9626 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9627 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
9633 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9634 0, 0, 640, 480, 0, 0, 0, 0);
9635 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9637 skip("Failed to create a 3D device, skipping test.\n");
9638 DestroyWindow(window
);
9642 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
9643 * (color key doesn't match although the values are equal), and a false
9644 * positive when the color key is 0 and the texture contains the value 1.
9645 * I don't want to mark this broken unconditionally since this would
9646 * essentially disable the test on Windows. Try to detect WARP (and I
9647 * guess mismatch other SW renderers) by its ability to texture from
9648 * system memory. Also on random occasions 254 == 255 and 255 != 255.*/
9649 memset(&device_desc
, 0, sizeof(device_desc
));
9650 device_desc
.dwSize
= sizeof(device_desc
);
9651 memset(&hel_desc
, 0, sizeof(hel_desc
));
9652 hel_desc
.dwSize
= sizeof(hel_desc
);
9653 hr
= IDirect3DDevice3_GetCaps(device
, &device_desc
, &hel_desc
);
9654 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9655 warp
= !!(device_desc
.dwDevCaps
& D3DDEVCAPS_TEXTURESYSTEMMEMORY
);
9657 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9658 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
9659 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9660 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
9661 IDirect3D3_Release(d3d
);
9662 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
9663 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9665 viewport
= create_viewport(device
, 0, 0, 640, 480);
9666 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
9667 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
9669 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9670 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
9671 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9672 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9673 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
9674 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
9675 /* Multiply the texture read result with 0, that way the result color if the key doesn't
9676 * match is constant. In theory color keying works without reading the texture result
9677 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
9679 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
9680 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9681 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9682 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9683 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
9684 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9685 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x00000000);
9686 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9688 memset(&fx
, 0, sizeof(fx
));
9689 fx
.dwSize
= sizeof(fx
);
9690 memset(&lock_desc
, 0, sizeof(lock_desc
));
9691 lock_desc
.dwSize
= sizeof(lock_desc
);
9693 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
9695 memset(&surface_desc
, 0, sizeof(surface_desc
));
9696 surface_desc
.dwSize
= sizeof(surface_desc
);
9697 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9698 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9699 surface_desc
.dwWidth
= 4;
9700 surface_desc
.dwHeight
= 1;
9701 U4(surface_desc
).ddpfPixelFormat
= tests
[t
].fmt
;
9702 /* Windows XP (at least with the r200 driver, other drivers untested) produces
9703 * garbage when doing color keyed texture->texture blits. */
9704 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
9705 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9706 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
9707 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9709 fx
.dwFillColor
= tests
[t
].clear
;
9710 /* On the w8 testbot (WARP driver) the blit result has different values in the
9712 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
9713 | U3(tests
[t
].fmt
).dwGBitMask
9714 | U4(tests
[t
].fmt
).dwBBitMask
;
9716 for (c
= 0; c
<= tests
[t
].max
; ++c
)
9718 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
9719 * texture after it has been set once... */
9720 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
9721 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9722 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9723 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9724 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
9725 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9726 hr
= IDirectDrawSurface4_QueryInterface(texture
, &IID_IDirect3DTexture2
, (void **)&d3d_texture
);
9727 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9728 hr
= IDirect3DDevice3_SetTexture(device
, 0, d3d_texture
);
9729 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9731 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9732 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
9734 hr
= IDirectDrawSurface4_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9735 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9736 switch (tests
[t
].bpp
)
9739 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9740 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9741 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9742 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
9746 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9747 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9748 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9749 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
9752 hr
= IDirectDrawSurface4_Unlock(src
, 0);
9753 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9754 hr
= IDirectDrawSurface4_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
9755 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9757 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9758 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9759 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
9760 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9762 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
9763 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9765 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
9766 hr
= IDirectDrawSurface4_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9767 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9768 switch (tests
[t
].bpp
)
9771 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9772 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9773 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9774 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
9778 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9779 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9780 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9781 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
9784 hr
= IDirectDrawSurface4_Unlock(dst
, 0);
9785 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9789 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9790 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
9792 if (data
[3] == tests
[t
].clear
)
9794 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
9795 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
9796 * even when a different surface is used. The blit itself doesn't draw anything,
9797 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
9798 * never be masked out by the key.
9800 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
9801 * terrible on WARP. */
9802 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
9803 IDirect3DTexture2_Release(d3d_texture
);
9804 IDirectDrawSurface4_Release(texture
);
9805 IDirectDrawSurface4_Release(src
);
9806 IDirectDrawSurface4_Release(dst
);
9811 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9812 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
9814 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9815 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
9817 if (c
== tests
[t
].max
)
9818 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9819 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
9821 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9822 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
9824 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x0000ff00, 1.0f
, 0);
9825 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9827 hr
= IDirect3DDevice3_BeginScene(device
);
9828 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9829 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
9830 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9831 hr
= IDirect3DDevice3_EndScene(device
);
9832 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9834 color
= get_surface_color(rt
, 80, 240);
9836 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
9837 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9838 color
, tests
[t
].name
, c
);
9840 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
9841 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9842 color
, tests
[t
].name
, c
);
9844 color
= get_surface_color(rt
, 240, 240);
9845 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
9846 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9847 color
, tests
[t
].name
, c
);
9849 color
= get_surface_color(rt
, 400, 240);
9850 if (c
== tests
[t
].max
)
9851 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
9852 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9853 color
, tests
[t
].name
, c
);
9855 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
9856 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9857 color
, tests
[t
].name
, c
);
9859 IDirect3DTexture2_Release(d3d_texture
);
9860 IDirectDrawSurface4_Release(texture
);
9862 IDirectDrawSurface4_Release(src
);
9863 IDirectDrawSurface4_Release(dst
);
9867 destroy_viewport(device
, viewport
);
9868 IDirectDrawSurface4_Release(rt
);
9869 IDirectDraw4_Release(ddraw
);
9870 refcount
= IDirect3DDevice3_Release(device
);
9871 ok(!refcount
, "Device has %u references left.\n", refcount
);
9872 DestroyWindow(window
);
9875 static void test_range_colorkey(void)
9877 IDirectDraw4
*ddraw
;
9880 IDirectDrawSurface4
*surface
;
9881 DDSURFACEDESC2 surface_desc
;
9885 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9886 0, 0, 640, 480, 0, 0, 0, 0);
9887 ddraw
= create_ddraw();
9888 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9889 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9890 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9892 memset(&surface_desc
, 0, sizeof(surface_desc
));
9893 surface_desc
.dwSize
= sizeof(surface_desc
);
9894 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
9895 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9896 surface_desc
.dwWidth
= 1;
9897 surface_desc
.dwHeight
= 1;
9898 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9899 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9900 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9901 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9902 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9903 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
9905 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
9906 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9907 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
9908 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9909 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9911 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
9912 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9913 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9914 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9916 /* Same for DDSCAPS_OFFSCREENPLAIN. */
9917 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9918 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9919 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
9920 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9921 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9923 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
9924 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9925 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9926 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9928 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9929 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9930 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9931 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9933 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
9934 ckey
.dwColorSpaceLowValue
= 0x00000000;
9935 ckey
.dwColorSpaceHighValue
= 0x00000001;
9936 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9937 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9939 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9940 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9941 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9942 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9944 ckey
.dwColorSpaceLowValue
= 0x00000001;
9945 ckey
.dwColorSpaceHighValue
= 0x00000000;
9946 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9947 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9949 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9950 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9951 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9952 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9954 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
9955 ckey
.dwColorSpaceLowValue
= 0x00000000;
9956 ckey
.dwColorSpaceHighValue
= 0x00000000;
9957 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9958 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9960 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
9961 ckey
.dwColorSpaceLowValue
= 0x00000001;
9962 ckey
.dwColorSpaceHighValue
= 0x00000000;
9963 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9964 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9965 ckey
.dwColorSpaceLowValue
= 0x00000000;
9966 ckey
.dwColorSpaceHighValue
= 0x00000001;
9967 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9968 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9969 /* Range destination keys don't work either. */
9970 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
9971 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9973 /* Just to show it's not because of A, R, and G having equal values. */
9974 ckey
.dwColorSpaceLowValue
= 0x00000000;
9975 ckey
.dwColorSpaceHighValue
= 0x01010101;
9976 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9977 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9979 /* None of these operations modified the key. */
9980 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9981 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9982 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9983 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9985 IDirectDrawSurface4_Release(surface
),
9986 refcount
= IDirectDraw4_Release(ddraw
);
9987 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
9988 DestroyWindow(window
);
9993 IDirectDraw4
*ddraw
;
9994 DEVMODEW current_mode
;
9996 if (!(ddraw
= create_ddraw()))
9998 skip("Failed to create a ddraw object, skipping tests.\n");
10001 IDirectDraw4_Release(ddraw
);
10003 memset(¤t_mode
, 0, sizeof(current_mode
));
10004 current_mode
.dmSize
= sizeof(current_mode
);
10005 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
10006 registry_mode
.dmSize
= sizeof(registry_mode
);
10007 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
10008 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
10009 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
10011 skip("Current mode does not match registry mode, skipping test.\n");
10015 test_process_vertices();
10016 test_coop_level_create_device_window();
10017 test_clipper_blt();
10018 test_coop_level_d3d_state();
10019 test_surface_interface_mismatch();
10020 test_coop_level_threaded();
10022 test_texture_load_ckey();
10031 test_window_style();
10032 test_redundant_mode_set();
10033 test_coop_level_mode_set();
10034 test_coop_level_mode_set_multi();
10036 test_coop_level_surf_create();
10038 test_coop_level_multi_window();
10039 test_draw_strided();
10041 test_specular_lighting();
10042 test_clear_rect_count();
10043 test_coop_level_versions();
10044 test_lighting_interface_versions();
10045 test_coop_level_activateapp();
10046 test_texturemanage();
10047 test_block_formats_creation();
10048 test_unsupported_formats();
10050 test_primary_caps();
10051 test_surface_lock();
10052 test_surface_discard();
10054 test_set_surface_desc();
10055 test_user_memory_getdc();
10056 test_sysmem_overlay();
10057 test_primary_palette();
10058 test_surface_attachment();
10059 test_private_data();
10060 test_pixel_format();
10061 test_create_surface_pitch();
10062 test_mipmap_lock();
10063 test_palette_complex();
10064 test_p8_rgb_blit();
10066 test_palette_gdi();
10067 test_palette_alpha();
10068 test_vb_writeonly();
10069 test_lost_device();
10070 test_surface_desc_lock();
10071 test_signed_formats();
10073 test_texcoordindex();
10074 test_colorkey_precision();
10075 test_range_colorkey();