2 * Copyright 2005 Antoine Chavasse (a.chavasse@gmail.com)
3 * Copyright 2008, 2011, 2012-2014 Stefan Dösinger for CodeWeavers
4 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
27 static BOOL is_ddraw64
= sizeof(DWORD
) != sizeof(DWORD
*);
28 static DEVMODEW registry_mode
;
45 struct create_window_thread_param
48 HANDLE window_created
;
49 HANDLE destroy_window
;
53 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
63 if (abs(x
- y
) > ulps
)
69 static BOOL
compare_vec4(struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
71 return compare_float(vec
->x
, x
, ulps
)
72 && compare_float(vec
->y
, y
, ulps
)
73 && compare_float(vec
->z
, z
, ulps
)
74 && compare_float(vec
->w
, w
, ulps
);
77 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
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
;
85 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
89 static IDirectDrawSurface4
*create_overlay(IDirectDraw4
*ddraw
,
90 unsigned int width
, unsigned int height
, DWORD format
)
92 IDirectDrawSurface4
*surface
;
95 memset(&desc
, 0, sizeof(desc
));
96 desc
.dwSize
= sizeof(desc
);
97 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
99 desc
.dwHeight
= height
;
100 desc
.ddsCaps
.dwCaps
= DDSCAPS_OVERLAY
;
101 U4(desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(desc
).ddpfPixelFormat
);
102 U4(desc
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
103 U4(desc
).ddpfPixelFormat
.dwFourCC
= format
;
105 if (FAILED(IDirectDraw4_CreateSurface(ddraw
, &desc
, &surface
, NULL
)))
110 static DWORD WINAPI
create_window_thread_proc(void *param
)
112 struct create_window_thread_param
*p
= param
;
116 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
117 0, 0, 640, 480, 0, 0, 0, 0);
118 ret
= SetEvent(p
->window_created
);
119 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
125 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
126 DispatchMessageA(&msg
);
127 res
= WaitForSingleObject(p
->destroy_window
, 100);
128 if (res
== WAIT_OBJECT_0
)
130 if (res
!= WAIT_TIMEOUT
)
132 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
137 DestroyWindow(p
->window
);
142 static void create_window_thread(struct create_window_thread_param
*p
)
146 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
147 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
148 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
149 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
150 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
151 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
152 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
153 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
156 static void destroy_window_thread(struct create_window_thread_param
*p
)
158 SetEvent(p
->destroy_window
);
159 WaitForSingleObject(p
->thread
, INFINITE
);
160 CloseHandle(p
->destroy_window
);
161 CloseHandle(p
->window_created
);
162 CloseHandle(p
->thread
);
165 static IDirectDrawSurface4
*get_depth_stencil(IDirect3DDevice3
*device
)
167 IDirectDrawSurface4
*rt
, *ret
;
168 DDSCAPS2 caps
= {DDSCAPS_ZBUFFER
, 0, 0, {0}};
171 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
172 ok(SUCCEEDED(hr
), "Failed to get the render target, hr %#x.\n", hr
);
173 hr
= IDirectDrawSurface4_GetAttachedSurface(rt
, &caps
, &ret
);
174 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
175 IDirectDrawSurface4_Release(rt
);
179 static HRESULT
set_display_mode(IDirectDraw4
*ddraw
, DWORD width
, DWORD height
)
181 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
183 return IDirectDraw4_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
186 static D3DCOLOR
get_surface_color(IDirectDrawSurface4
*surface
, UINT x
, UINT y
)
188 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
189 DDSURFACEDESC2 surface_desc
;
193 memset(&surface_desc
, 0, sizeof(surface_desc
));
194 surface_desc
.dwSize
= sizeof(surface_desc
);
196 hr
= IDirectDrawSurface4_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
197 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
201 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
203 hr
= IDirectDrawSurface4_Unlock(surface
, &rect
);
204 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
209 static HRESULT CALLBACK
enum_z_fmt(DDPIXELFORMAT
*format
, void *ctx
)
211 DDPIXELFORMAT
*z_fmt
= ctx
;
213 if (U1(*format
).dwZBufferBitDepth
> U1(*z_fmt
).dwZBufferBitDepth
)
219 static IDirectDraw4
*create_ddraw(void)
221 IDirectDraw4
*ddraw4
;
225 if (FAILED(DirectDrawCreate(NULL
, &ddraw1
, NULL
)))
228 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw4
, (void **)&ddraw4
);
229 IDirectDraw_Release(ddraw1
);
236 static IDirect3DDevice3
*create_device(HWND window
, DWORD coop_level
)
238 IDirectDrawSurface4
*surface
, *ds
;
239 IDirect3DDevice3
*device
= NULL
;
240 DDSURFACEDESC2 surface_desc
;
241 IDirectDraw4
*ddraw4
;
246 if (!(ddraw4
= create_ddraw()))
249 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, coop_level
);
250 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
252 memset(&surface_desc
, 0, sizeof(surface_desc
));
253 surface_desc
.dwSize
= sizeof(surface_desc
);
254 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
255 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
256 surface_desc
.dwWidth
= 640;
257 surface_desc
.dwHeight
= 480;
259 hr
= IDirectDraw4_CreateSurface(ddraw4
, &surface_desc
, &surface
, NULL
);
260 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
262 if (coop_level
& DDSCL_NORMAL
)
264 IDirectDrawClipper
*clipper
;
266 hr
= IDirectDraw4_CreateClipper(ddraw4
, 0, &clipper
, NULL
);
267 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
268 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
269 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
270 hr
= IDirectDrawSurface4_SetClipper(surface
, clipper
);
271 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
272 IDirectDrawClipper_Release(clipper
);
275 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirect3D3
, (void **)&d3d3
);
276 IDirectDraw4_Release(ddraw4
);
279 IDirectDrawSurface4_Release(surface
);
283 memset(&z_fmt
, 0, sizeof(z_fmt
));
284 hr
= IDirect3D3_EnumZBufferFormats(d3d3
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
285 if (FAILED(hr
) || !z_fmt
.dwSize
)
287 IDirect3D3_Release(d3d3
);
288 IDirectDrawSurface4_Release(surface
);
292 memset(&surface_desc
, 0, sizeof(surface_desc
));
293 surface_desc
.dwSize
= sizeof(surface_desc
);
294 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
295 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
296 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
297 surface_desc
.dwWidth
= 640;
298 surface_desc
.dwHeight
= 480;
299 hr
= IDirectDraw4_CreateSurface(ddraw4
, &surface_desc
, &ds
, NULL
);
300 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
303 IDirect3D3_Release(d3d3
);
304 IDirectDrawSurface4_Release(surface
);
308 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
309 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
310 IDirectDrawSurface4_Release(ds
);
313 IDirect3D3_Release(d3d3
);
314 IDirectDrawSurface4_Release(surface
);
318 hr
= IDirect3D3_CreateDevice(d3d3
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
319 IDirect3D3_Release(d3d3
);
320 IDirectDrawSurface4_Release(surface
);
327 static IDirect3DViewport3
*create_viewport(IDirect3DDevice3
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
329 IDirect3DViewport3
*viewport
;
334 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
335 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
336 hr
= IDirect3D3_CreateViewport(d3d
, &viewport
, NULL
);
337 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
338 hr
= IDirect3DDevice3_AddViewport(device
, viewport
);
339 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
340 memset(&vp
, 0, sizeof(vp
));
341 vp
.dwSize
= sizeof(vp
);
348 vp
.dvClipWidth
= 2.0f
;
349 vp
.dvClipHeight
= 2.0f
;
352 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp
);
353 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
354 IDirect3D3_Release(d3d
);
359 static void destroy_viewport(IDirect3DDevice3
*device
, IDirect3DViewport3
*viewport
)
363 hr
= IDirect3DDevice3_DeleteViewport(device
, viewport
);
364 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
365 IDirect3DViewport3_Release(viewport
);
368 static IDirect3DMaterial3
*create_material(IDirect3DDevice3
*device
, D3DMATERIAL
*mat
)
370 IDirect3DMaterial3
*material
;
374 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
375 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
376 hr
= IDirect3D3_CreateMaterial(d3d
, &material
, NULL
);
377 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
378 hr
= IDirect3DMaterial3_SetMaterial(material
, mat
);
379 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
380 IDirect3D3_Release(d3d
);
385 static IDirect3DMaterial3
*create_diffuse_material(IDirect3DDevice3
*device
, float r
, float g
, float b
, float a
)
389 memset(&mat
, 0, sizeof(mat
));
390 mat
.dwSize
= sizeof(mat
);
391 U1(U(mat
).diffuse
).r
= r
;
392 U2(U(mat
).diffuse
).g
= g
;
393 U3(U(mat
).diffuse
).b
= b
;
394 U4(U(mat
).diffuse
).a
= a
;
396 return create_material(device
, &mat
);
399 static IDirect3DMaterial3
*create_specular_material(IDirect3DDevice3
*device
,
400 float r
, float g
, float b
, float a
, float power
)
404 memset(&mat
, 0, sizeof(mat
));
405 mat
.dwSize
= sizeof(mat
);
406 U1(U2(mat
).specular
).r
= r
;
407 U2(U2(mat
).specular
).g
= g
;
408 U3(U2(mat
).specular
).b
= b
;
409 U4(U2(mat
).specular
).a
= a
;
410 U4(mat
).power
= power
;
412 return create_material(device
, &mat
);
415 static IDirect3DMaterial3
*create_emissive_material(IDirect3DDevice3
*device
, float r
, float g
, float b
, float a
)
419 memset(&mat
, 0, sizeof(mat
));
420 mat
.dwSize
= sizeof(mat
);
421 U1(U3(mat
).emissive
).r
= r
;
422 U2(U3(mat
).emissive
).g
= g
;
423 U3(U3(mat
).emissive
).b
= b
;
424 U4(U3(mat
).emissive
).a
= a
;
426 return create_material(device
, &mat
);
429 static void destroy_material(IDirect3DMaterial3
*material
)
431 IDirect3DMaterial3_Release(material
);
438 WPARAM expect_wparam
;
441 static const struct message
*expect_messages
;
443 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
445 if (expect_messages
&& message
== expect_messages
->message
)
447 if (expect_messages
->check_wparam
)
448 ok (wparam
== expect_messages
->expect_wparam
,
449 "Got unexpected wparam %lx for message %x, expected %lx.\n",
450 wparam
, message
, expect_messages
->expect_wparam
);
455 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
458 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
459 * interface. This prevents subsequent SetCooperativeLevel() calls on a
460 * different window from failing with DDERR_HWNDALREADYSET. */
461 static void fix_wndproc(HWND window
, LONG_PTR proc
)
466 if (!(ddraw
= create_ddraw()))
469 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
470 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
471 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
472 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
473 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
475 IDirectDraw4_Release(ddraw
);
478 static void test_process_vertices(void)
480 IDirect3DVertexBuffer
*src_vb
, *dst_vb
;
481 IDirect3DViewport3
*viewport
;
482 D3DVERTEXBUFFERDESC vb_desc
;
483 IDirect3DDevice3
*device
;
484 struct vec3
*src_data
;
485 struct vec4
*dst_data
;
492 static D3DMATRIX identity
=
494 1.0f
, 0.0f
, 0.0f
, 0.0f
,
495 0.0f
, 1.0f
, 0.0f
, 0.0f
,
496 0.0f
, 0.0f
, 1.0f
, 0.0f
,
497 0.0f
, 0.0f
, 0.0f
, 1.0f
,
499 static D3DMATRIX projection
=
501 1.0f
, 0.0f
, 0.0f
, 0.0f
,
502 0.0f
, 1.0f
, 0.0f
, 0.0f
,
503 0.0f
, 0.0f
, 1.0f
, 0.0f
,
504 6.0f
, 7.0f
, 8.0f
, 1.0f
,
507 window
= CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW
,
508 0, 0, 640, 480, 0, 0, 0, 0);
509 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
511 skip("Failed to create a 3D device, skipping test.\n");
512 DestroyWindow(window
);
516 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d3
);
517 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
519 memset(&vb_desc
, 0, sizeof(vb_desc
));
520 vb_desc
.dwSize
= sizeof(vb_desc
);
521 vb_desc
.dwFVF
= D3DFVF_XYZ
;
522 vb_desc
.dwNumVertices
= 3;
523 hr
= IDirect3D3_CreateVertexBuffer(d3d3
, &vb_desc
, &src_vb
, 0, NULL
);
524 ok(SUCCEEDED(hr
), "Failed to create source vertex buffer, hr %#x.\n", hr
);
526 hr
= IDirect3DVertexBuffer_Lock(src_vb
, DDLOCK_WRITEONLY
, (void **)&src_data
, NULL
);
527 ok(SUCCEEDED(hr
), "Failed to lock source vertex buffer, hr %#x.\n", hr
);
528 src_data
[0].x
= -1.0f
;
529 src_data
[0].y
= -1.0f
;
530 src_data
[0].z
= -1.0f
;
531 src_data
[1].x
= 0.0f
;
532 src_data
[1].y
= 0.0f
;
533 src_data
[1].z
= 0.0f
;
534 src_data
[2].x
= 1.0f
;
535 src_data
[2].y
= 1.0f
;
536 src_data
[2].z
= 1.0f
;
537 hr
= IDirect3DVertexBuffer_Unlock(src_vb
);
538 ok(SUCCEEDED(hr
), "Failed to unlock source vertex buffer, hr %#x.\n", hr
);
540 memset(&vb_desc
, 0, sizeof(vb_desc
));
541 vb_desc
.dwSize
= sizeof(vb_desc
);
542 vb_desc
.dwFVF
= D3DFVF_XYZRHW
;
543 vb_desc
.dwNumVertices
= 3;
544 hr
= IDirect3D3_CreateVertexBuffer(d3d3
, &vb_desc
, &dst_vb
, 0, NULL
);
545 ok(SUCCEEDED(hr
), "Failed to create destination vertex buffer, hr %#x.\n", hr
);
547 hr
= IDirect3D3_CreateViewport(d3d3
, &viewport
, NULL
);
548 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
549 hr
= IDirect3DDevice3_AddViewport(device
, viewport
);
550 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
551 vp2
.dwSize
= sizeof(vp2
);
558 vp2
.dvClipWidth
= 4.0f
;
559 vp2
.dvClipHeight
= 5.0f
;
562 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp2
);
563 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
564 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
565 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
567 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &identity
);
568 ok(SUCCEEDED(hr
), "Failed to set world transformation, hr %#x.\n", hr
);
569 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &identity
);
570 ok(SUCCEEDED(hr
), "Failed to set view transformation, hr %#x.\n", hr
);
571 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &identity
);
572 ok(SUCCEEDED(hr
), "Failed to set projection transformation, hr %#x.\n", hr
);
574 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
575 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
577 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
578 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
579 ok(compare_vec4(&dst_data
[0], -6.500e+1f
, +1.800e+2f
, +2.000e-1f
, +1.000e+0f
, 4096),
580 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
581 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
582 ok(compare_vec4(&dst_data
[1], -4.000e+1f
, +1.400e+2f
, +4.000e-1f
, +1.000e+0f
, 4096),
583 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
584 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
585 ok(compare_vec4(&dst_data
[2], -1.500e+1f
, +1.000e+2f
, +6.000e-1f
, +1.000e+0f
, 4096),
586 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
587 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
588 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
589 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
591 hr
= IDirect3DDevice3_MultiplyTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &projection
);
592 ok(SUCCEEDED(hr
), "Failed to set projection transformation, hr %#x.\n", hr
);
594 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
595 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
597 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
598 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
599 ok(compare_vec4(&dst_data
[0], +8.500e+1f
, -1.000e+2f
, +1.800e+0f
, +1.000e+0f
, 4096),
600 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
601 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
602 ok(compare_vec4(&dst_data
[1], +1.100e+2f
, -1.400e+2f
, +2.000e+0f
, +1.000e+0f
, 4096),
603 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
604 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
605 ok(compare_vec4(&dst_data
[2], +1.350e+2f
, -1.800e+2f
, +2.200e+0f
, +1.000e+0f
, 4096),
606 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
607 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
608 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
609 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
611 vp2
.dwSize
= sizeof(vp2
);
618 vp2
.dvClipWidth
= 2.0f
;
619 vp2
.dvClipHeight
= 4.0f
;
622 hr
= IDirect3DViewport3_SetViewport2(viewport
, &vp2
);
623 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
625 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
626 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
628 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
629 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
630 ok(compare_vec4(&dst_data
[0], +7.500e+1f
, +4.000e+1f
, -8.000e-1f
, +1.000e+0f
, 4096),
631 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
632 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
633 ok(compare_vec4(&dst_data
[1], +1.200e+2f
, +2.000e+1f
, -1.000e+0f
, +1.000e+0f
, 4096),
634 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
635 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
636 ok(compare_vec4(&dst_data
[2], +1.650e+2f
, +0.000e+0f
, -1.200e+0f
, +1.000e+0f
, 4096),
637 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
638 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
639 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
640 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
642 vp1
.dwSize
= sizeof(vp1
);
653 hr
= IDirect3DViewport3_SetViewport(viewport
, &vp1
);
654 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
656 hr
= IDirect3DVertexBuffer_ProcessVertices(dst_vb
, D3DVOP_TRANSFORM
, 0, 3, src_vb
, 0, device
, 0);
657 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
659 hr
= IDirect3DVertexBuffer_Lock(dst_vb
, DDLOCK_READONLY
, (void **)&dst_data
, NULL
);
660 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
661 ok(compare_vec4(&dst_data
[0], +1.100e+2f
, +6.800e+1f
, +7.000e+0f
, +1.000e+0f
, 4096),
662 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
663 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
664 ok(compare_vec4(&dst_data
[1], +1.170e+2f
, +6.600e+1f
, +8.000e+0f
, +1.000e+0f
, 4096),
665 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
666 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
667 ok(compare_vec4(&dst_data
[2], +1.240e+2f
, +6.400e+1f
, +9.000e+0f
, +1.000e+0f
, 4096),
668 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
669 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
670 hr
= IDirect3DVertexBuffer_Unlock(dst_vb
);
671 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
673 hr
= IDirect3DDevice3_DeleteViewport(device
, viewport
);
674 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
676 IDirect3DVertexBuffer_Release(dst_vb
);
677 IDirect3DVertexBuffer_Release(src_vb
);
678 IDirect3DViewport3_Release(viewport
);
679 IDirect3D3_Release(d3d3
);
680 IDirect3DDevice3_Release(device
);
681 DestroyWindow(window
);
684 static void test_coop_level_create_device_window(void)
686 HWND focus_window
, device_window
;
690 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
691 0, 0, 640, 480, 0, 0, 0, 0);
692 ddraw
= create_ddraw();
693 ok(!!ddraw
, "Failed to create a ddraw object.\n");
695 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
696 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
697 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
698 ok(!device_window
, "Unexpected device window found.\n");
699 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
700 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
701 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
702 ok(!device_window
, "Unexpected device window found.\n");
703 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
704 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
705 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
706 ok(!device_window
, "Unexpected device window found.\n");
707 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
708 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
709 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
710 ok(!device_window
, "Unexpected device window found.\n");
711 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
712 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
713 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
714 ok(!device_window
, "Unexpected device window found.\n");
716 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
717 if (broken(hr
== DDERR_INVALIDPARAMS
))
719 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
720 IDirectDraw4_Release(ddraw
);
721 DestroyWindow(focus_window
);
725 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
726 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
727 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
728 ok(!device_window
, "Unexpected device window found.\n");
729 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
730 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
731 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
732 ok(!device_window
, "Unexpected device window found.\n");
734 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
735 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
736 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
737 ok(!device_window
, "Unexpected device window found.\n");
738 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
739 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
740 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
741 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
742 ok(!!device_window
, "Device window not found.\n");
744 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
745 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
746 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
747 ok(!device_window
, "Unexpected device window found.\n");
748 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
749 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
750 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
751 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
752 ok(!!device_window
, "Device window not found.\n");
754 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
755 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
756 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
757 ok(!device_window
, "Unexpected device window found.\n");
758 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
759 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
760 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
761 ok(!device_window
, "Unexpected device window found.\n");
762 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
763 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
764 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
765 ok(!device_window
, "Unexpected device window found.\n");
766 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
767 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
768 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
769 ok(!!device_window
, "Device window not found.\n");
771 IDirectDraw4_Release(ddraw
);
772 DestroyWindow(focus_window
);
775 static void test_clipper_blt(void)
777 IDirectDrawSurface4
*src_surface
, *dst_surface
;
778 RECT client_rect
, src_rect
;
779 IDirectDrawClipper
*clipper
;
780 DDSURFACEDESC2 surface_desc
;
781 unsigned int i
, j
, x
, y
;
793 static const DWORD src_data
[] =
795 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
796 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
797 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
799 static const D3DCOLOR expected1
[] =
801 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
802 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
803 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
804 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
806 /* Nvidia on Windows seems to have an off-by-one error
807 * when processing source rectangles. Our left = 1 and
808 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
809 * read as well, but only for the edge pixels on the
810 * output image. The bug happens on the y axis as well,
811 * but we only read one row there, and all source rows
812 * contain the same data. This bug is not dependent on
813 * the presence of a clipper. */
814 static const D3DCOLOR expected1_broken
[] =
816 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
817 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
818 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
819 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
821 static const D3DCOLOR expected2
[] =
823 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
824 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
825 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
826 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
829 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
830 10, 10, 640, 480, 0, 0, 0, 0);
831 ShowWindow(window
, SW_SHOW
);
832 ddraw
= create_ddraw();
833 ok(!!ddraw
, "Failed to create a ddraw object.\n");
835 ret
= GetClientRect(window
, &client_rect
);
836 ok(ret
, "Failed to get client rect.\n");
837 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
838 ok(ret
, "Failed to map client rect.\n");
840 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
841 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
843 hr
= IDirectDraw4_CreateClipper(ddraw
, 0, &clipper
, NULL
);
844 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
845 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
846 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
847 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
848 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
849 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
850 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
851 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
852 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
853 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
854 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
855 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
856 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
857 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
858 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
859 rgn_data
->rdh
.rcBound
.left
, rgn_data
->rdh
.rcBound
.top
,
860 rgn_data
->rdh
.rcBound
.right
, rgn_data
->rdh
.rcBound
.bottom
,
861 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
862 HeapFree(GetProcessHeap(), 0, rgn_data
);
864 r1
= CreateRectRgn(0, 0, 320, 240);
865 ok(!!r1
, "Failed to create region.\n");
866 r2
= CreateRectRgn(320, 240, 640, 480);
867 ok(!!r2
, "Failed to create region.\n");
868 CombineRgn(r1
, r1
, r2
, RGN_OR
);
869 ret
= GetRegionData(r1
, 0, NULL
);
870 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
871 ret
= GetRegionData(r1
, ret
, rgn_data
);
872 ok(!!ret
, "Failed to get region data.\n");
877 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
878 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
879 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
880 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
881 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
882 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
884 HeapFree(GetProcessHeap(), 0, rgn_data
);
886 memset(&surface_desc
, 0, sizeof(surface_desc
));
887 surface_desc
.dwSize
= sizeof(surface_desc
);
888 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
889 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
890 surface_desc
.dwWidth
= 640;
891 surface_desc
.dwHeight
= 480;
892 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
893 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
894 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
895 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
896 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
897 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
899 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
900 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
901 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
902 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
904 memset(&fx
, 0, sizeof(fx
));
905 fx
.dwSize
= sizeof(fx
);
906 hr
= IDirectDrawSurface4_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
907 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
908 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
909 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
911 hr
= IDirectDrawSurface4_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
912 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
913 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
914 ptr
= surface_desc
.lpSurface
;
915 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
916 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
917 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
918 hr
= IDirectDrawSurface4_Unlock(src_surface
, NULL
);
919 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
921 hr
= IDirectDrawSurface4_SetClipper(dst_surface
, clipper
);
922 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
924 SetRect(&src_rect
, 1, 1, 5, 2);
925 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
926 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
927 for (i
= 0; i
< 4; ++i
)
929 for (j
= 0; j
< 4; ++j
)
931 x
= 80 * ((2 * j
) + 1);
932 y
= 60 * ((2 * i
) + 1);
933 color
= get_surface_color(dst_surface
, x
, y
);
934 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
935 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
936 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
940 U5(fx
).dwFillColor
= 0xff0000ff;
941 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
942 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
943 for (i
= 0; i
< 4; ++i
)
945 for (j
= 0; j
< 4; ++j
)
947 x
= 80 * ((2 * j
) + 1);
948 y
= 60 * ((2 * i
) + 1);
949 color
= get_surface_color(dst_surface
, x
, y
);
950 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
951 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
955 hr
= IDirectDrawSurface4_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
956 ok(hr
== DDERR_BLTFASTCANTCLIP
, "Got unexpected hr %#x.\n", hr
);
958 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
959 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
960 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
961 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
962 DestroyWindow(window
);
963 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
964 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
965 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
966 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
967 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
968 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
969 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
970 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
971 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
972 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
973 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
974 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
976 IDirectDrawSurface4_Release(dst_surface
);
977 IDirectDrawSurface4_Release(src_surface
);
978 refcount
= IDirectDrawClipper_Release(clipper
);
979 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
980 IDirectDraw4_Release(ddraw
);
983 static void test_coop_level_d3d_state(void)
985 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
986 IDirectDrawSurface4
*rt
, *surface
;
987 IDirect3DViewport3
*viewport
;
988 IDirect3DDevice3
*device
;
996 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
997 0, 0, 640, 480, 0, 0, 0, 0);
998 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1000 skip("Failed to create a 3D device, skipping test.\n");
1001 DestroyWindow(window
);
1005 viewport
= create_viewport(device
, 0, 0, 640, 480);
1007 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1008 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1009 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
1010 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1011 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
1012 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
1013 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1014 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
1015 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
1016 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
1017 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
1018 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1019 color
= get_surface_color(rt
, 320, 240);
1020 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
1022 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1023 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1024 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1025 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1026 IDirect3D3_Release(d3d
);
1027 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1028 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1029 hr
= IDirectDrawSurface4_IsLost(rt
);
1030 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
1031 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
1032 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
1033 IDirectDraw4_Release(ddraw
);
1035 hr
= IDirect3DDevice3_GetRenderTarget(device
, &surface
);
1036 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1037 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
1038 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
1039 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1040 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
1041 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
1042 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1043 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
1044 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
1045 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1046 color
= get_surface_color(rt
, 320, 240);
1047 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1049 destroy_viewport(device
, viewport
);
1050 IDirectDrawSurface4_Release(surface
);
1051 IDirectDrawSurface4_Release(rt
);
1052 IDirect3DDevice3_Release(device
);
1053 DestroyWindow(window
);
1056 static void test_surface_interface_mismatch(void)
1058 IDirectDraw4
*ddraw
= NULL
;
1059 IDirect3D3
*d3d
= NULL
;
1060 IDirectDrawSurface4
*surface
= NULL
, *ds
;
1061 IDirectDrawSurface3
*surface3
= NULL
;
1062 IDirect3DDevice3
*device
= NULL
;
1063 IDirect3DViewport3
*viewport
= NULL
;
1064 DDSURFACEDESC2 surface_desc
;
1065 DDPIXELFORMAT z_fmt
;
1070 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1072 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1073 0, 0, 640, 480, 0, 0, 0, 0);
1074 ddraw
= create_ddraw();
1075 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1076 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
1077 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1079 memset(&surface_desc
, 0, sizeof(surface_desc
));
1080 surface_desc
.dwSize
= sizeof(surface_desc
);
1081 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1082 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
1083 surface_desc
.dwWidth
= 640;
1084 surface_desc
.dwHeight
= 480;
1086 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1087 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1089 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
1090 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr
);
1092 if (FAILED(IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
)))
1094 skip("D3D interface is not available, skipping test.\n");
1098 memset(&z_fmt
, 0, sizeof(z_fmt
));
1099 hr
= IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
1100 if (FAILED(hr
) || !z_fmt
.dwSize
)
1102 skip("No depth buffer formats available, skipping test.\n");
1106 memset(&surface_desc
, 0, sizeof(surface_desc
));
1107 surface_desc
.dwSize
= sizeof(surface_desc
);
1108 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
1109 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1110 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
1111 surface_desc
.dwWidth
= 640;
1112 surface_desc
.dwHeight
= 480;
1113 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
1114 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
1118 /* Using a different surface interface version still works */
1119 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
1120 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
1121 refcount
= IDirectDrawSurface4_Release(ds
);
1122 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1127 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface4
*)surface3
, &device
, NULL
);
1128 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
1132 viewport
= create_viewport(device
, 0, 0, 640, 480);
1134 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
1135 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1136 color
= get_surface_color(surface
, 320, 240);
1137 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
1141 destroy_viewport(device
, viewport
);
1142 if (surface3
) IDirectDrawSurface3_Release(surface3
);
1143 if (surface
) IDirectDrawSurface4_Release(surface
);
1144 if (device
) IDirect3DDevice3_Release(device
);
1145 if (d3d
) IDirect3D3_Release(d3d
);
1146 if (ddraw
) IDirectDraw4_Release(ddraw
);
1147 DestroyWindow(window
);
1150 static void test_coop_level_threaded(void)
1152 struct create_window_thread_param p
;
1153 IDirectDraw4
*ddraw
;
1156 ddraw
= create_ddraw();
1157 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1158 create_window_thread(&p
);
1160 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1161 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1163 IDirectDraw4_Release(ddraw
);
1164 destroy_window_thread(&p
);
1167 static void test_depth_blit(void)
1176 { -1.0, 1.0, 0.50f
, 0xff00ff00},
1177 { 1.0, 1.0, 0.50f
, 0xff00ff00},
1178 { -1.0, -1.0, 0.50f
, 0xff00ff00},
1179 { 1.0, -1.0, 0.50f
, 0xff00ff00},
1181 static const D3DCOLOR expected_colors
[4][4] =
1183 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1184 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1185 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1186 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1188 DDSURFACEDESC2 ddsd_new
, ddsd_existing
;
1190 IDirect3DDevice3
*device
;
1191 IDirectDrawSurface4
*ds1
, *ds2
, *ds3
, *rt
;
1192 IDirect3DViewport3
*viewport
;
1193 RECT src_rect
, dst_rect
;
1198 IDirectDraw4
*ddraw
;
1203 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1204 0, 0, 640, 480, 0, 0, 0, 0);
1205 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1207 skip("Failed to create a 3D device, skipping test.\n");
1208 DestroyWindow(window
);
1212 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1213 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
1214 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1215 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
1216 IDirect3D3_Release(d3d
);
1218 ds1
= get_depth_stencil(device
);
1220 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1221 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1222 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1223 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1224 hr
= IDirectDrawSurface4_GetSurfaceDesc(ds1
, &ddsd_existing
);
1225 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
1226 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1227 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1228 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1229 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1230 U4(ddsd_new
).ddpfPixelFormat
= U4(ddsd_existing
).ddpfPixelFormat
;
1231 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1232 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1233 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1234 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1235 IDirectDraw4_Release(ddraw
);
1237 viewport
= create_viewport(device
, 0, 0, ddsd_existing
.dwWidth
, ddsd_existing
.dwHeight
);
1238 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1239 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
1241 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1242 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1243 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1244 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1246 U1(d3drect
).x1
= U2(d3drect
).y1
= 0;
1247 U3(d3drect
).x2
= ddsd_existing
.dwWidth
; U4(d3drect
).y2
= ddsd_existing
.dwHeight
;
1248 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
1249 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1252 SetRect(&src_rect
, 0, 0, 320, 240);
1253 SetRect(&dst_rect
, 0, 0, 320, 240);
1254 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1255 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1256 /* Different locations. */
1257 SetRect(&src_rect
, 0, 0, 320, 240);
1258 SetRect(&dst_rect
, 320, 240, 640, 480);
1259 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1260 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1262 SetRect(&src_rect
, 0, 0, 320, 240);
1263 SetRect(&dst_rect
, 0, 0, 640, 480);
1264 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1265 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1267 SetRect(&src_rect
, 0, 480, 640, 0);
1268 SetRect(&dst_rect
, 0, 0, 640, 480);
1269 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1270 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1271 SetRect(&src_rect
, 0, 0, 640, 480);
1272 SetRect(&dst_rect
, 0, 480, 640, 0);
1273 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1274 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1275 /* Full, explicit. */
1276 SetRect(&src_rect
, 0, 0, 640, 480);
1277 SetRect(&dst_rect
, 0, 0, 640, 480);
1278 hr
= IDirectDrawSurface4_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1279 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1280 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1282 /* Depth blit inside a BeginScene / EndScene pair */
1283 hr
= IDirect3DDevice3_BeginScene(device
);
1284 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1285 /* From the current depth stencil */
1286 hr
= IDirectDrawSurface4_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1287 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1288 /* To the current depth stencil */
1289 hr
= IDirectDrawSurface4_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1290 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1291 /* Between unbound surfaces */
1292 hr
= IDirectDrawSurface4_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1293 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1294 hr
= IDirect3DDevice3_EndScene(device
);
1295 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1297 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1298 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1299 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1300 * a reliable result(z = 0.0) */
1301 memset(&fx
, 0, sizeof(fx
));
1302 fx
.dwSize
= sizeof(fx
);
1303 hr
= IDirectDrawSurface4_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1304 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1306 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
, 0xffff0000, 1.0f
, 0);
1307 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1308 SetRect(&dst_rect
, 0, 0, 320, 240);
1309 hr
= IDirectDrawSurface4_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1310 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1311 IDirectDrawSurface4_Release(ds3
);
1312 IDirectDrawSurface4_Release(ds2
);
1313 IDirectDrawSurface4_Release(ds1
);
1315 hr
= IDirect3DDevice3_BeginScene(device
);
1316 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1317 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
1319 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1320 hr
= IDirect3DDevice3_EndScene(device
);
1321 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1323 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1324 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1325 for (i
= 0; i
< 4; ++i
)
1327 for (j
= 0; j
< 4; ++j
)
1329 unsigned int x
= 80 * ((2 * j
) + 1);
1330 unsigned int y
= 60 * ((2 * i
) + 1);
1331 color
= get_surface_color(rt
, x
, y
);
1332 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1333 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1336 IDirectDrawSurface4_Release(rt
);
1338 destroy_viewport(device
, viewport
);
1339 IDirect3DDevice3_Release(device
);
1340 DestroyWindow(window
);
1343 static void test_texture_load_ckey(void)
1345 IDirectDraw4
*ddraw
;
1346 IDirectDrawSurface4
*src
;
1347 IDirectDrawSurface4
*dst
;
1348 IDirect3DTexture2
*src_tex
;
1349 IDirect3DTexture2
*dst_tex
;
1350 DDSURFACEDESC2 ddsd
;
1354 ddraw
= create_ddraw();
1355 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1356 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
1357 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1359 memset(&ddsd
, 0, sizeof(ddsd
));
1360 ddsd
.dwSize
= sizeof(ddsd
);
1361 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1362 ddsd
.dwHeight
= 128;
1364 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1365 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1366 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1367 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1368 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1369 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1371 hr
= IDirectDrawSurface4_QueryInterface(src
, &IID_IDirect3DTexture2
, (void **)&src_tex
);
1372 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr
);
1375 /* 64 bit ddraw does not support d3d */
1376 skip("Could not get Direct3DTexture2 interface, skipping texture::Load color keying tests.\n");
1377 IDirectDrawSurface4_Release(dst
);
1378 IDirectDrawSurface4_Release(src
);
1379 IDirectDraw4_Release(ddraw
);
1382 hr
= IDirectDrawSurface4_QueryInterface(dst
, &IID_IDirect3DTexture2
, (void **)&dst_tex
);
1383 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr
);
1385 /* No surface has a color key */
1386 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1387 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1388 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1389 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1390 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1391 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1392 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1394 /* Source surface has a color key */
1395 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1396 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1397 ok(SUCCEEDED(hr
), "Failed to set color key, 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 /* Both surfaces have a color key: Dest ckey is overwritten */
1406 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1407 hr
= IDirectDrawSurface4_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1408 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1409 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1410 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1411 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1412 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1413 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1414 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1416 /* Only the destination has a color key: It is not deleted */
1417 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1418 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1419 hr
= IDirectDrawSurface4_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1420 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1421 hr
= IDirect3DTexture2_Load(dst_tex
, src_tex
);
1422 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1423 hr
= IDirectDrawSurface4_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1424 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1425 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1426 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1428 IDirect3DTexture2_Release(dst_tex
);
1429 IDirect3DTexture2_Release(src_tex
);
1430 IDirectDrawSurface4_Release(dst
);
1431 IDirectDrawSurface4_Release(src
);
1432 IDirectDraw4_Release(ddraw
);
1435 static ULONG
get_refcount(IUnknown
*test_iface
)
1437 IUnknown_AddRef(test_iface
);
1438 return IUnknown_Release(test_iface
);
1441 static void test_viewport(void)
1443 IDirectDraw4
*ddraw
;
1445 HRESULT hr
, old_d3d_ref
;
1447 IDirect3DViewport
*viewport
;
1448 IDirect3DViewport2
*viewport2
;
1449 IDirect3DViewport3
*viewport3
, *another_vp
, *test_vp
;
1450 IDirectDrawGammaControl
*gamma
;
1453 IDirect3DDevice3
*device
;
1455 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1456 0, 0, 640, 480, 0, 0, 0, 0);
1457 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1459 skip("Failed to create a 3D device, skipping test.\n");
1460 DestroyWindow(window
);
1463 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1464 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
1465 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1466 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
1467 old_d3d_ref
= get_refcount((IUnknown
*) d3d
);
1469 hr
= IDirect3D3_CreateViewport(d3d
, &viewport3
, NULL
);
1470 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1471 ref
= get_refcount((IUnknown
*)viewport3
);
1472 ok(ref
== 1, "Initial IDirect3DViewport3 refcount is %u\n", ref
);
1473 ref
= get_refcount((IUnknown
*)d3d
);
1474 ok(ref
== old_d3d_ref
, "IDirect3D3 refcount is %u\n", ref
);
1476 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1477 hr
= IDirect3DViewport2_QueryInterface(viewport3
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1478 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
1479 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1480 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1481 /* NULL iid: Segfaults */
1483 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IDirect3DViewport
, (void **)&viewport
);
1484 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport, hr %#x.\n", hr
);
1487 ref
= get_refcount((IUnknown
*)viewport
);
1488 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1489 ref
= get_refcount((IUnknown
*)viewport3
);
1490 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1491 IDirect3DViewport_Release(viewport
);
1495 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IDirect3DViewport3
, (void **)&viewport2
);
1496 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1499 ref
= get_refcount((IUnknown
*)viewport2
);
1500 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1501 ref
= get_refcount((IUnknown
*)viewport3
);
1502 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1503 IDirect3DViewport3_Release(viewport2
);
1506 hr
= IDirect3DViewport3_QueryInterface(viewport3
, &IID_IUnknown
, (void **)&unknown
);
1507 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1510 ref
= get_refcount((IUnknown
*)viewport3
);
1511 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1512 ref
= get_refcount(unknown
);
1513 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1514 IUnknown_Release(unknown
);
1517 /* AddViewport(NULL): Segfault */
1518 hr
= IDirect3DDevice3_DeleteViewport(device
, NULL
);
1519 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1520 hr
= IDirect3DDevice3_GetCurrentViewport(device
, NULL
);
1521 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1523 hr
= IDirect3D3_CreateViewport(d3d
, &another_vp
, NULL
);
1524 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1526 /* Setting a viewport not in the viewport list fails */
1527 hr
= IDirect3DDevice3_SetCurrentViewport(device
, another_vp
);
1528 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1530 hr
= IDirect3DDevice3_AddViewport(device
, viewport3
);
1531 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1532 ref
= get_refcount((IUnknown
*) viewport3
);
1533 ok(ref
== 2, "viewport3 refcount is %d\n", ref
);
1534 hr
= IDirect3DDevice3_AddViewport(device
, another_vp
);
1535 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1536 ref
= get_refcount((IUnknown
*) another_vp
);
1537 ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1539 test_vp
= (IDirect3DViewport3
*) 0xbaadc0de;
1540 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1541 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1542 ok(test_vp
== (IDirect3DViewport3
*) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp
);
1544 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport3
);
1545 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1546 ref
= get_refcount((IUnknown
*) viewport3
);
1547 ok(ref
== 3, "viewport3 refcount is %d\n", ref
);
1548 ref
= get_refcount((IUnknown
*) device
);
1549 ok(ref
== 1, "device refcount is %d\n", ref
);
1552 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1553 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1554 ok(test_vp
== viewport3
, "Got unexpected viewport %p\n", test_vp
);
1555 ref
= get_refcount((IUnknown
*) viewport3
);
1556 ok(ref
== 4, "viewport3 refcount is %d\n", ref
);
1557 if(test_vp
) IDirect3DViewport3_Release(test_vp
);
1559 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1561 /* Cannot set the viewport to NULL */
1562 hr
= IDirect3DDevice3_SetCurrentViewport(device
, NULL
);
1563 ok(hr
== DDERR_INVALIDPARAMS
, "Failed to set viewport to NULL, hr %#x.\n", hr
);
1565 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1566 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1567 ok(test_vp
== viewport3
, "Got unexpected viewport %p\n", test_vp
);
1568 if(test_vp
) IDirect3DViewport3_Release(test_vp
);
1570 /* SetCurrentViewport properly releases the old viewport's reference */
1571 hr
= IDirect3DDevice3_SetCurrentViewport(device
, another_vp
);
1572 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1573 ref
= get_refcount((IUnknown
*) viewport3
);
1574 ok(ref
== 2, "viewport3 refcount is %d\n", ref
);
1575 ref
= get_refcount((IUnknown
*) another_vp
);
1576 ok(ref
== 3, "another_vp refcount is %d\n", ref
);
1578 /* Unlike device2::DeleteViewport, device3::DeleteViewport releases the
1579 * reference held by SetCurrentViewport */
1580 hr
= IDirect3DDevice3_DeleteViewport(device
, another_vp
);
1581 ok(SUCCEEDED(hr
), "Failed to delete viewport from device, hr %#x.\n", hr
);
1582 ref
= get_refcount((IUnknown
*) another_vp
);
1583 ok(ref
== 1, "another_vp refcount is %d\n", ref
);
1585 /* GetCurrentViewport still fails */
1587 hr
= IDirect3DDevice3_GetCurrentViewport(device
, &test_vp
);
1588 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1589 ok(test_vp
== NULL
, "Got unexpected viewport %p\n", test_vp
);
1590 if(test_vp
) IDirect3DViewport3_Release(test_vp
);
1592 /* Setting a different viewport doesn't have any surprises now */
1593 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport3
);
1594 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1595 ref
= get_refcount((IUnknown
*) viewport3
);
1596 ok(ref
== 3, "viewport3 refcount is %d\n", ref
);
1597 ref
= get_refcount((IUnknown
*) another_vp
);
1598 ok(ref
== 1, "another_vp refcount is %d\n", ref
);
1600 /* Destroying the device removes the viewport and releases the reference */
1601 IDirect3DDevice3_Release(device
);
1602 ref
= get_refcount((IUnknown
*) viewport3
);
1603 ok(ref
== 1, "viewport3 refcount is %d\n", ref
);
1605 ref
= IDirect3DViewport3_Release(another_vp
);
1606 ok(ref
== 0, "Got unexpected ref %d\n", ref
);
1607 ref
= IDirect3DViewport3_Release(viewport3
);
1608 ok(ref
== 0, "Got unexpected ref %d\n", ref
);
1609 IDirect3D3_Release(d3d
);
1610 DestroyWindow(window
);
1611 IDirectDraw4_Release(ddraw
);
1614 static void test_zenable(void)
1616 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1619 struct vec4 position
;
1624 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1625 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1626 {{640.0f
, 480.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1627 {{640.0f
, 0.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1629 IDirect3DViewport3
*viewport
;
1630 IDirect3DDevice3
*device
;
1631 IDirectDrawSurface4
*rt
;
1638 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1639 0, 0, 640, 480, 0, 0, 0, 0);
1640 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1642 skip("Failed to create a 3D device, skipping test.\n");
1643 DestroyWindow(window
);
1647 viewport
= create_viewport(device
, 0, 0, 640, 480);
1648 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1649 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1651 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1652 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1654 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 0.0f
, 0);
1655 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1656 hr
= IDirect3DDevice3_BeginScene(device
);
1657 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1658 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, tquad
, 4, 0);
1659 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1660 hr
= IDirect3DDevice3_EndScene(device
);
1661 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1663 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1664 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1665 for (i
= 0; i
< 4; ++i
)
1667 for (j
= 0; j
< 4; ++j
)
1669 x
= 80 * ((2 * j
) + 1);
1670 y
= 60 * ((2 * i
) + 1);
1671 color
= get_surface_color(rt
, x
, y
);
1672 ok(compare_color(color
, 0x0000ff00, 1),
1673 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1676 IDirectDrawSurface4_Release(rt
);
1678 destroy_viewport(device
, viewport
);
1679 IDirect3DDevice3_Release(device
);
1680 DestroyWindow(window
);
1683 static void test_ck_rgba(void)
1685 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1688 struct vec4 position
;
1689 struct vec2 texcoord
;
1693 {{ 0.0f
, 480.0f
, 0.25f
, 1.0f
}, {0.0f
, 0.0f
}},
1694 {{ 0.0f
, 0.0f
, 0.25f
, 1.0f
}, {0.0f
, 1.0f
}},
1695 {{640.0f
, 480.0f
, 0.25f
, 1.0f
}, {1.0f
, 0.0f
}},
1696 {{640.0f
, 0.0f
, 0.25f
, 1.0f
}, {1.0f
, 1.0f
}},
1697 {{ 0.0f
, 480.0f
, 0.75f
, 1.0f
}, {0.0f
, 0.0f
}},
1698 {{ 0.0f
, 0.0f
, 0.75f
, 1.0f
}, {0.0f
, 1.0f
}},
1699 {{640.0f
, 480.0f
, 0.75f
, 1.0f
}, {1.0f
, 0.0f
}},
1700 {{640.0f
, 0.0f
, 0.75f
, 1.0f
}, {1.0f
, 1.0f
}},
1704 D3DCOLOR fill_color
;
1707 D3DCOLOR result1
, result1_broken
;
1708 D3DCOLOR result2
, result2_broken
;
1712 /* r200 on Windows doesn't check the alpha component when applying the color
1713 * key, so the key matches on every texel. */
1714 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1715 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1716 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1717 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1718 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1719 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1720 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1721 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1724 IDirectDrawSurface4
*surface
;
1725 IDirect3DViewport3
*viewport
;
1726 DDSURFACEDESC2 surface_desc
;
1727 IDirect3DTexture2
*texture
;
1728 IDirect3DDevice3
*device
;
1729 IDirectDrawSurface4
*rt
;
1730 IDirectDraw4
*ddraw
;
1738 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1739 0, 0, 640, 480, 0, 0, 0, 0);
1740 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1742 skip("Failed to create a 3D device, skipping test.\n");
1743 DestroyWindow(window
);
1747 viewport
= create_viewport(device
, 0, 0, 640, 480);
1748 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1749 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1751 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1752 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1753 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1754 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1755 IDirect3D3_Release(d3d
);
1757 memset(&surface_desc
, 0, sizeof(surface_desc
));
1758 surface_desc
.dwSize
= sizeof(surface_desc
);
1759 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1760 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1761 surface_desc
.dwWidth
= 256;
1762 surface_desc
.dwHeight
= 256;
1763 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1764 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1765 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1766 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1767 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1768 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1769 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1770 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1771 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1772 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1773 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1774 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1775 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1777 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
1778 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1779 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1780 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1781 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1782 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1784 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1785 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1787 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1789 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1790 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1791 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1792 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1794 memset(&fx
, 0, sizeof(fx
));
1795 fx
.dwSize
= sizeof(fx
);
1796 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1797 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1798 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1800 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
,
1801 D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 1.0f
, 0);
1802 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1803 hr
= IDirect3DDevice3_BeginScene(device
);
1804 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1805 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1806 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1807 hr
= IDirect3DDevice3_EndScene(device
);
1808 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1810 color
= get_surface_color(rt
, 320, 240);
1811 ok(compare_color(color
, tests
[i
].result1
, 1) || compare_color(color
, tests
[i
].result1_broken
, 1),
1812 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1813 tests
[i
].result1
, i
, color
);
1815 U5(fx
).dwFillColor
= 0xff0000ff;
1816 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1817 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1819 hr
= IDirect3DDevice3_BeginScene(device
);
1820 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1821 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[4], 4, 0);
1822 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1823 hr
= IDirect3DDevice3_EndScene(device
);
1824 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1826 /* This tests that fragments that are masked out by the color key are
1827 * discarded, instead of just fully transparent. */
1828 color
= get_surface_color(rt
, 320, 240);
1829 ok(compare_color(color
, tests
[i
].result2
, 1) || compare_color(color
, tests
[i
].result2_broken
, 1),
1830 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1831 tests
[i
].result2
, i
, color
);
1834 IDirectDrawSurface4_Release(rt
);
1835 IDirect3DTexture2_Release(texture
);
1836 IDirectDrawSurface4_Release(surface
);
1837 destroy_viewport(device
, viewport
);
1838 IDirectDraw4_Release(ddraw
);
1839 IDirect3DDevice3_Release(device
);
1840 DestroyWindow(window
);
1843 static void test_ck_default(void)
1845 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1848 struct vec4 position
;
1849 struct vec2 texcoord
;
1853 {{ 0.0f
, 480.0f
, 0.0f
, 1.0f
}, {0.0f
, 0.0f
}},
1854 {{ 0.0f
, 0.0f
, 0.0f
, 1.0f
}, {0.0f
, 1.0f
}},
1855 {{640.0f
, 480.0f
, 0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
1856 {{640.0f
, 0.0f
, 0.0f
, 1.0f
}, {1.0f
, 1.0f
}},
1858 IDirectDrawSurface4
*surface
, *rt
;
1859 IDirect3DViewport3
*viewport
;
1860 DDSURFACEDESC2 surface_desc
;
1861 IDirect3DTexture2
*texture
;
1862 IDirect3DDevice3
*device
;
1863 IDirectDraw4
*ddraw
;
1871 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1872 0, 0, 640, 480, 0, 0, 0, 0);
1874 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1876 skip("Failed to create a 3D device, skipping test.\n");
1877 DestroyWindow(window
);
1881 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1882 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1883 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1884 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1885 IDirect3D3_Release(d3d
);
1887 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
1888 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1890 viewport
= create_viewport(device
, 0, 0, 640, 480);
1891 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
1892 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1894 memset(&surface_desc
, 0, sizeof(surface_desc
));
1895 surface_desc
.dwSize
= sizeof(surface_desc
);
1896 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1897 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1898 surface_desc
.dwWidth
= 256;
1899 surface_desc
.dwHeight
= 256;
1900 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1901 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1902 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1903 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1904 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1905 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1906 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1907 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1908 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1909 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1910 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1911 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1912 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
1913 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1915 memset(&fx
, 0, sizeof(fx
));
1916 fx
.dwSize
= sizeof(fx
);
1917 U5(fx
).dwFillColor
= 0x000000ff;
1918 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1919 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1921 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1922 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1923 hr
= IDirect3DDevice3_BeginScene(device
);
1924 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1925 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1926 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1927 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1928 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1929 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1930 hr
= IDirect3DDevice3_EndScene(device
);
1931 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1932 color
= get_surface_color(rt
, 320, 240);
1933 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1935 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1936 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1937 hr
= IDirect3DDevice3_BeginScene(device
);
1938 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1939 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1940 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1941 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1942 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1943 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1944 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1945 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1946 hr
= IDirect3DDevice3_EndScene(device
);
1947 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1948 color
= get_surface_color(rt
, 320, 240);
1949 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1951 IDirect3DTexture_Release(texture
);
1952 IDirectDrawSurface4_Release(surface
);
1953 destroy_viewport(device
, viewport
);
1954 IDirectDrawSurface4_Release(rt
);
1955 IDirect3DDevice3_Release(device
);
1956 IDirectDraw4_Release(ddraw
);
1957 DestroyWindow(window
);
1960 static void test_ck_complex(void)
1962 IDirectDrawSurface4
*surface
, *mipmap
, *tmp
;
1963 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
1964 DDSURFACEDESC2 surface_desc
;
1965 IDirect3DDevice3
*device
;
1966 DDCOLORKEY color_key
;
1967 IDirectDraw4
*ddraw
;
1974 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1975 0, 0, 640, 480, 0, 0, 0, 0);
1976 if (!(device
= create_device(window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1978 skip("Failed to create a 3D device, skipping test.\n");
1979 DestroyWindow(window
);
1982 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
1983 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1984 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
1985 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1986 IDirect3D3_Release(d3d
);
1988 memset(&surface_desc
, 0, sizeof(surface_desc
));
1989 surface_desc
.dwSize
= sizeof(surface_desc
);
1990 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1991 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1992 surface_desc
.dwWidth
= 128;
1993 surface_desc
.dwHeight
= 128;
1994 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1995 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1997 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1998 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1999 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
2000 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
2001 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2002 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
2003 memset(&color_key
, 0, sizeof(color_key
));
2004 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2005 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
2006 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2007 color_key
.dwColorSpaceLowValue
);
2008 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2009 color_key
.dwColorSpaceHighValue
);
2012 IDirectDrawSurface_AddRef(mipmap
);
2013 for (i
= 0; i
< 7; ++i
)
2015 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
2016 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
2018 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2019 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
2020 color_key
.dwColorSpaceLowValue
= 0x000000ff;
2021 color_key
.dwColorSpaceHighValue
= 0x000000ff;
2022 hr
= IDirectDrawSurface4_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2023 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x, i %u.\n", hr
, i
);
2024 memset(&color_key
, 0, sizeof(color_key
));
2025 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2026 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x, i %u.\n", hr
, i
);
2027 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
2028 color_key
.dwColorSpaceLowValue
, i
);
2029 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
2030 color_key
.dwColorSpaceHighValue
, i
);
2032 IDirectDrawSurface_Release(mipmap
);
2036 memset(&color_key
, 0, sizeof(color_key
));
2037 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2038 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
2039 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2040 color_key
.dwColorSpaceLowValue
);
2041 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2042 color_key
.dwColorSpaceHighValue
);
2044 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
2045 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
2046 IDirectDrawSurface_Release(mipmap
);
2047 refcount
= IDirectDrawSurface4_Release(surface
);
2048 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2050 memset(&surface_desc
, 0, sizeof(surface_desc
));
2051 surface_desc
.dwSize
= sizeof(surface_desc
);
2052 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
2053 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
2054 U5(surface_desc
).dwBackBufferCount
= 1;
2055 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2056 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2058 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2059 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
2060 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
2061 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
2062 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2063 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
2064 memset(&color_key
, 0, sizeof(color_key
));
2065 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
2066 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
2067 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2068 color_key
.dwColorSpaceLowValue
);
2069 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2070 color_key
.dwColorSpaceHighValue
);
2072 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &tmp
);
2073 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
2075 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2076 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
2077 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
2078 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
2079 hr
= IDirectDrawSurface4_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2080 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
2081 memset(&color_key
, 0, sizeof(color_key
));
2082 hr
= IDirectDrawSurface4_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
2083 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
2084 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2085 color_key
.dwColorSpaceLowValue
);
2086 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
2087 color_key
.dwColorSpaceHighValue
);
2089 IDirectDrawSurface_Release(tmp
);
2091 refcount
= IDirectDrawSurface4_Release(surface
);
2092 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2093 IDirectDraw4_Release(ddraw
);
2094 refcount
= IDirect3DDevice3_Release(device
);
2095 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
2096 DestroyWindow(window
);
2102 REFIID refcount_iid
;
2106 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
2107 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
2109 ULONG refcount
, expected_refcount
;
2110 IUnknown
*iface1
, *iface2
;
2114 for (i
= 0; i
< entry_count
; ++i
)
2116 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
2117 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
2120 for (j
= 0; j
< entry_count
; ++j
)
2122 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
2123 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
2126 expected_refcount
= 0;
2127 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
2128 ++expected_refcount
;
2129 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
2130 ++expected_refcount
;
2131 refcount
= IUnknown_Release(iface2
);
2132 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2133 refcount
, test_name
, i
, j
, expected_refcount
);
2137 expected_refcount
= 0;
2138 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
2139 ++expected_refcount
;
2140 refcount
= IUnknown_Release(iface1
);
2141 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2142 refcount
, test_name
, i
, expected_refcount
);
2147 static void test_surface_qi(void)
2149 static const struct qi_test tests
[] =
2151 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface4
, S_OK
},
2152 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface4
, S_OK
},
2153 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
2154 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2155 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
2156 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
2157 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
2158 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
2159 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
2160 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
2161 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
2162 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
2163 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
2164 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
2165 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
2166 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
2167 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
2168 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
2169 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
2170 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
2171 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
2172 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
2173 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
2174 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
2175 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
2176 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
2177 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
2178 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
2179 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
2180 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
2181 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
2182 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
2183 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
2184 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
2185 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
2188 IDirectDrawSurface4
*surface
;
2189 DDSURFACEDESC2 surface_desc
;
2190 IDirect3DDevice3
*device
;
2191 IDirectDraw4
*ddraw
;
2195 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2197 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2201 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2202 0, 0, 640, 480, 0, 0, 0, 0);
2203 /* Try to create a D3D device to see if the ddraw implementation supports
2204 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2205 * doesn't support e.g. the IDirect3DTexture interfaces. */
2206 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
2208 skip("Failed to create a 3D device, skipping test.\n");
2209 DestroyWindow(window
);
2212 IDirect3DDevice_Release(device
);
2213 ddraw
= create_ddraw();
2214 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2215 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2216 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
2218 memset(&surface_desc
, 0, sizeof(surface_desc
));
2219 surface_desc
.dwSize
= sizeof(surface_desc
);
2220 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2221 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2222 surface_desc
.dwWidth
= 512;
2223 surface_desc
.dwHeight
= 512;
2224 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2225 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2227 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface4
, tests
, sizeof(tests
) / sizeof(*tests
));
2229 IDirectDrawSurface4_Release(surface
);
2230 IDirectDraw4_Release(ddraw
);
2231 DestroyWindow(window
);
2234 static void test_device_qi(void)
2236 static const struct qi_test tests
[] =
2238 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
2239 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
2240 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
2241 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2242 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
2243 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
2244 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
2245 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
2246 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
2247 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
2248 {&IID_IDirect3DDevice3
, &IID_IDirect3DDevice3
, S_OK
},
2249 {&IID_IDirect3DDevice2
, &IID_IDirect3DDevice3
, S_OK
},
2250 {&IID_IDirect3DDevice
, &IID_IDirect3DDevice3
, S_OK
},
2251 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
2252 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
2253 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
2254 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
2255 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
2256 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
2257 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
2258 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
2259 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
2260 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
2261 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
2262 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
2263 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
2264 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
2265 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
2266 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
2267 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
2268 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
2269 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
2270 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
2271 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
2272 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
2273 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
2274 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
2275 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
2276 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
2277 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
2278 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
2279 {&IID_IUnknown
, &IID_IDirect3DDevice3
, S_OK
},
2282 IDirect3DDevice3
*device
;
2285 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2286 0, 0, 640, 480, 0, 0, 0, 0);
2287 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
2289 skip("Failed to create a 3D device, skipping test.\n");
2290 DestroyWindow(window
);
2294 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice3
, tests
, sizeof(tests
) / sizeof(*tests
));
2296 IDirect3DDevice3_Release(device
);
2297 DestroyWindow(window
);
2300 static void test_wndproc(void)
2302 LONG_PTR proc
, ddraw_proc
;
2303 IDirectDraw4
*ddraw
;
2309 static struct message messages
[] =
2311 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2312 {WM_MOVE
, FALSE
, 0},
2313 {WM_SIZE
, FALSE
, 0},
2314 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2315 {WM_ACTIVATE
, FALSE
, 0},
2316 {WM_SETFOCUS
, FALSE
, 0},
2320 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2321 ddraw
= create_ddraw();
2322 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2324 wc
.lpfnWndProc
= test_proc
;
2325 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2326 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2328 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2329 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2331 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2332 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2333 (LONG_PTR
)test_proc
, proc
);
2334 expect_messages
= messages
;
2335 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2336 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2337 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2338 expect_messages
= NULL
;
2339 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2340 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2341 (LONG_PTR
)test_proc
, proc
);
2342 ref
= IDirectDraw4_Release(ddraw
);
2343 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2344 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2345 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2346 (LONG_PTR
)test_proc
, proc
);
2348 /* DDSCL_NORMAL doesn't. */
2349 ddraw
= create_ddraw();
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
);
2353 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2354 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2355 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2356 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2357 (LONG_PTR
)test_proc
, proc
);
2358 ref
= IDirectDraw4_Release(ddraw
);
2359 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2360 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2361 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2362 (LONG_PTR
)test_proc
, proc
);
2364 /* The original window proc is only restored by ddraw if the current
2365 * window proc matches the one ddraw set. This also affects switching
2366 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2367 ddraw
= create_ddraw();
2368 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2369 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2370 (LONG_PTR
)test_proc
, proc
);
2371 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2372 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2373 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2374 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2375 (LONG_PTR
)test_proc
, proc
);
2377 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2378 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2379 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2380 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2381 (LONG_PTR
)test_proc
, proc
);
2382 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2383 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2384 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2385 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2386 (LONG_PTR
)test_proc
, proc
);
2387 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2388 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2389 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2390 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2391 (LONG_PTR
)DefWindowProcA
, proc
);
2392 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2393 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2394 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2395 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2396 (LONG_PTR
)DefWindowProcA
, proc
);
2397 ref
= IDirectDraw4_Release(ddraw
);
2398 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2399 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2400 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2401 (LONG_PTR
)test_proc
, proc
);
2403 ddraw
= create_ddraw();
2404 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2405 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2406 (LONG_PTR
)test_proc
, proc
);
2407 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2408 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2409 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2410 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2411 (LONG_PTR
)test_proc
, proc
);
2412 ref
= IDirectDraw4_Release(ddraw
);
2413 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2414 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2415 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2416 (LONG_PTR
)DefWindowProcA
, proc
);
2418 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2419 expect_messages
= NULL
;
2420 DestroyWindow(window
);
2421 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2424 static void test_window_style(void)
2426 LONG style
, exstyle
, tmp
, expected_style
;
2427 RECT fullscreen_rect
, r
;
2428 IDirectDraw4
*ddraw
;
2434 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2435 0, 0, 100, 100, 0, 0, 0, 0);
2436 ddraw
= create_ddraw();
2437 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2439 style
= GetWindowLongA(window
, GWL_STYLE
);
2440 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2441 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2443 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2444 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2446 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2447 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2448 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2449 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2451 GetWindowRect(window
, &r
);
2452 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2453 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2454 r
.left
, r
.top
, r
.right
, r
.bottom
);
2455 GetClientRect(window
, &r
);
2456 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2458 ret
= SetForegroundWindow(GetDesktopWindow());
2459 ok(ret
, "Failed to set foreground window.\n");
2461 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2462 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2463 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2464 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2466 ret
= SetForegroundWindow(window
);
2467 ok(ret
, "Failed to set foreground window.\n");
2468 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2469 * the next tests expect this. */
2470 ShowWindow(window
, SW_HIDE
);
2472 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2473 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2475 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2476 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2477 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2478 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2480 ShowWindow(window
, SW_SHOW
);
2481 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2482 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2484 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2485 expected_style
= style
| WS_VISIBLE
;
2486 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2487 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2488 expected_style
= exstyle
| WS_EX_TOPMOST
;
2489 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2491 ret
= SetForegroundWindow(GetDesktopWindow());
2492 ok(ret
, "Failed to set foreground window.\n");
2493 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2494 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2495 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2496 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2497 expected_style
= exstyle
| WS_EX_TOPMOST
;
2498 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2500 ref
= IDirectDraw4_Release(ddraw
);
2501 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2503 DestroyWindow(window
);
2506 static void test_redundant_mode_set(void)
2508 DDSURFACEDESC2 surface_desc
= {0};
2509 IDirectDraw4
*ddraw
;
2515 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2516 0, 0, 100, 100, 0, 0, 0, 0);
2517 ddraw
= create_ddraw();
2518 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2520 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2521 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2523 surface_desc
.dwSize
= sizeof(surface_desc
);
2524 hr
= IDirectDraw4_GetDisplayMode(ddraw
, &surface_desc
);
2525 ok(SUCCEEDED(hr
), "GetDipslayMode failed, hr %#x.\n", hr
);
2527 hr
= IDirectDraw4_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2528 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2529 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2531 GetWindowRect(window
, &r
);
2534 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2535 GetWindowRect(window
, &s
);
2536 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2537 r
.left
, r
.top
, r
.right
, r
.bottom
,
2538 s
.left
, s
.top
, s
.right
, s
.bottom
);
2540 hr
= IDirectDraw4_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2541 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2542 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2544 GetWindowRect(window
, &s
);
2545 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2546 r
.left
, r
.top
, r
.right
, r
.bottom
,
2547 s
.left
, s
.top
, s
.right
, s
.bottom
);
2549 ref
= IDirectDraw4_Release(ddraw
);
2550 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2552 DestroyWindow(window
);
2555 static SIZE screen_size
, screen_size2
;
2557 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2559 if (message
== WM_SIZE
)
2561 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2562 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2565 return test_proc(hwnd
, message
, wparam
, lparam
);
2568 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2570 if (message
== WM_SIZE
)
2572 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2573 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2576 return test_proc(hwnd
, message
, wparam
, lparam
);
2579 struct test_coop_level_mode_set_enum_param
2581 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2584 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC2
*surface_desc
, void *context
)
2586 struct test_coop_level_mode_set_enum_param
*param
= context
;
2588 if (U1(U4(*surface_desc
).ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2589 return DDENUMRET_OK
;
2590 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2591 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2592 return DDENUMRET_OK
;
2594 if (!param
->ddraw_width
)
2596 param
->ddraw_width
= surface_desc
->dwWidth
;
2597 param
->ddraw_height
= surface_desc
->dwHeight
;
2598 return DDENUMRET_OK
;
2600 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2601 return DDENUMRET_OK
;
2603 param
->user32_width
= surface_desc
->dwWidth
;
2604 param
->user32_height
= surface_desc
->dwHeight
;
2605 return DDENUMRET_CANCEL
;
2608 static void test_coop_level_mode_set(void)
2610 IDirectDrawSurface4
*primary
;
2611 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2612 IDirectDraw4
*ddraw
;
2613 DDSURFACEDESC2 ddsd
;
2615 HWND window
, window2
;
2619 struct test_coop_level_mode_set_enum_param param
;
2624 static const struct message exclusive_messages
[] =
2626 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2627 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2628 {WM_SIZE
, FALSE
, 0},
2629 {WM_DISPLAYCHANGE
, FALSE
, 0},
2632 static const struct message exclusive_focus_loss_messages
[] =
2634 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2635 {WM_DISPLAYCHANGE
, FALSE
, 0},
2636 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2637 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2638 * SW_MINIMIZED, causing a recursive window activation that does not
2639 * produce the same result in Wine yet. Ignore the difference for now.
2640 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2641 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2642 {WM_MOVE
, FALSE
, 0},
2643 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2644 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2647 static const struct message exclusive_focus_restore_messages
[] =
2649 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2650 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2651 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2652 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2653 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2654 /* Native redundantly sets the window size here. */
2655 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2656 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2657 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2658 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2661 static const struct message sc_restore_messages
[] =
2663 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2664 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2665 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2666 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2669 static const struct message sc_minimize_messages
[] =
2671 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2672 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2673 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2674 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2677 static const struct message sc_maximize_messages
[] =
2679 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2680 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2681 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2682 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2686 static const struct message normal_messages
[] =
2688 {WM_DISPLAYCHANGE
, FALSE
, 0},
2692 ddraw
= create_ddraw();
2693 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2695 memset(¶m
, 0, sizeof(param
));
2696 hr
= IDirectDraw4_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2697 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2698 ref
= IDirectDraw4_Release(ddraw
);
2699 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2701 if (!param
.user32_height
)
2703 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2707 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2708 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2709 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2711 memset(&devmode
, 0, sizeof(devmode
));
2712 devmode
.dmSize
= sizeof(devmode
);
2713 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2714 devmode
.dmPelsWidth
= param
.user32_width
;
2715 devmode
.dmPelsHeight
= param
.user32_height
;
2716 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2717 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2719 ddraw
= create_ddraw();
2720 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2722 wc
.lpfnWndProc
= mode_set_proc
;
2723 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2724 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2725 wc
.lpfnWndProc
= mode_set_proc2
;
2726 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2727 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2729 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2730 0, 0, 100, 100, 0, 0, 0, 0);
2731 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2732 0, 0, 100, 100, 0, 0, 0, 0);
2734 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2735 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2737 GetWindowRect(window
, &r
);
2738 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2739 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2740 r
.left
, r
.top
, r
.right
, r
.bottom
);
2742 memset(&ddsd
, 0, sizeof(ddsd
));
2743 ddsd
.dwSize
= sizeof(ddsd
);
2744 ddsd
.dwFlags
= DDSD_CAPS
;
2745 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2747 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2748 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2749 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2750 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2751 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2752 param
.user32_width
, ddsd
.dwWidth
);
2753 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2754 param
.user32_height
, ddsd
.dwHeight
);
2756 GetWindowRect(window
, &r
);
2757 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2758 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2759 r
.left
, r
.top
, r
.right
, r
.bottom
);
2761 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2762 expect_messages
= exclusive_messages
;
2766 hr
= IDirectDrawSurface4_IsLost(primary
);
2767 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2768 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2769 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2770 hr
= IDirectDrawSurface4_IsLost(primary
);
2771 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2773 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2774 expect_messages
= NULL
;
2775 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2776 "Expected screen size %ux%u, got %ux%u.\n",
2777 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
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 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2785 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2786 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2787 param
.user32_width
, ddsd
.dwWidth
);
2788 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2789 param
.user32_height
, ddsd
.dwHeight
);
2790 IDirectDrawSurface4_Release(primary
);
2792 memset(&ddsd
, 0, sizeof(ddsd
));
2793 ddsd
.dwSize
= sizeof(ddsd
);
2794 ddsd
.dwFlags
= DDSD_CAPS
;
2795 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2797 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2798 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2799 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2800 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2801 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2802 param
.ddraw_width
, ddsd
.dwWidth
);
2803 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2804 param
.ddraw_height
, ddsd
.dwHeight
);
2806 GetWindowRect(window
, &r
);
2807 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2808 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2809 r
.left
, r
.top
, r
.right
, r
.bottom
);
2811 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2812 expect_messages
= exclusive_messages
;
2816 hr
= IDirectDrawSurface4_IsLost(primary
);
2817 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2818 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2819 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2820 hr
= IDirectDrawSurface4_IsLost(primary
);
2821 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2823 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2824 expect_messages
= NULL
;
2825 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2826 "Expected screen size %ux%u, got %ux%u.\n",
2827 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2829 GetWindowRect(window
, &r
);
2830 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2831 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2832 r
.left
, r
.top
, r
.right
, r
.bottom
);
2834 expect_messages
= exclusive_focus_loss_messages
;
2835 ret
= SetForegroundWindow(GetDesktopWindow());
2836 ok(ret
, "Failed to set foreground window.\n");
2837 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2838 memset(&devmode
, 0, sizeof(devmode
));
2839 devmode
.dmSize
= sizeof(devmode
);
2840 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2841 ok(ret
, "Failed to get display mode.\n");
2842 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2843 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2844 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2846 expect_messages
= exclusive_focus_restore_messages
;
2847 ShowWindow(window
, SW_RESTORE
);
2848 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2850 GetWindowRect(window
, &r
);
2851 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2852 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2853 r
.left
, r
.top
, r
.right
, r
.bottom
);
2854 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2855 ok(ret
, "Failed to get display mode.\n");
2856 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2857 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2858 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2860 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2861 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2862 /* Normally the primary should be restored here. Unfortunately this causes the
2863 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2864 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2865 * the point of the GetSurfaceDesc call. */
2867 expect_messages
= sc_minimize_messages
;
2868 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2869 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2870 expect_messages
= NULL
;
2872 expect_messages
= sc_restore_messages
;
2873 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2874 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2875 expect_messages
= NULL
;
2877 expect_messages
= sc_maximize_messages
;
2878 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2879 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2880 expect_messages
= NULL
;
2882 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2883 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2885 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2886 expect_messages
= exclusive_messages
;
2890 hr
= IDirectDrawSurface4_IsLost(primary
);
2891 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2892 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
2893 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2894 hr
= IDirectDrawSurface4_IsLost(primary
);
2895 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2897 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2898 expect_messages
= NULL
;
2899 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2900 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2901 "Expected screen size %ux%u, got %ux%u.\n",
2902 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2904 GetWindowRect(window
, &r
);
2905 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2906 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2907 r
.left
, r
.top
, r
.right
, r
.bottom
);
2909 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2910 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2911 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2912 param
.ddraw_width
, ddsd
.dwWidth
);
2913 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2914 param
.ddraw_height
, ddsd
.dwHeight
);
2915 IDirectDrawSurface4_Release(primary
);
2918 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2919 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
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 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2941 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2943 GetWindowRect(window
, &r
);
2944 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2945 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2946 r
.left
, r
.top
, r
.right
, r
.bottom
);
2948 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2949 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2950 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2951 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2952 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2953 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2954 IDirectDrawSurface4_Release(primary
);
2956 memset(&ddsd
, 0, sizeof(ddsd
));
2957 ddsd
.dwSize
= sizeof(ddsd
);
2958 ddsd
.dwFlags
= DDSD_CAPS
;
2959 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2961 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2962 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2963 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
2964 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2965 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2966 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2967 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2968 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2970 GetWindowRect(window
, &r
);
2971 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2972 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2973 r
.left
, r
.top
, r
.right
, r
.bottom
);
2975 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2976 expect_messages
= normal_messages
;
2980 hr
= IDirectDrawSurface4_IsLost(primary
);
2981 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2982 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2983 devmode
.dmPelsWidth
= param
.user32_width
;
2984 devmode
.dmPelsHeight
= param
.user32_height
;
2985 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2986 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2987 hr
= IDirectDrawSurface4_IsLost(primary
);
2988 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2990 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2991 expect_messages
= NULL
;
2992 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2994 GetWindowRect(window
, &r
);
2995 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2996 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2997 r
.left
, r
.top
, r
.right
, r
.bottom
);
2999 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3000 expect_messages
= normal_messages
;
3004 hr
= IDirectDrawSurface4_Restore(primary
);
3005 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
3006 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3007 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3008 hr
= IDirectDrawSurface4_Restore(primary
);
3009 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
3010 hr
= IDirectDrawSurface4_IsLost(primary
);
3011 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3013 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3014 expect_messages
= NULL
;
3015 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3017 GetWindowRect(window
, &r
);
3018 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3019 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3020 r
.left
, r
.top
, r
.right
, r
.bottom
);
3022 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3023 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3024 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3025 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3026 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3027 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3028 IDirectDrawSurface4_Release(primary
);
3030 memset(&ddsd
, 0, sizeof(ddsd
));
3031 ddsd
.dwSize
= sizeof(ddsd
);
3032 ddsd
.dwFlags
= DDSD_CAPS
;
3033 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3035 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3036 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3037 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3038 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3039 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3040 param
.ddraw_width
, ddsd
.dwWidth
);
3041 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3042 param
.ddraw_height
, ddsd
.dwHeight
);
3044 GetWindowRect(window
, &r
);
3045 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3046 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3047 r
.left
, r
.top
, r
.right
, r
.bottom
);
3049 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3050 expect_messages
= normal_messages
;
3054 hr
= IDirectDrawSurface4_IsLost(primary
);
3055 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3056 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
3057 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3058 hr
= IDirectDrawSurface4_IsLost(primary
);
3059 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3061 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3062 expect_messages
= NULL
;
3063 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3065 GetWindowRect(window
, &r
);
3066 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3067 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3068 r
.left
, r
.top
, r
.right
, r
.bottom
);
3070 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3071 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3072 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3073 param
.ddraw_width
, ddsd
.dwWidth
);
3074 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3075 param
.ddraw_height
, ddsd
.dwHeight
);
3076 IDirectDrawSurface4_Release(primary
);
3078 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3079 ok(ret
, "Failed to get display mode.\n");
3080 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3081 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3082 "Expected resolution %ux%u, got %ux%u.\n",
3083 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3084 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3085 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3086 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3088 memset(&ddsd
, 0, sizeof(ddsd
));
3089 ddsd
.dwSize
= sizeof(ddsd
);
3090 ddsd
.dwFlags
= DDSD_CAPS
;
3091 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3093 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3094 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3095 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3096 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3097 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3098 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3099 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3100 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3102 GetWindowRect(window
, &r
);
3103 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3104 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3105 r
.left
, r
.top
, r
.right
, r
.bottom
);
3107 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
3108 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
3109 * not DDSCL_FULLSCREEN. */
3110 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3111 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3113 GetWindowRect(window
, &r
);
3114 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3115 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3116 r
.left
, r
.top
, r
.right
, r
.bottom
);
3118 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3119 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3120 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3121 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3122 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3123 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3124 IDirectDrawSurface4_Release(primary
);
3126 memset(&ddsd
, 0, sizeof(ddsd
));
3127 ddsd
.dwSize
= sizeof(ddsd
);
3128 ddsd
.dwFlags
= DDSD_CAPS
;
3129 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3131 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3132 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
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
);
3140 GetWindowRect(window
, &r
);
3141 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3142 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3143 r
.left
, r
.top
, r
.right
, r
.bottom
);
3145 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3146 expect_messages
= normal_messages
;
3150 hr
= IDirectDrawSurface4_IsLost(primary
);
3151 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3152 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
3153 devmode
.dmPelsWidth
= param
.user32_width
;
3154 devmode
.dmPelsHeight
= param
.user32_height
;
3155 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3156 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3157 hr
= IDirectDrawSurface4_IsLost(primary
);
3158 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3160 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3161 expect_messages
= NULL
;
3162 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3164 GetWindowRect(window
, &r
);
3165 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3166 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3167 r
.left
, r
.top
, r
.right
, r
.bottom
);
3169 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3170 expect_messages
= normal_messages
;
3174 hr
= IDirectDrawSurface4_Restore(primary
);
3175 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
3176 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3177 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3178 hr
= IDirectDrawSurface4_Restore(primary
);
3179 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
3180 hr
= IDirectDrawSurface4_IsLost(primary
);
3181 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3183 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3184 expect_messages
= NULL
;
3185 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3187 GetWindowRect(window
, &r
);
3188 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3189 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3190 r
.left
, r
.top
, r
.right
, r
.bottom
);
3192 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3193 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3194 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3195 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3196 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3197 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3198 IDirectDrawSurface4_Release(primary
);
3200 memset(&ddsd
, 0, sizeof(ddsd
));
3201 ddsd
.dwSize
= sizeof(ddsd
);
3202 ddsd
.dwFlags
= DDSD_CAPS
;
3203 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3205 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3206 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3207 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3208 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3209 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3210 param
.ddraw_width
, ddsd
.dwWidth
);
3211 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3212 param
.ddraw_height
, ddsd
.dwHeight
);
3214 GetWindowRect(window
, &r
);
3215 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3216 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3217 r
.left
, r
.top
, r
.right
, r
.bottom
);
3219 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3220 expect_messages
= normal_messages
;
3224 hr
= IDirectDrawSurface4_IsLost(primary
);
3225 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3226 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
3227 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3228 hr
= IDirectDrawSurface4_IsLost(primary
);
3229 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3231 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3232 expect_messages
= NULL
;
3233 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3235 GetWindowRect(window
, &r
);
3236 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3237 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3238 r
.left
, r
.top
, r
.right
, r
.bottom
);
3240 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3241 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3242 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3243 param
.ddraw_width
, ddsd
.dwWidth
);
3244 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3245 param
.ddraw_height
, ddsd
.dwHeight
);
3246 IDirectDrawSurface4_Release(primary
);
3248 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3249 ok(ret
, "Failed to get display mode.\n");
3250 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3251 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3252 "Expected resolution %ux%u, got %ux%u.\n",
3253 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3254 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3255 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3256 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3258 memset(&ddsd
, 0, sizeof(ddsd
));
3259 ddsd
.dwSize
= sizeof(ddsd
);
3260 ddsd
.dwFlags
= DDSD_CAPS
;
3261 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3263 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3264 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3265 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3266 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3267 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3268 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3269 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3270 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3271 IDirectDrawSurface4_Release(primary
);
3273 GetWindowRect(window
, &r
);
3274 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3275 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3276 r
.left
, r
.top
, r
.right
, r
.bottom
);
3278 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3279 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3280 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3281 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3282 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3284 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3285 expect_messages
= exclusive_messages
;
3289 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3290 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3292 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3293 expect_messages
= NULL
;
3294 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
3295 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
3296 "Expected screen size %ux%u, got %ux%u.\n",
3297 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3298 screen_size
.cx
, screen_size
.cy
);
3300 GetWindowRect(window
, &r
);
3301 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3302 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3303 r
.left
, r
.top
, r
.right
, r
.bottom
);
3305 memset(&ddsd
, 0, sizeof(ddsd
));
3306 ddsd
.dwSize
= sizeof(ddsd
);
3307 ddsd
.dwFlags
= DDSD_CAPS
;
3308 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3310 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3311 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3312 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3313 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3314 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3315 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3316 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3317 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3318 IDirectDrawSurface4_Release(primary
);
3320 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3321 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3322 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3323 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3324 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3326 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3327 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3329 memset(&ddsd
, 0, sizeof(ddsd
));
3330 ddsd
.dwSize
= sizeof(ddsd
);
3331 ddsd
.dwFlags
= DDSD_CAPS
;
3332 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3334 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3335 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3336 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3337 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3338 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3339 param
.ddraw_width
, ddsd
.dwWidth
);
3340 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3341 param
.ddraw_height
, ddsd
.dwHeight
);
3342 IDirectDrawSurface4_Release(primary
);
3344 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
3345 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3347 /* If the window is changed at the same time, messages are sent to the new window. */
3348 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3349 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3350 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3351 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3353 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3354 expect_messages
= exclusive_messages
;
3357 screen_size2
.cx
= 0;
3358 screen_size2
.cy
= 0;
3360 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3361 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3363 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3364 expect_messages
= NULL
;
3365 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
3366 screen_size
.cx
, screen_size
.cy
);
3367 ok(screen_size2
.cx
== registry_mode
.dmPelsWidth
&& screen_size2
.cy
== registry_mode
.dmPelsHeight
,
3368 "Expected screen size 2 %ux%u, got %ux%u.\n",
3369 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size2
.cx
, screen_size2
.cy
);
3371 GetWindowRect(window
, &r
);
3372 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3373 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
3374 r
.left
, r
.top
, r
.right
, r
.bottom
);
3375 GetWindowRect(window2
, &r
);
3376 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3377 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3378 r
.left
, r
.top
, r
.right
, r
.bottom
);
3380 memset(&ddsd
, 0, sizeof(ddsd
));
3381 ddsd
.dwSize
= sizeof(ddsd
);
3382 ddsd
.dwFlags
= DDSD_CAPS
;
3383 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3385 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3386 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3387 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &ddsd
);
3388 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3389 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3390 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3391 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3392 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3393 IDirectDrawSurface4_Release(primary
);
3395 ref
= IDirectDraw4_Release(ddraw
);
3396 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3398 GetWindowRect(window
, &r
);
3399 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3400 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
3401 r
.left
, r
.top
, r
.right
, r
.bottom
);
3403 expect_messages
= NULL
;
3404 DestroyWindow(window
);
3405 DestroyWindow(window2
);
3406 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3407 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3410 static void test_coop_level_mode_set_multi(void)
3412 IDirectDraw4
*ddraw1
, *ddraw2
;
3418 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3419 0, 0, 100, 100, 0, 0, 0, 0);
3420 ddraw1
= create_ddraw();
3421 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3423 /* With just a single ddraw object, the display mode is restored on
3425 hr
= set_display_mode(ddraw1
, 800, 600);
3426 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3427 w
= GetSystemMetrics(SM_CXSCREEN
);
3428 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3429 h
= GetSystemMetrics(SM_CYSCREEN
);
3430 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3432 ref
= IDirectDraw4_Release(ddraw1
);
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 /* When there are multiple ddraw objects, the display mode is restored to
3440 * the initial mode, before the first SetDisplayMode() call. */
3441 ddraw1
= create_ddraw();
3442 hr
= set_display_mode(ddraw1
, 800, 600);
3443 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3444 w
= GetSystemMetrics(SM_CXSCREEN
);
3445 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3446 h
= GetSystemMetrics(SM_CYSCREEN
);
3447 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3449 ddraw2
= create_ddraw();
3450 hr
= set_display_mode(ddraw2
, 640, 480);
3451 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3452 w
= GetSystemMetrics(SM_CXSCREEN
);
3453 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3454 h
= GetSystemMetrics(SM_CYSCREEN
);
3455 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3457 ref
= IDirectDraw4_Release(ddraw2
);
3458 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3459 w
= GetSystemMetrics(SM_CXSCREEN
);
3460 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3461 h
= GetSystemMetrics(SM_CYSCREEN
);
3462 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3464 ref
= IDirectDraw4_Release(ddraw1
);
3465 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3466 w
= GetSystemMetrics(SM_CXSCREEN
);
3467 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3468 h
= GetSystemMetrics(SM_CYSCREEN
);
3469 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3471 /* Regardless of release ordering. */
3472 ddraw1
= create_ddraw();
3473 hr
= set_display_mode(ddraw1
, 800, 600);
3474 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3475 w
= GetSystemMetrics(SM_CXSCREEN
);
3476 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3477 h
= GetSystemMetrics(SM_CYSCREEN
);
3478 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3480 ddraw2
= create_ddraw();
3481 hr
= set_display_mode(ddraw2
, 640, 480);
3482 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3483 w
= GetSystemMetrics(SM_CXSCREEN
);
3484 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3485 h
= GetSystemMetrics(SM_CYSCREEN
);
3486 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3488 ref
= IDirectDraw4_Release(ddraw1
);
3489 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3490 w
= GetSystemMetrics(SM_CXSCREEN
);
3491 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3492 h
= GetSystemMetrics(SM_CYSCREEN
);
3493 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3495 ref
= IDirectDraw4_Release(ddraw2
);
3496 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3497 w
= GetSystemMetrics(SM_CXSCREEN
);
3498 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3499 h
= GetSystemMetrics(SM_CYSCREEN
);
3500 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3502 /* But only for ddraw objects that called SetDisplayMode(). */
3503 ddraw1
= create_ddraw();
3504 ddraw2
= create_ddraw();
3505 hr
= set_display_mode(ddraw2
, 640, 480);
3506 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3507 w
= GetSystemMetrics(SM_CXSCREEN
);
3508 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3509 h
= GetSystemMetrics(SM_CYSCREEN
);
3510 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3512 ref
= IDirectDraw4_Release(ddraw1
);
3513 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3514 w
= GetSystemMetrics(SM_CXSCREEN
);
3515 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3516 h
= GetSystemMetrics(SM_CYSCREEN
);
3517 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3519 ref
= IDirectDraw4_Release(ddraw2
);
3520 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3521 w
= GetSystemMetrics(SM_CXSCREEN
);
3522 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3523 h
= GetSystemMetrics(SM_CYSCREEN
);
3524 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3526 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3527 * restoring the display mode. */
3528 ddraw1
= create_ddraw();
3529 hr
= set_display_mode(ddraw1
, 800, 600);
3530 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3531 w
= GetSystemMetrics(SM_CXSCREEN
);
3532 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3533 h
= GetSystemMetrics(SM_CYSCREEN
);
3534 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3536 ddraw2
= create_ddraw();
3537 hr
= set_display_mode(ddraw2
, 640, 480);
3538 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3539 w
= GetSystemMetrics(SM_CXSCREEN
);
3540 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3541 h
= GetSystemMetrics(SM_CYSCREEN
);
3542 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3544 hr
= IDirectDraw4_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3545 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3547 ref
= IDirectDraw4_Release(ddraw1
);
3548 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3549 w
= GetSystemMetrics(SM_CXSCREEN
);
3550 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3551 h
= GetSystemMetrics(SM_CYSCREEN
);
3552 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3554 ref
= IDirectDraw4_Release(ddraw2
);
3555 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3556 w
= GetSystemMetrics(SM_CXSCREEN
);
3557 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3558 h
= GetSystemMetrics(SM_CYSCREEN
);
3559 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3561 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3562 ddraw1
= create_ddraw();
3563 hr
= set_display_mode(ddraw1
, 800, 600);
3564 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3565 w
= GetSystemMetrics(SM_CXSCREEN
);
3566 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3567 h
= GetSystemMetrics(SM_CYSCREEN
);
3568 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3570 hr
= IDirectDraw4_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3571 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3573 ddraw2
= create_ddraw();
3574 hr
= set_display_mode(ddraw2
, 640, 480);
3575 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3577 ref
= IDirectDraw4_Release(ddraw1
);
3578 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3579 w
= GetSystemMetrics(SM_CXSCREEN
);
3580 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3581 h
= GetSystemMetrics(SM_CYSCREEN
);
3582 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3584 ref
= IDirectDraw4_Release(ddraw2
);
3585 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3586 w
= GetSystemMetrics(SM_CXSCREEN
);
3587 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3588 h
= GetSystemMetrics(SM_CYSCREEN
);
3589 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3591 DestroyWindow(window
);
3594 static void test_initialize(void)
3596 IDirectDraw4
*ddraw
;
3599 ddraw
= create_ddraw();
3600 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3602 hr
= IDirectDraw4_Initialize(ddraw
, NULL
);
3603 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3604 IDirectDraw4_Release(ddraw
);
3607 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw4
, (void **)&ddraw
);
3608 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw4 instance, hr %#x.\n", hr
);
3609 hr
= IDirectDraw4_Initialize(ddraw
, NULL
);
3610 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3611 hr
= IDirectDraw4_Initialize(ddraw
, NULL
);
3612 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3613 IDirectDraw4_Release(ddraw
);
3617 static void test_coop_level_surf_create(void)
3619 IDirectDrawSurface4
*surface
;
3620 IDirectDraw4
*ddraw
;
3621 DDSURFACEDESC2 ddsd
;
3624 ddraw
= create_ddraw();
3625 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3627 memset(&ddsd
, 0, sizeof(ddsd
));
3628 ddsd
.dwSize
= sizeof(ddsd
);
3629 ddsd
.dwFlags
= DDSD_CAPS
;
3630 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3631 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3632 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3634 IDirectDraw4_Release(ddraw
);
3637 static void test_vb_discard(void)
3639 static const struct vec4 quad
[] =
3641 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
3642 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
3643 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
3644 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
3647 IDirect3DDevice3
*device
;
3649 IDirect3DVertexBuffer
*buffer
;
3652 D3DVERTEXBUFFERDESC desc
;
3654 static const unsigned int vbsize
= 16;
3657 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3658 0, 0, 640, 480, 0, 0, 0, 0);
3660 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3662 skip("Failed to create a 3D device, skipping test.\n");
3663 DestroyWindow(window
);
3667 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
3668 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
3670 memset(&desc
, 0, sizeof(desc
));
3671 desc
.dwSize
= sizeof(desc
);
3672 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
3673 desc
.dwFVF
= D3DFVF_XYZRHW
;
3674 desc
.dwNumVertices
= vbsize
;
3675 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0, NULL
);
3676 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3678 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3679 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3680 memcpy(data
, quad
, sizeof(quad
));
3681 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
3682 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3684 hr
= IDirect3DDevice3_BeginScene(device
);
3685 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3686 hr
= IDirect3DDevice3_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
3687 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3688 hr
= IDirect3DDevice3_EndScene(device
);
3689 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3691 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3692 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3693 memset(data
, 0xaa, sizeof(struct vec4
) * vbsize
);
3694 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
3695 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3697 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3698 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3699 for (i
= 0; i
< sizeof(struct vec4
) * vbsize
; i
++)
3701 if (data
[i
] != 0xaa)
3703 ok(FALSE
, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i
, data
[i
]);
3707 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
3708 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3710 IDirect3DVertexBuffer_Release(buffer
);
3711 IDirect3D3_Release(d3d
);
3712 IDirect3DDevice3_Release(device
);
3713 DestroyWindow(window
);
3716 static void test_coop_level_multi_window(void)
3718 HWND window1
, window2
;
3719 IDirectDraw4
*ddraw
;
3722 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3723 0, 0, 640, 480, 0, 0, 0, 0);
3724 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3725 0, 0, 640, 480, 0, 0, 0, 0);
3726 ddraw
= create_ddraw();
3727 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3729 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3730 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3731 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3732 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3733 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3734 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3736 IDirectDraw4_Release(ddraw
);
3737 DestroyWindow(window2
);
3738 DestroyWindow(window1
);
3741 static void test_draw_strided(void)
3743 static struct vec3 position
[] =
3750 static DWORD diffuse
[] =
3752 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3754 static WORD indices
[] =
3759 IDirectDrawSurface4
*rt
;
3760 IDirect3DDevice3
*device
;
3764 D3DDRAWPRIMITIVESTRIDEDDATA strided
;
3765 IDirect3DViewport3
*viewport
;
3766 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3768 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3769 0, 0, 640, 480, 0, 0, 0, 0);
3771 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3773 skip("Failed to create a 3D device, skipping test.\n");
3774 DestroyWindow(window
);
3778 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
3779 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3780 viewport
= create_viewport(device
, 0, 0, 640, 480);
3781 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
3782 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
3783 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
3784 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
3786 hr
= IDirect3DDevice3_BeginScene(device
);
3787 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3789 memset(&strided
, 0x55, sizeof(strided
));
3790 strided
.position
.lpvData
= position
;
3791 strided
.position
.dwStride
= sizeof(*position
);
3792 strided
.diffuse
.lpvData
= diffuse
;
3793 strided
.diffuse
.dwStride
= sizeof(*diffuse
);
3794 hr
= IDirect3DDevice3_DrawIndexedPrimitiveStrided(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
3795 &strided
, 4, indices
, 6, 0);
3796 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3798 hr
= IDirect3DDevice3_EndScene(device
);
3799 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3801 color
= get_surface_color(rt
, 320, 240);
3802 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3804 IDirect3DViewport3_Release(viewport
);
3805 IDirectDrawSurface4_Release(rt
);
3806 IDirect3DDevice3_Release(device
);
3807 DestroyWindow(window
);
3810 static void test_lighting(void)
3812 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3813 static D3DMATRIX mat
=
3815 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3816 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3817 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3818 0.0f
, 0.0f
, 0.0f
, 1.0f
,
3822 1.0f
, 0.0f
, 1.0f
, 0.0f
,
3823 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3824 1.0f
, 0.0f
, 1.0f
, 0.0f
,
3825 0.0f
, 0.0f
, 0.5f
, 1.0f
,
3829 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3830 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3831 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
3832 10.f
, 10.0f
, 10.0f
, 1.0f
,
3836 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3837 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3838 0.0f
, 0.0f
, 1.0f
, -1.0f
,
3839 10.f
, 10.0f
, 10.0f
, 0.0f
,
3843 struct vec3 position
;
3848 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
3849 {{-1.0f
, 0.0f
, 0.1f
}, 0xffff0000},
3850 {{ 0.0f
, 0.0f
, 0.1f
}, 0xffff0000},
3851 {{ 0.0f
, -1.0f
, 0.1f
}, 0xffff0000},
3855 {{-1.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
3856 {{-1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
3857 {{ 0.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
3858 {{ 0.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
3862 struct vec3 position
;
3868 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3869 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3870 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3871 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3875 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3876 {{0.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3877 {{1.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3878 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3882 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3883 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3884 {{ 1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3885 {{ 1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3889 {{-10.0f
, -11.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3890 {{-10.0f
, -9.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3891 {{-10.0f
, -9.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3892 {{-10.0f
, -11.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3896 {{-11.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3897 {{-11.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3898 {{ -9.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3899 {{ -9.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3901 static WORD indices
[] = {0, 1, 2, 2, 3, 0};
3904 D3DMATRIX
*world_matrix
;
3907 const char *message
;
3911 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
3912 {&mat_singular
, nquad
, 0x000000b4, "Lit quad with singular world matrix"},
3913 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
3914 {&mat_nonaffine
, translatedquad
, 0x000000ff, "Lit quad with non-affine matrix"},
3919 IDirect3DDevice3
*device
;
3920 IDirectDrawSurface4
*rt
;
3921 IDirect3DViewport3
*viewport
;
3922 IDirect3DMaterial3
*material
;
3923 IDirect3DLight
*light
;
3924 D3DMATERIALHANDLE mat_handle
;
3925 D3DLIGHT2 light_desc
;
3927 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
3928 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
3933 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3934 0, 0, 640, 480, 0, 0, 0, 0);
3935 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3937 skip("Failed to create a 3D device, skipping test.\n");
3938 DestroyWindow(window
);
3942 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
3943 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
3945 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
3946 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3948 viewport
= create_viewport(device
, 0, 0, 640, 480);
3949 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
3950 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3952 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
3953 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3955 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
3956 ok(SUCCEEDED(hr
), "Failed to set world transformation, hr %#x.\n", hr
);
3957 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
3958 ok(SUCCEEDED(hr
), "Failed to set view transformation, hr %#x.\n", hr
);
3959 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
3960 ok(SUCCEEDED(hr
), "Failed to set projection transformation, hr %#x.\n", hr
);
3961 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3962 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
3963 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
3964 ok(SUCCEEDED(hr
), "Failed to disable zbuffer, hr %#x.\n", hr
);
3965 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
3966 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
3967 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
3968 ok(SUCCEEDED(hr
), "Failed to disable stencil buffer, hr %#x.\n", hr
);
3969 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
3970 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
3972 hr
= IDirect3DDevice3_BeginScene(device
);
3973 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3975 /* There is no D3DRENDERSTATE_LIGHTING on ddraw < 7. */
3976 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3977 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3978 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, unlitquad
, 4,
3980 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3982 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
3983 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
3984 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, litquad
, 4,
3986 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3988 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3989 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3990 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, unlitnquad
, 4,
3992 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3994 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
3995 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
3996 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, litnquad
, 4,
3998 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4000 hr
= IDirect3DDevice3_EndScene(device
);
4001 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4003 color
= get_surface_color(rt
, 160, 360);
4004 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color
);
4005 color
= get_surface_color(rt
, 160, 120);
4006 ok(color
== 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color
);
4007 color
= get_surface_color(rt
, 480, 360);
4008 ok(color
== 0x000000ff, "Unlit quad with normals has color 0x%08x.\n", color
);
4009 color
= get_surface_color(rt
, 480, 120);
4010 ok(color
== 0x00ffff00, "Lit quad with normals has color 0x%08x.\n", color
);
4012 material
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
4013 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
4014 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
4015 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
4016 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
4018 hr
= IDirect3D3_CreateLight(d3d
, &light
, NULL
);
4019 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
4020 memset(&light_desc
, 0, sizeof(light_desc
));
4021 light_desc
.dwSize
= sizeof(light_desc
);
4022 light_desc
.dltType
= D3DLIGHT_DIRECTIONAL
;
4023 U1(light_desc
.dcvColor
).r
= 1.0f
;
4024 U2(light_desc
.dcvColor
).g
= 1.0f
;
4025 U3(light_desc
.dcvColor
).b
= 1.0f
;
4026 U4(light_desc
.dcvColor
).a
= 1.0f
;
4027 U3(light_desc
.dvDirection
).z
= 1.0f
;
4028 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
4029 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
4030 hr
= IDirect3DViewport3_AddLight(viewport
, light
);
4031 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
4033 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
4034 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
4036 hr
= IDirect3DDevice3_BeginScene(device
);
4037 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4039 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, nquad
,
4041 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4043 hr
= IDirect3DDevice3_EndScene(device
);
4044 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4046 color
= get_surface_color(rt
, 320, 240);
4047 ok(color
== 0x00000000, "Lit quad with no light has color 0x%08x.\n", color
);
4049 light_desc
.dwFlags
= D3DLIGHT_ACTIVE
;
4050 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
4051 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
4053 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
4055 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, tests
[i
].world_matrix
);
4056 ok(SUCCEEDED(hr
), "Failed to set world transformation, hr %#x.\n", hr
);
4058 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
4059 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
4061 hr
= IDirect3DDevice3_BeginScene(device
);
4062 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4064 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, tests
[i
].quad
,
4066 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4068 hr
= IDirect3DDevice3_EndScene(device
);
4069 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4071 color
= get_surface_color(rt
, 320, 240);
4072 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
4075 hr
= IDirect3DViewport3_DeleteLight(viewport
, light
);
4076 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
4077 IDirect3DLight_Release(light
);
4078 destroy_material(material
);
4079 IDirect3DViewport3_Release(viewport
);
4080 IDirectDrawSurface4_Release(rt
);
4081 refcount
= IDirect3DDevice3_Release(device
);
4082 ok(!refcount
, "Device has %u references left.\n", refcount
);
4083 IDirect3D3_Release(d3d
);
4084 DestroyWindow(window
);
4087 static void test_specular_lighting(void)
4089 static const unsigned int vertices_side
= 5;
4090 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
4091 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_NORMAL
;
4092 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
4093 static D3DMATRIX mat
=
4095 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4096 0.0f
, 1.0f
, 0.0f
, 0.0f
,
4097 0.0f
, 0.0f
, 1.0f
, 0.0f
,
4098 0.0f
, 0.0f
, 0.0f
, 1.0f
,
4100 static D3DLIGHT2 directional
=
4103 D3DLIGHT_DIRECTIONAL
,
4104 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
4105 {{0.0f
}, {0.0f
}, {0.0f
}},
4106 {{0.0f
}, {0.0f
}, {1.0f
}},
4112 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
4113 {{0.0f
}, {0.0f
}, {0.0f
}},
4114 {{0.0f
}, {0.0f
}, {0.0f
}},
4123 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
4124 {{0.0f
}, {0.0f
}, {0.0f
}},
4125 {{0.0f
}, {0.0f
}, {1.0f
}},
4129 M_PI
/ 12.0f
, M_PI
/ 3.0f
4134 D3DLIGHT_PARALLELPOINT
,
4135 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
4136 {{0.5f
}, {0.0f
}, {-1.0f
}},
4137 {{0.0f
}, {0.0f
}, {0.0f
}},
4139 static const struct expected_color
4144 expected_directional
[] =
4146 {160, 120, 0x003c3c3c},
4147 {320, 120, 0x00717171},
4148 {480, 120, 0x003c3c3c},
4149 {160, 240, 0x00717171},
4150 {320, 240, 0x00ffffff},
4151 {480, 240, 0x00717171},
4152 {160, 360, 0x003c3c3c},
4153 {320, 360, 0x00717171},
4154 {480, 360, 0x003c3c3c},
4158 {160, 120, 0x00000000},
4159 {320, 120, 0x00090909},
4160 {480, 120, 0x00000000},
4161 {160, 240, 0x00090909},
4162 {320, 240, 0x00fafafa},
4163 {480, 240, 0x00090909},
4164 {160, 360, 0x00000000},
4165 {320, 360, 0x00090909},
4166 {480, 360, 0x00000000},
4170 {160, 120, 0x00000000},
4171 {320, 120, 0x00020202},
4172 {480, 120, 0x00000000},
4173 {160, 240, 0x00020202},
4174 {320, 240, 0x00fafafa},
4175 {480, 240, 0x00020202},
4176 {160, 360, 0x00000000},
4177 {320, 360, 0x00020202},
4178 {480, 360, 0x00000000},
4180 expected_parallelpoint
[] =
4182 {160, 120, 0x00050505},
4183 {320, 120, 0x002c2c2c},
4184 {480, 120, 0x006e6e6e},
4185 {160, 240, 0x00090909},
4186 {320, 240, 0x00717171},
4187 {480, 240, 0x00ffffff},
4188 {160, 360, 0x00050505},
4189 {320, 360, 0x002c2c2c},
4190 {480, 360, 0x006e6e6e},
4196 const struct expected_color
*expected
;
4197 unsigned int expected_count
;
4201 /* D3DRENDERSTATE_LOCALVIEWER does not exist in D3D < 7 (the behavior is
4202 * the one you get on newer D3D versions with it set as TRUE). */
4203 {&directional
, FALSE
, expected_directional
,
4204 sizeof(expected_directional
) / sizeof(expected_directional
[0])},
4205 {&directional
, TRUE
, expected_directional
,
4206 sizeof(expected_directional
) / sizeof(expected_directional
[0])},
4207 {&point
, TRUE
, expected_point
,
4208 sizeof(expected_point
) / sizeof(expected_point
[0])},
4209 {&spot
, TRUE
, expected_spot
,
4210 sizeof(expected_spot
) / sizeof(expected_spot
[0])},
4211 {¶llelpoint
, TRUE
, expected_parallelpoint
,
4212 sizeof(expected_parallelpoint
) / sizeof(expected_parallelpoint
[0])},
4215 IDirect3DDevice3
*device
;
4216 IDirectDrawSurface4
*rt
;
4217 IDirect3DViewport3
*viewport
;
4218 IDirect3DMaterial3
*material
;
4219 IDirect3DLight
*light
;
4220 D3DMATERIALHANDLE mat_handle
;
4225 unsigned int i
, j
, x
, y
;
4228 struct vec3 position
;
4233 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4234 0, 0, 640, 480, 0, 0, 0, 0);
4235 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4237 skip("Failed to create a 3D device, skipping test.\n");
4238 DestroyWindow(window
);
4242 quad
= HeapAlloc(GetProcessHeap(), 0, vertices_side
* vertices_side
* sizeof(*quad
));
4243 indices
= HeapAlloc(GetProcessHeap(), 0, indices_count
* sizeof(*indices
));
4244 for (i
= 0, y
= 0; y
< vertices_side
; ++y
)
4246 for (x
= 0; x
< vertices_side
; ++x
)
4248 quad
[i
].position
.x
= x
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
4249 quad
[i
].position
.y
= y
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
4250 quad
[i
].position
.z
= 1.0f
;
4251 quad
[i
].normal
.x
= 0.0f
;
4252 quad
[i
].normal
.y
= 0.0f
;
4253 quad
[i
++].normal
.z
= -1.0f
;
4256 for (i
= 0, y
= 0; y
< (vertices_side
- 1); ++y
)
4258 for (x
= 0; x
< (vertices_side
- 1); ++x
)
4260 indices
[i
++] = y
* vertices_side
+ x
+ 1;
4261 indices
[i
++] = y
* vertices_side
+ x
;
4262 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
4263 indices
[i
++] = y
* vertices_side
+ x
+ 1;
4264 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
4265 indices
[i
++] = (y
+ 1) * vertices_side
+ x
+ 1;
4269 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
4270 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
4272 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
4273 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4275 viewport
= create_viewport(device
, 0, 0, 640, 480);
4276 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
4277 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
4279 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
4280 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
4281 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
4282 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
4283 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
4284 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
4285 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
4286 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
4287 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
4288 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
4289 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
4290 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
4292 material
= create_specular_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 30.0f
);
4293 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
4294 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
4295 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
4296 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
4298 hr
= IDirect3D3_CreateLight(d3d
, &light
, NULL
);
4299 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
4300 hr
= IDirect3DViewport3_AddLight(viewport
, light
);
4301 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
4303 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, TRUE
);
4304 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
4306 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
4308 tests
[i
].light
->dwFlags
= D3DLIGHT_ACTIVE
;
4309 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)tests
[i
].light
);
4310 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
4312 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LOCALVIEWER
, tests
[i
].local_viewer
);
4313 ok(SUCCEEDED(hr
), "Failed to set local viewer state, hr %#x.\n", hr
);
4315 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
4316 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
4318 hr
= IDirect3DDevice3_BeginScene(device
);
4319 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4321 hr
= IDirect3DDevice3_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, quad
,
4322 vertices_side
* vertices_side
, indices
, indices_count
, 0);
4323 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4325 hr
= IDirect3DDevice3_EndScene(device
);
4326 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4328 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
4330 color
= get_surface_color(rt
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
4331 ok(compare_color(color
, tests
[i
].expected
[j
].color
, 1),
4332 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
4333 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
4334 tests
[i
].expected
[j
].y
, color
, i
);
4338 hr
= IDirect3DViewport3_DeleteLight(viewport
, light
);
4339 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
4340 IDirect3DLight_Release(light
);
4341 destroy_material(material
);
4342 IDirect3DViewport3_Release(viewport
);
4343 IDirectDrawSurface4_Release(rt
);
4344 refcount
= IDirect3DDevice3_Release(device
);
4345 ok(!refcount
, "Device has %u references left.\n", refcount
);
4346 IDirect3D3_Release(d3d
);
4347 DestroyWindow(window
);
4348 HeapFree(GetProcessHeap(), 0, indices
);
4349 HeapFree(GetProcessHeap(), 0, quad
);
4352 static void test_clear_rect_count(void)
4354 IDirectDrawSurface4
*rt
;
4355 IDirect3DDevice3
*device
;
4359 IDirect3DViewport3
*viewport
;
4360 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
4362 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4363 0, 0, 640, 480, 0, 0, 0, 0);
4364 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4366 skip("Failed to create a 3D device, skipping test.\n");
4367 DestroyWindow(window
);
4371 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
4372 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4374 viewport
= create_viewport(device
, 0, 0, 640, 480);
4375 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
4376 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
4377 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x00ffffff, 0.0f
, 0);
4378 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
4379 hr
= IDirect3DViewport3_Clear2(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
, 0x00ff0000, 0.0f
, 0);
4380 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
4381 hr
= IDirect3DViewport3_Clear2(viewport
, 0, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 0.0f
, 0);
4382 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
4383 hr
= IDirect3DViewport3_Clear2(viewport
, 1, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 0.0f
, 0);
4384 ok(SUCCEEDED(hr
), "Failed to clear the viewport, hr %#x.\n", hr
);
4386 color
= get_surface_color(rt
, 320, 240);
4387 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x000000ff, 1)),
4388 "Got unexpected color 0x%08x.\n", color
);
4390 IDirect3DViewport3_Release(viewport
);
4391 IDirectDrawSurface4_Release(rt
);
4392 IDirect3DDevice3_Release(device
);
4393 DestroyWindow(window
);
4396 static BOOL
test_mode_restored(IDirectDraw4
*ddraw
, HWND window
)
4398 DDSURFACEDESC2 ddsd1
, ddsd2
;
4401 memset(&ddsd1
, 0, sizeof(ddsd1
));
4402 ddsd1
.dwSize
= sizeof(ddsd1
);
4403 hr
= IDirectDraw4_GetDisplayMode(ddraw
, &ddsd1
);
4404 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
4406 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4407 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4408 hr
= set_display_mode(ddraw
, 640, 480);
4409 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
4410 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4411 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4413 memset(&ddsd2
, 0, sizeof(ddsd2
));
4414 ddsd2
.dwSize
= sizeof(ddsd2
);
4415 hr
= IDirectDraw4_GetDisplayMode(ddraw
, &ddsd2
);
4416 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
4417 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
4418 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
4420 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
4423 static void test_coop_level_versions(void)
4429 IDirectDrawSurface
*surface
;
4430 IDirectDraw4
*ddraw4
;
4433 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
4434 0, 0, 640, 480, 0, 0, 0, 0);
4436 ddraw4
= create_ddraw();
4437 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
4438 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
4439 restored
= test_mode_restored(ddraw4
, window
);
4440 ok(restored
, "Display mode not restored in new ddraw object\n");
4442 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
4443 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
4444 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4446 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4447 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
4448 restored
= test_mode_restored(ddraw4
, window
);
4449 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
4451 /* A successful one does */
4452 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4453 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4454 restored
= test_mode_restored(ddraw4
, window
);
4455 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
4457 IDirectDraw_Release(ddraw
);
4458 IDirectDraw4_Release(ddraw4
);
4460 ddraw4
= create_ddraw();
4461 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
4462 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
4463 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4465 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
4466 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4467 restored
= test_mode_restored(ddraw4
, window
);
4468 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
4470 IDirectDraw_Release(ddraw
);
4471 IDirectDraw4_Release(ddraw4
);
4473 /* A failing call does not restore the ddraw2+ behavior */
4474 ddraw4
= create_ddraw();
4475 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
4476 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
4477 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4479 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4480 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4481 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4482 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
4483 restored
= test_mode_restored(ddraw4
, window
);
4484 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
4486 IDirectDraw_Release(ddraw
);
4487 IDirectDraw4_Release(ddraw4
);
4489 /* Neither does a sequence of successful calls with the new interface */
4490 ddraw4
= create_ddraw();
4491 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
4492 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
4493 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4495 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4496 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4497 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4498 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4499 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, DDSCL_NORMAL
);
4500 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4502 restored
= test_mode_restored(ddraw4
, window
);
4503 ok(!restored
, "Display mode restored after ddraw1-ddraw4 SetCooperativeLevel() call sequence\n");
4504 IDirectDraw_Release(ddraw
);
4505 IDirectDraw4_Release(ddraw4
);
4507 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
4508 ddraw4
= create_ddraw();
4509 ok(!!ddraw4
, "Failed to create a ddraw object.\n");
4510 hr
= IDirectDraw4_QueryInterface(ddraw4
, &IID_IDirectDraw
, (void **)&ddraw
);
4511 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4513 hr
= IDirectDraw4_SetCooperativeLevel(ddraw4
, window
, DDSCL_NORMAL
);
4514 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4516 memset(&ddsd
, 0, sizeof(ddsd
));
4517 ddsd
.dwSize
= sizeof(ddsd
);
4518 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4519 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4520 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
4521 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4522 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
4523 IDirectDrawSurface_Release(surface
);
4524 restored
= test_mode_restored(ddraw4
, window
);
4525 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
4527 IDirectDraw_Release(ddraw
);
4528 IDirectDraw4_Release(ddraw4
);
4529 DestroyWindow(window
);
4532 static void test_lighting_interface_versions(void)
4534 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
4535 IDirect3DMaterial3
*emissive
;
4536 IDirect3DViewport3
*viewport
;
4537 IDirect3DDevice3
*device
;
4538 IDirectDrawSurface4
*rt
;
4542 D3DMATERIALHANDLE mat_handle
;
4546 static D3DVERTEX quad
[] =
4548 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4549 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4550 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4551 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4554 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
4557 struct vec3 position
;
4559 DWORD diffuse
, specular
;
4563 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4564 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4565 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4566 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4569 static D3DLVERTEX lquad
[] =
4571 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4572 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4573 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4574 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4577 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
4580 struct vec3 position
;
4581 DWORD diffuse
, specular
;
4582 struct vec2 texcoord
;
4586 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4587 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4588 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4589 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4592 static D3DTLVERTEX tlquad
[] =
4594 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4595 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4596 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4597 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4604 DWORD d3drs_lighting
, d3drs_specular
;
4610 /* Lighting is enabled when all of these conditions are met:
4611 * 1) No pretransformed position(D3DFVF_XYZRHW)
4612 * 2) Normals are available (D3DFVF_NORMAL)
4613 * 3) D3DDP_DONOTLIGHT is not set.
4615 * D3DRENDERSTATE_LIGHTING is ignored, it is not defined
4616 * in this d3d version */
4619 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x0000ff00},
4620 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
4621 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4622 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4623 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x0000ff00},
4624 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
4625 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4626 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4629 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, 0, 0x0000ff00},
4630 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, 0, 0x0000ff00},
4631 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4632 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4633 /* The specular color in the vertex is ignored because
4634 * D3DRENDERSTATE_COLORVERTEX is not enabled */
4635 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, 0, 0x0000ff00},
4636 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, 0, 0x0000ff00},
4637 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4638 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4641 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
4642 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x00ff0000},
4643 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4644 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4645 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
4646 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x00ff8080},
4647 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4648 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4651 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, 0, 0x00ff0000},
4652 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, 0, 0x00ff0000},
4653 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4654 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4655 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, 0, 0x00ff8080},
4656 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, 0, 0x00ff8080},
4657 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4658 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4661 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
4662 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
4663 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
4664 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
4665 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
4666 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
4667 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
4668 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
4671 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4672 0, 0, 640, 480, 0, 0, 0, 0);
4674 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4676 skip("Failed to create a 3D device, skipping test.\n");
4677 DestroyWindow(window
);
4681 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
4682 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4684 viewport
= create_viewport(device
, 0, 0, 640, 480);
4685 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
4686 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
4688 emissive
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
4689 hr
= IDirect3DMaterial3_GetHandle(emissive
, device
, &mat_handle
);
4690 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
4691 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
4692 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
4693 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
4694 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
4696 hr
= IDirect3DDevice3_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
4697 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
4698 ok(rs
== FALSE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs
);
4700 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4702 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff202020, 0.0f
, 0);
4703 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
4705 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
4706 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
4707 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
4708 tests
[i
].d3drs_specular
);
4709 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
4711 hr
= IDirect3DDevice3_BeginScene(device
);
4712 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4713 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
4714 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
4715 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4716 hr
= IDirect3DDevice3_EndScene(device
);
4717 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4719 color
= get_surface_color(rt
, 320, 240);
4720 ok(compare_color(color
, tests
[i
].color
, 1),
4721 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
4722 color
, tests
[i
].color
, i
);
4725 destroy_material(emissive
);
4726 IDirectDrawSurface4_Release(rt
);
4727 ref
= IDirect3DDevice3_Release(device
);
4728 ok(ref
== 0, "Device not properly released, refcount %u.\n", ref
);
4729 DestroyWindow(window
);
4735 IDirectDraw4
*ddraw
;
4738 } activateapp_testdata
;
4740 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
4742 if (message
== WM_ACTIVATEAPP
)
4744 if (activateapp_testdata
.ddraw
)
4747 activateapp_testdata
.received
= FALSE
;
4748 hr
= IDirectDraw4_SetCooperativeLevel(activateapp_testdata
.ddraw
,
4749 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
4750 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
4751 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
4753 activateapp_testdata
.received
= TRUE
;
4756 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
4759 static void test_coop_level_activateapp(void)
4761 IDirectDraw4
*ddraw
;
4765 DDSURFACEDESC2 ddsd
;
4766 IDirectDrawSurface4
*surface
;
4768 ddraw
= create_ddraw();
4769 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4771 wc
.lpfnWndProc
= activateapp_test_proc
;
4772 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
4773 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
4775 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
4776 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
4778 /* Exclusive with window already active. */
4779 SetForegroundWindow(window
);
4780 activateapp_testdata
.received
= FALSE
;
4781 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4782 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4783 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
4784 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4785 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4787 /* Exclusive with window not active. */
4788 SetForegroundWindow(GetDesktopWindow());
4789 activateapp_testdata
.received
= FALSE
;
4790 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4791 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4792 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4793 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4794 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4796 /* Normal with window not active, then exclusive with the same window. */
4797 SetForegroundWindow(GetDesktopWindow());
4798 activateapp_testdata
.received
= FALSE
;
4799 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4800 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4801 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
4802 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4803 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4804 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4805 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4806 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4808 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
4809 SetForegroundWindow(GetDesktopWindow());
4810 activateapp_testdata
.received
= FALSE
;
4811 activateapp_testdata
.ddraw
= ddraw
;
4812 activateapp_testdata
.window
= window
;
4813 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
4814 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4815 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4816 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4817 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4818 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4820 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
4821 * succeeding. Another switch to exclusive and back to normal is needed to release the
4822 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
4823 * WM_ACTIVATEAPP messages. */
4824 activateapp_testdata
.ddraw
= NULL
;
4825 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4826 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4827 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4828 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4830 /* Setting DDSCL_NORMAL with recursive invocation. */
4831 SetForegroundWindow(GetDesktopWindow());
4832 activateapp_testdata
.received
= FALSE
;
4833 activateapp_testdata
.ddraw
= ddraw
;
4834 activateapp_testdata
.window
= window
;
4835 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
4836 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4837 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4838 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4840 /* DDraw is in exlusive mode now. */
4841 memset(&ddsd
, 0, sizeof(ddsd
));
4842 ddsd
.dwSize
= sizeof(ddsd
);
4843 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4844 U5(ddsd
).dwBackBufferCount
= 1;
4845 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4846 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4847 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4848 IDirectDrawSurface4_Release(surface
);
4850 /* Recover again, just to be sure. */
4851 activateapp_testdata
.ddraw
= NULL
;
4852 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4853 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4854 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4855 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4857 DestroyWindow(window
);
4858 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
4859 IDirectDraw4_Release(ddraw
);
4862 static void test_texturemanage(void)
4864 IDirectDraw4
*ddraw
;
4866 DDSURFACEDESC2 ddsd
;
4867 IDirectDrawSurface4
*surface
;
4869 DDCAPS hal_caps
, hel_caps
;
4870 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
4873 DWORD caps_in
, caps2_in
;
4875 DWORD caps_out
, caps2_out
;
4879 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4881 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4883 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4885 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4887 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DD_OK
,
4888 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
},
4889 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DD_OK
,
4890 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
},
4891 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
4892 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_LOCALVIDMEM
, 0},
4893 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
4894 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0},
4896 {0, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4898 {0, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4900 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4902 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4904 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4906 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4908 {DDSCAPS_VIDEOMEMORY
, 0, DD_OK
,
4909 DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
, 0},
4910 {DDSCAPS_SYSTEMMEMORY
, 0, DD_OK
,
4911 DDSCAPS_SYSTEMMEMORY
, 0},
4914 ddraw
= create_ddraw();
4915 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4916 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4917 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4919 memset(&hal_caps
, 0, sizeof(hal_caps
));
4920 hal_caps
.dwSize
= sizeof(hal_caps
);
4921 memset(&hel_caps
, 0, sizeof(hel_caps
));
4922 hel_caps
.dwSize
= sizeof(hel_caps
);
4923 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, &hel_caps
);
4924 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4925 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
4927 skip("Managed textures not supported, skipping managed texture test.\n");
4928 IDirectDraw4_Release(ddraw
);
4932 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4934 memset(&ddsd
, 0, sizeof(ddsd
));
4935 ddsd
.dwSize
= sizeof(ddsd
);
4936 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4937 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps_in
;
4938 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2_in
;
4942 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4943 ok(hr
== tests
[i
].hr
, "Got unexpected, hr %#x, case %u.\n", hr
, i
);
4947 memset(&ddsd
, 0, sizeof(ddsd
));
4948 ddsd
.dwSize
= sizeof(ddsd
);
4949 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
4950 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4952 ok(ddsd
.ddsCaps
.dwCaps
== tests
[i
].caps_out
,
4953 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4954 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps_out
, ddsd
.ddsCaps
.dwCaps
, i
);
4955 ok(ddsd
.ddsCaps
.dwCaps2
== tests
[i
].caps2_out
,
4956 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4957 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps2_out
, ddsd
.ddsCaps
.dwCaps2
, i
);
4959 IDirectDrawSurface4_Release(surface
);
4962 IDirectDraw4_Release(ddraw
);
4965 #define SUPPORT_DXT1 0x01
4966 #define SUPPORT_DXT2 0x02
4967 #define SUPPORT_DXT3 0x04
4968 #define SUPPORT_DXT4 0x08
4969 #define SUPPORT_DXT5 0x10
4970 #define SUPPORT_YUY2 0x20
4971 #define SUPPORT_UYVY 0x40
4973 static HRESULT WINAPI
test_block_formats_creation_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
4975 DWORD
*supported_fmts
= ctx
;
4977 if (!(fmt
->dwFlags
& DDPF_FOURCC
))
4978 return DDENUMRET_OK
;
4980 switch (fmt
->dwFourCC
)
4982 case MAKEFOURCC('D','X','T','1'):
4983 *supported_fmts
|= SUPPORT_DXT1
;
4985 case MAKEFOURCC('D','X','T','2'):
4986 *supported_fmts
|= SUPPORT_DXT2
;
4988 case MAKEFOURCC('D','X','T','3'):
4989 *supported_fmts
|= SUPPORT_DXT3
;
4991 case MAKEFOURCC('D','X','T','4'):
4992 *supported_fmts
|= SUPPORT_DXT4
;
4994 case MAKEFOURCC('D','X','T','5'):
4995 *supported_fmts
|= SUPPORT_DXT5
;
4997 case MAKEFOURCC('Y','U','Y','2'):
4998 *supported_fmts
|= SUPPORT_YUY2
;
5000 case MAKEFOURCC('U','Y','V','Y'):
5001 *supported_fmts
|= SUPPORT_UYVY
;
5007 return DDENUMRET_OK
;
5010 static void test_block_formats_creation(void)
5012 HRESULT hr
, expect_hr
;
5013 unsigned int i
, j
, w
, h
;
5015 IDirectDraw4
*ddraw
;
5017 IDirect3DDevice3
*device
;
5018 IDirectDrawSurface4
*surface
;
5019 DWORD supported_fmts
= 0, supported_overlay_fmts
= 0;
5020 DWORD num_fourcc_codes
= 0, *fourcc_codes
;
5021 DDSURFACEDESC2 ddsd
;
5030 unsigned int block_width
;
5031 unsigned int block_height
;
5032 unsigned int block_size
;
5033 BOOL create_size_checked
, overlay
;
5037 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1
, 4, 4, 8, TRUE
, FALSE
},
5038 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2
, 4, 4, 16, TRUE
, FALSE
},
5039 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3
, 4, 4, 16, TRUE
, FALSE
},
5040 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4
, 4, 4, 16, TRUE
, FALSE
},
5041 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5
, 4, 4, 16, TRUE
, FALSE
},
5042 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2
, 2, 1, 4, FALSE
, TRUE
},
5043 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY
, 2, 1, 4, FALSE
, TRUE
},
5053 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
5054 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
5056 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
5057 * Other hw / drivers successfully create those surfaces. Ignore them, this
5058 * suggests that no game uses this, otherwise Nvidia would support it. */
5060 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0,
5061 "videomemory texture", FALSE
5064 DDSCAPS_VIDEOMEMORY
| DDSCAPS_OVERLAY
, 0,
5065 "videomemory overlay", TRUE
5068 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0,
5069 "systemmemory texture", FALSE
5072 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
5073 "managed texture", FALSE
5085 enum size_type size_type
;
5091 {DDSD_LINEARSIZE
, SIZE_TYPE_ZERO
, 0, DD_OK
},
5092 {DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
5093 {DDSD_PITCH
, SIZE_TYPE_ZERO
, 0, DD_OK
},
5094 {DDSD_PITCH
, SIZE_TYPE_PITCH
, 0, DD_OK
},
5095 {DDSD_LPSURFACE
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
5096 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
5097 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_PITCH
, 0, DDERR_INVALIDPARAMS
},
5098 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
5099 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 1, DD_OK
},
5100 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, -1, DDERR_INVALIDPARAMS
},
5101 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_ZERO
, 0, DD_OK
},
5102 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_PITCH
, 0, DD_OK
},
5103 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_SIZE
, 0, DD_OK
},
5104 {DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
5107 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5108 0, 0, 640, 480, 0, 0, 0, 0);
5110 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5112 skip("Failed to create a 3D device, skipping test.\n");
5113 DestroyWindow(window
);
5117 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
5118 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5119 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **) &ddraw
);
5120 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5121 IDirect3D3_Release(d3d
);
5123 hr
= IDirect3DDevice3_EnumTextureFormats(device
, test_block_formats_creation_cb
,
5125 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
5127 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
5128 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
5129 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
5130 num_fourcc_codes
* sizeof(*fourcc_codes
));
5133 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
5134 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
5135 for (i
= 0; i
< num_fourcc_codes
; i
++)
5137 for (j
= 0; j
< sizeof(formats
) / sizeof(*formats
); j
++)
5139 if (fourcc_codes
[i
] == formats
[j
].fourcc
)
5140 supported_overlay_fmts
|= formats
[j
].support_flag
;
5143 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
5145 memset(&hal_caps
, 0, sizeof(hal_caps
));
5146 hal_caps
.dwSize
= sizeof(hal_caps
);
5147 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
5148 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5150 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 2 * 2 * 16 + 1);
5152 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
5154 for (j
= 0; j
< sizeof(types
) / sizeof(*types
); j
++)
5158 if (formats
[i
].overlay
!= types
[j
].overlay
5159 || (types
[j
].overlay
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
)))
5162 if (formats
[i
].overlay
)
5163 support
= supported_overlay_fmts
& formats
[i
].support_flag
;
5165 support
= supported_fmts
& formats
[i
].support_flag
;
5167 for (w
= 1; w
<= 8; w
++)
5169 for (h
= 1; h
<= 8; h
++)
5171 BOOL block_aligned
= TRUE
;
5174 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
5175 block_aligned
= FALSE
;
5177 memset(&ddsd
, 0, sizeof(ddsd
));
5178 ddsd
.dwSize
= sizeof(ddsd
);
5179 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
5180 ddsd
.ddsCaps
.dwCaps
= types
[j
].caps
;
5181 ddsd
.ddsCaps
.dwCaps2
= types
[j
].caps2
;
5182 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5183 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
5184 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
5188 /* TODO: Handle power of two limitations. I cannot test the pow2
5189 * behavior on windows because I have no hardware that doesn't at
5190 * least support np2_conditional. There's probably no HW that
5191 * supports DXTN textures but no conditional np2 textures. */
5192 if (!support
&& !(types
[j
].caps
& DDSCAPS_SYSTEMMEMORY
))
5193 expect_hr
= DDERR_INVALIDPARAMS
;
5194 else if (formats
[i
].create_size_checked
&& !block_aligned
)
5196 expect_hr
= DDERR_INVALIDPARAMS
;
5197 if (!(types
[j
].caps
& DDSCAPS_TEXTURE
))
5203 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5206 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
5207 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
5210 IDirectDrawSurface4_Release(surface
);
5215 if (formats
[i
].overlay
)
5218 for (j
= 0; j
< sizeof(user_mem_tests
) / sizeof(*user_mem_tests
); ++j
)
5220 memset(&ddsd
, 0, sizeof(ddsd
));
5221 ddsd
.dwSize
= sizeof(ddsd
);
5222 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| user_mem_tests
[j
].flags
;
5223 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
;
5225 switch (user_mem_tests
[j
].size_type
)
5227 case SIZE_TYPE_ZERO
:
5228 U1(ddsd
).dwLinearSize
= 0;
5231 case SIZE_TYPE_PITCH
:
5232 U1(ddsd
).dwLinearSize
= 2 * formats
[i
].block_size
;
5235 case SIZE_TYPE_SIZE
:
5236 U1(ddsd
).dwLinearSize
= 2 * 2 * formats
[i
].block_size
;
5239 U1(ddsd
).dwLinearSize
+= user_mem_tests
[j
].rel_size
;
5241 ddsd
.lpSurface
= mem
;
5242 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5243 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
5244 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
5248 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5249 ok(hr
== user_mem_tests
[j
].hr
, "Test %u: Got unexpected hr %#x, format %s.\n", j
, hr
, formats
[i
].name
);
5254 memset(&ddsd
, 0, sizeof(ddsd
));
5255 ddsd
.dwSize
= sizeof(ddsd
);
5256 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
5257 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", j
, hr
);
5258 ok(ddsd
.dwFlags
== (DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_LINEARSIZE
),
5259 "Test %u: Got unexpected flags %#x.\n", j
, ddsd
.dwFlags
);
5260 if (user_mem_tests
[j
].flags
& DDSD_LPSURFACE
)
5261 ok(U1(ddsd
).dwLinearSize
== ~0u, "Test %u: Got unexpected linear size %#x.\n",
5262 j
, U1(ddsd
).dwLinearSize
);
5264 ok(U1(ddsd
).dwLinearSize
== 2 * 2 * formats
[i
].block_size
,
5265 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
5266 j
, U1(ddsd
).dwLinearSize
, 2 * 2 * formats
[i
].block_size
);
5267 IDirectDrawSurface4_Release(surface
);
5271 HeapFree(GetProcessHeap(), 0, mem
);
5273 IDirectDraw4_Release(ddraw
);
5274 IDirect3DDevice3_Release(device
);
5275 DestroyWindow(window
);
5278 struct format_support_check
5280 const DDPIXELFORMAT
*format
;
5284 static HRESULT WINAPI
test_unsupported_formats_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
5286 struct format_support_check
*format
= ctx
;
5288 if (!memcmp(format
->format
, fmt
, sizeof(*fmt
)))
5290 format
->supported
= TRUE
;
5291 return DDENUMRET_CANCEL
;
5294 return DDENUMRET_OK
;
5297 static void test_unsupported_formats(void)
5300 BOOL expect_success
;
5302 IDirectDraw4
*ddraw
;
5304 IDirect3DDevice3
*device
;
5305 IDirectDrawSurface4
*surface
;
5306 DDSURFACEDESC2 ddsd
;
5308 DWORD expected_caps
;
5319 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
5320 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
5326 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
5327 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
5331 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
5333 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5334 0, 0, 640, 480, 0, 0, 0, 0);
5336 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5338 skip("Failed to create a 3D device, skipping test.\n");
5339 DestroyWindow(window
);
5343 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
5344 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5345 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **) &ddraw
);
5346 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5347 IDirect3D3_Release(d3d
);
5349 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
5351 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
5352 hr
= IDirect3DDevice3_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
5353 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
5355 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
5357 memset(&ddsd
, 0, sizeof(ddsd
));
5358 ddsd
.dwSize
= sizeof(ddsd
);
5359 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5360 U4(ddsd
).ddpfPixelFormat
= formats
[i
].fmt
;
5363 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
5365 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
5366 expect_success
= FALSE
;
5368 expect_success
= TRUE
;
5370 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5371 ok(SUCCEEDED(hr
) == expect_success
,
5372 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
5373 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
5377 memset(&ddsd
, 0, sizeof(ddsd
));
5378 ddsd
.dwSize
= sizeof(ddsd
);
5379 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
5380 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5382 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
5383 expected_caps
= DDSCAPS_VIDEOMEMORY
;
5384 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
5385 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
5386 else if (check
.supported
)
5387 expected_caps
= DDSCAPS_VIDEOMEMORY
;
5389 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
5391 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
5392 "Expected capability %#x, format %s, input cap %#x.\n",
5393 expected_caps
, formats
[i
].name
, caps
[j
]);
5395 IDirectDrawSurface4_Release(surface
);
5399 IDirectDraw4_Release(ddraw
);
5400 IDirect3DDevice3_Release(device
);
5401 DestroyWindow(window
);
5404 static void test_rt_caps(void)
5406 PALETTEENTRY palette_entries
[256];
5407 IDirectDrawPalette
*palette
;
5408 IDirectDraw4
*ddraw
;
5409 DDPIXELFORMAT z_fmt
;
5416 static const DDPIXELFORMAT p8_fmt
=
5418 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
5419 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
5424 const DDPIXELFORMAT
*pf
;
5427 HRESULT create_device_hr
;
5428 HRESULT set_rt_hr
, alternative_set_rt_hr
;
5434 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
5435 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5442 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5443 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5450 DDSCAPS_OFFSCREENPLAIN
,
5451 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5458 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5459 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5460 D3DERR_SURFACENOTINVIDMEM
,
5466 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5467 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5474 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
5475 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5483 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5491 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5498 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5499 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5500 D3DERR_SURFACENOTINVIDMEM
,
5506 DDSCAPS_SYSTEMMEMORY
,
5507 DDSCAPS_SYSTEMMEMORY
,
5515 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5522 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5524 DDERR_NOPALETTEATTACHED
,
5530 DDSCAPS_OFFSCREENPLAIN
,
5531 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5538 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5539 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5540 DDERR_NOPALETTEATTACHED
,
5546 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5547 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5554 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
5555 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5557 DDERR_INVALIDPIXELFORMAT
,
5562 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5563 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5565 DDERR_INVALIDPIXELFORMAT
,
5571 DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5578 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5579 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5581 DDERR_INVALIDPIXELFORMAT
,
5586 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
5587 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
5594 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5595 0, 0, 640, 480, 0, 0, 0, 0);
5596 ddraw
= create_ddraw();
5597 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5598 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5599 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5601 if (FAILED(IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
)))
5603 skip("D3D interface is not available, skipping test.\n");
5607 memset(&z_fmt
, 0, sizeof(z_fmt
));
5608 hr
= IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
5609 if (FAILED(hr
) || !z_fmt
.dwSize
)
5611 skip("No depth buffer formats available, skipping test.\n");
5612 IDirect3D3_Release(d3d
);
5616 memset(palette_entries
, 0, sizeof(palette_entries
));
5617 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
5618 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5620 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5622 IDirectDrawSurface4
*surface
, *rt
, *expected_rt
, *tmp
;
5623 DDSURFACEDESC2 surface_desc
;
5624 IDirect3DDevice3
*device
;
5626 memset(&surface_desc
, 0, sizeof(surface_desc
));
5627 surface_desc
.dwSize
= sizeof(surface_desc
);
5628 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5629 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5630 if (test_data
[i
].pf
)
5632 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5633 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
5635 surface_desc
.dwWidth
= 640;
5636 surface_desc
.dwHeight
= 480;
5637 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5638 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5639 i
, test_data
[i
].caps_in
, hr
);
5641 memset(&surface_desc
, 0, sizeof(surface_desc
));
5642 surface_desc
.dwSize
= sizeof(surface_desc
);
5643 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
5644 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5645 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
5646 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5647 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
5649 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
5650 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
5651 i
, hr
, test_data
[i
].create_device_hr
);
5654 if (hr
== DDERR_NOPALETTEATTACHED
)
5656 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
5657 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
5658 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
5659 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5660 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5662 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5664 IDirectDrawSurface4_Release(surface
);
5666 memset(&surface_desc
, 0, sizeof(surface_desc
));
5667 surface_desc
.dwSize
= sizeof(surface_desc
);
5668 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5669 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5670 surface_desc
.dwWidth
= 640;
5671 surface_desc
.dwHeight
= 480;
5672 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5673 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
5675 hr
= IDirect3D3_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
, NULL
);
5676 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
5679 memset(&surface_desc
, 0, sizeof(surface_desc
));
5680 surface_desc
.dwSize
= sizeof(surface_desc
);
5681 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5682 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5683 if (test_data
[i
].pf
)
5685 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5686 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
5688 surface_desc
.dwWidth
= 640;
5689 surface_desc
.dwHeight
= 480;
5690 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
5691 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5692 i
, test_data
[i
].caps_in
, hr
);
5694 hr
= IDirect3DDevice3_SetRenderTarget(device
, rt
, 0);
5695 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
5696 "Test %u: Got unexpected hr %#x, expected %#x.\n",
5697 i
, hr
, test_data
[i
].set_rt_hr
);
5698 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
5701 expected_rt
= surface
;
5703 hr
= IDirect3DDevice3_GetRenderTarget(device
, &tmp
);
5704 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
5705 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
5707 IDirectDrawSurface4_Release(tmp
);
5708 IDirectDrawSurface4_Release(rt
);
5709 refcount
= IDirect3DDevice3_Release(device
);
5710 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
5711 refcount
= IDirectDrawSurface4_Release(surface
);
5712 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
5715 IDirectDrawPalette_Release(palette
);
5716 IDirect3D3_Release(d3d
);
5719 refcount
= IDirectDraw4_Release(ddraw
);
5720 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5721 DestroyWindow(window
);
5724 static void test_primary_caps(void)
5726 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
5727 IDirectDrawSurface4
*surface
;
5728 DDSURFACEDESC2 surface_desc
;
5729 IDirectDraw4
*ddraw
;
5739 DWORD back_buffer_count
;
5747 DDSCAPS_PRIMARYSURFACE
,
5750 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
5754 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
5761 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
5768 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
5775 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
5782 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
5789 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5796 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5803 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5805 DDERR_NOEXCLUSIVEMODE
,
5809 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5810 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5816 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5817 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5820 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
5823 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5824 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
5830 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5831 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
5838 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5839 0, 0, 640, 480, 0, 0, 0, 0);
5840 ddraw
= create_ddraw();
5841 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5843 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5845 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
5846 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5848 memset(&surface_desc
, 0, sizeof(surface_desc
));
5849 surface_desc
.dwSize
= sizeof(surface_desc
);
5850 surface_desc
.dwFlags
= DDSD_CAPS
;
5851 if (test_data
[i
].back_buffer_count
!= ~0u)
5852 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
5853 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5854 U5(surface_desc
).dwBackBufferCount
= test_data
[i
].back_buffer_count
;
5855 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5856 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
5860 memset(&surface_desc
, 0, sizeof(surface_desc
));
5861 surface_desc
.dwSize
= sizeof(surface_desc
);
5862 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
5863 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5864 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
5865 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5866 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
5868 IDirectDrawSurface4_Release(surface
);
5871 refcount
= IDirectDraw4_Release(ddraw
);
5872 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5873 DestroyWindow(window
);
5876 static void test_surface_lock(void)
5878 IDirectDraw4
*ddraw
;
5879 IDirect3D3
*d3d
= NULL
;
5880 IDirectDrawSurface4
*surface
;
5884 DDSURFACEDESC2 ddsd
;
5886 DDPIXELFORMAT z_fmt
;
5896 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
5898 "videomemory offscreenplain"
5901 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5903 "systemmemory offscreenplain"
5906 DDSCAPS_PRIMARYSURFACE
,
5911 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
5913 "videomemory texture"
5916 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
5918 "opaque videomemory texture"
5921 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
5923 "systemmemory texture"
5927 DDSCAPS2_TEXTUREMANAGE
,
5932 DDSCAPS2_D3DTEXTUREMANAGE
,
5937 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
5938 "opaque managed texture"
5942 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
5943 "opaque managed texture"
5946 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5957 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5958 0, 0, 640, 480, 0, 0, 0, 0);
5959 ddraw
= create_ddraw();
5960 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5961 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5962 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5964 if (FAILED(IDirectDraw4_QueryInterface(ddraw
, &IID_IDirect3D3
, (void **)&d3d
)))
5966 skip("D3D interface is not available, skipping test.\n");
5970 memset(&z_fmt
, 0, sizeof(z_fmt
));
5971 hr
= IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
5972 if (FAILED(hr
) || !z_fmt
.dwSize
)
5974 skip("No depth buffer formats available, skipping test.\n");
5978 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5980 memset(&ddsd
, 0, sizeof(ddsd
));
5981 ddsd
.dwSize
= sizeof(ddsd
);
5982 ddsd
.dwFlags
= DDSD_CAPS
;
5983 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5985 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5989 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
5991 ddsd
.dwFlags
|= DDSD_PIXELFORMAT
;
5992 U4(ddsd
).ddpfPixelFormat
= z_fmt
;
5994 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
5995 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
5997 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5998 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
6000 memset(&ddsd
, 0, sizeof(ddsd
));
6001 ddsd
.dwSize
= sizeof(ddsd
);
6002 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
6003 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
6006 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
6007 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
6010 IDirectDrawSurface4_Release(surface
);
6015 IDirect3D3_Release(d3d
);
6016 refcount
= IDirectDraw4_Release(ddraw
);
6017 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
6018 DestroyWindow(window
);
6021 static void test_surface_discard(void)
6023 IDirect3DDevice3
*device
;
6025 IDirectDraw4
*ddraw
;
6028 DDSURFACEDESC2 ddsd
;
6029 IDirectDrawSurface4
*surface
, *target
;
6038 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
6039 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
6040 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
6041 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
6042 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
},
6043 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
6044 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
},
6045 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
6049 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6050 0, 0, 640, 480, 0, 0, 0, 0);
6052 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
6054 skip("Failed to create a 3D device, skipping test.\n");
6055 DestroyWindow(window
);
6058 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
6059 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
6060 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
6061 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
6062 hr
= IDirect3DDevice3_GetRenderTarget(device
, &target
);
6063 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6065 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
6069 memset(&ddsd
, 0, sizeof(ddsd
));
6070 ddsd
.dwSize
= sizeof(ddsd
);
6071 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6072 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
6073 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
6076 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6077 ok(SUCCEEDED(hr
), "Failed to create offscreen surface, hr %#x, case %u.\n", hr
, i
);
6079 memset(&ddsd
, 0, sizeof(ddsd
));
6080 ddsd
.dwSize
= sizeof(ddsd
);
6081 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
6082 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6083 addr
= ddsd
.lpSurface
;
6084 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
6085 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6087 memset(&ddsd
, 0, sizeof(ddsd
));
6088 ddsd
.dwSize
= sizeof(ddsd
);
6089 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
6090 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6091 discarded
= ddsd
.lpSurface
!= addr
;
6092 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
6093 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6095 hr
= IDirectDrawSurface4_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
6096 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
6098 memset(&ddsd
, 0, sizeof(ddsd
));
6099 ddsd
.dwSize
= sizeof(ddsd
);
6100 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
6101 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6102 discarded
|= ddsd
.lpSurface
!= addr
;
6103 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
6104 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6106 IDirectDrawSurface4_Release(surface
);
6108 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
6109 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
6110 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
6113 IDirectDrawSurface4_Release(target
);
6114 IDirectDraw4_Release(ddraw
);
6115 IDirect3D3_Release(d3d
);
6116 IDirect3DDevice3_Release(device
);
6117 DestroyWindow(window
);
6120 static void test_flip(void)
6122 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
6123 IDirectDrawSurface4
*primary
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
6124 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
6125 DDSURFACEDESC2 surface_desc
;
6126 BOOL sysmem_primary
;
6127 IDirectDraw4
*ddraw
;
6134 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6135 0, 0, 640, 480, 0, 0, 0, 0);
6136 ddraw
= create_ddraw();
6137 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6139 hr
= set_display_mode(ddraw
, 640, 480);
6140 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
6141 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6142 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6144 memset(&surface_desc
, 0, sizeof(surface_desc
));
6145 surface_desc
.dwSize
= sizeof(surface_desc
);
6146 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6147 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6148 U5(surface_desc
).dwBackBufferCount
= 3;
6149 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6150 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6152 memset(&surface_desc
, 0, sizeof(surface_desc
));
6153 surface_desc
.dwSize
= sizeof(surface_desc
);
6154 hr
= IDirectDrawSurface4_GetSurfaceDesc(primary
, &surface_desc
);
6155 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6156 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
)
6157 == (DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
6158 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6159 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
6161 hr
= IDirectDrawSurface4_GetAttachedSurface(primary
, &caps
, &backbuffer1
);
6162 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6163 memset(&surface_desc
, 0, sizeof(surface_desc
));
6164 surface_desc
.dwSize
= sizeof(surface_desc
);
6165 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer1
, &surface_desc
);
6166 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6167 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
6168 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
| DDSCAPS_BACKBUFFER
),
6169 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6171 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
6172 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6173 memset(&surface_desc
, 0, sizeof(surface_desc
));
6174 surface_desc
.dwSize
= sizeof(surface_desc
);
6175 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer2
, &surface_desc
);
6176 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6177 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
6178 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
6179 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6181 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
6182 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6183 memset(&surface_desc
, 0, sizeof(surface_desc
));
6184 surface_desc
.dwSize
= sizeof(surface_desc
);
6185 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer3
, &surface_desc
);
6186 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6187 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
6188 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
6189 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6191 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
6192 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6193 ok(surface
== primary
, "Got unexpected surface %p, expected %p.\n", surface
, primary
);
6194 IDirectDrawSurface4_Release(surface
);
6196 memset(&surface_desc
, 0, sizeof(surface_desc
));
6197 surface_desc
.dwSize
= sizeof(surface_desc
);
6198 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6199 surface_desc
.ddsCaps
.dwCaps
= 0;
6200 surface_desc
.dwWidth
= 640;
6201 surface_desc
.dwHeight
= 480;
6202 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6203 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6204 hr
= IDirectDrawSurface4_Flip(primary
, surface
, DDFLIP_WAIT
);
6205 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6206 IDirectDrawSurface4_Release(surface
);
6208 hr
= IDirectDrawSurface4_Flip(primary
, primary
, DDFLIP_WAIT
);
6209 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6210 hr
= IDirectDrawSurface4_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
6211 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6212 hr
= IDirectDrawSurface4_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
6213 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6214 hr
= IDirectDrawSurface4_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
6215 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6217 memset(&fx
, 0, sizeof(fx
));
6218 fx
.dwSize
= sizeof(fx
);
6219 U5(fx
).dwFillColor
= 0xffff0000;
6220 hr
= IDirectDrawSurface4_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6221 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6222 U5(fx
).dwFillColor
= 0xff00ff00;
6223 hr
= IDirectDrawSurface4_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6224 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6225 U5(fx
).dwFillColor
= 0xff0000ff;
6226 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6227 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6229 hr
= IDirectDrawSurface4_Flip(primary
, NULL
, DDFLIP_WAIT
);
6230 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6231 color
= get_surface_color(backbuffer1
, 320, 240);
6232 /* The testbot seems to just copy the contents of one surface to all the
6233 * others, instead of properly flipping. */
6234 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6235 "Got unexpected color 0x%08x.\n", color
);
6236 color
= get_surface_color(backbuffer2
, 320, 240);
6237 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
6238 U5(fx
).dwFillColor
= 0xffff0000;
6239 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6240 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6242 hr
= IDirectDrawSurface4_Flip(primary
, NULL
, DDFLIP_WAIT
);
6243 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6244 color
= get_surface_color(backbuffer1
, 320, 240);
6245 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6246 "Got unexpected color 0x%08x.\n", color
);
6247 color
= get_surface_color(backbuffer2
, 320, 240);
6248 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6249 U5(fx
).dwFillColor
= 0xff00ff00;
6250 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6251 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6253 hr
= IDirectDrawSurface4_Flip(primary
, NULL
, DDFLIP_WAIT
);
6254 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6255 color
= get_surface_color(backbuffer1
, 320, 240);
6256 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6257 "Got unexpected color 0x%08x.\n", color
);
6258 color
= get_surface_color(backbuffer2
, 320, 240);
6259 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
6260 U5(fx
).dwFillColor
= 0xff0000ff;
6261 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6262 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6264 hr
= IDirectDrawSurface4_Flip(primary
, backbuffer1
, DDFLIP_WAIT
);
6265 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6266 color
= get_surface_color(backbuffer2
, 320, 240);
6267 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6268 "Got unexpected color 0x%08x.\n", color
);
6269 color
= get_surface_color(backbuffer3
, 320, 240);
6270 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
6271 U5(fx
).dwFillColor
= 0xffff0000;
6272 hr
= IDirectDrawSurface4_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6273 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6275 hr
= IDirectDrawSurface4_Flip(primary
, backbuffer2
, DDFLIP_WAIT
);
6276 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6277 color
= get_surface_color(backbuffer1
, 320, 240);
6278 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6279 color
= get_surface_color(backbuffer3
, 320, 240);
6280 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6281 "Got unexpected color 0x%08x.\n", color
);
6282 U5(fx
).dwFillColor
= 0xff00ff00;
6283 hr
= IDirectDrawSurface4_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6284 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6286 hr
= IDirectDrawSurface4_Flip(primary
, backbuffer3
, DDFLIP_WAIT
);
6287 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6288 color
= get_surface_color(backbuffer1
, 320, 240);
6289 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6290 "Got unexpected color 0x%08x.\n", color
);
6291 color
= get_surface_color(backbuffer2
, 320, 240);
6292 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
6294 IDirectDrawSurface4_Release(backbuffer3
);
6295 IDirectDrawSurface4_Release(backbuffer2
);
6296 IDirectDrawSurface4_Release(backbuffer1
);
6297 IDirectDrawSurface4_Release(primary
);
6298 refcount
= IDirectDraw4_Release(ddraw
);
6299 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
6300 DestroyWindow(window
);
6303 static void reset_ddsd(DDSURFACEDESC2
*ddsd
)
6305 memset(ddsd
, 0, sizeof(*ddsd
));
6306 ddsd
->dwSize
= sizeof(*ddsd
);
6309 static void test_set_surface_desc(void)
6311 IDirectDraw4
*ddraw
;
6314 DDSURFACEDESC2 ddsd
;
6315 IDirectDrawSurface4
*surface
;
6325 invalid_caps_tests
[] =
6327 {DDSCAPS_VIDEOMEMORY
, 0, FALSE
, "videomemory plain"},
6328 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, TRUE
, "systemmemory texture"},
6329 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
, "managed texture"},
6330 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
, "managed texture"},
6331 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
, "systemmemory primary"},
6334 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6335 0, 0, 640, 480, 0, 0, 0, 0);
6336 ddraw
= create_ddraw();
6337 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6338 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6339 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6342 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6345 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6346 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6347 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6348 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6349 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6350 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6351 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6353 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6354 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6357 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6358 ddsd
.lpSurface
= data
;
6359 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6360 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6362 /* Redundantly setting the same lpSurface is not an error. */
6363 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6364 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6365 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6366 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6367 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6368 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
6370 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
6371 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6372 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6373 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
6374 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
6375 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6378 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6379 ddsd
.lpSurface
= data
;
6380 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 1);
6381 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
6383 ddsd
.lpSurface
= NULL
;
6384 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6385 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
6387 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, NULL
, 0);
6388 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
6390 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6391 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6392 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6393 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6394 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6396 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
6397 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6398 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
6400 ddsd
.dwFlags
= DDSD_CAPS
;
6401 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6402 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6404 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
6405 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
6406 ddsd
.lpSurface
= data
;
6407 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6408 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6409 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6410 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6411 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6412 ddsd
.ddsCaps
.dwCaps
= 0;
6413 ddsd
.ddsCaps
.dwCaps2
= 0xdeadbeef;
6414 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6415 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6417 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6418 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6419 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6420 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6421 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6423 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
6425 ddsd
.dwFlags
= DDSD_HEIGHT
;
6427 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6428 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
6430 ddsd
.lpSurface
= data
;
6431 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
6432 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6433 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6436 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6437 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
6440 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6441 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
6442 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6443 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6445 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0 */
6447 ddsd
.dwFlags
= DDSD_PITCH
;
6448 U1(ddsd
).lPitch
= 8 * 4;
6449 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6450 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
6452 ddsd
.dwFlags
= DDSD_WIDTH
;
6454 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6455 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
6457 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
6458 ddsd
.lpSurface
= data
;
6459 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6460 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
6462 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
6463 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6464 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
6466 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6467 U1(ddsd
).lPitch
= 16 * 4;
6469 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6470 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6473 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6474 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6475 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6476 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6477 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
6479 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
6481 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
6482 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6483 U1(ddsd
).lPitch
= 4 * 4;
6484 ddsd
.lpSurface
= data
;
6485 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6486 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6488 U1(ddsd
).lPitch
= 4;
6489 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6490 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6492 U1(ddsd
).lPitch
= 16 * 4 + 1;
6493 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6494 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6496 U1(ddsd
).lPitch
= 16 * 4 + 3;
6497 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6498 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6500 U1(ddsd
).lPitch
= -4;
6501 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6502 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
6504 U1(ddsd
).lPitch
= 16 * 4;
6505 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6506 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6509 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6510 U1(ddsd
).lPitch
= 0;
6512 ddsd
.lpSurface
= data
;
6513 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6514 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
6516 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6517 U1(ddsd
).lPitch
= 16 * 4;
6519 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6520 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
6522 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
6523 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
6524 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6525 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6526 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6527 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6528 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6529 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6530 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6531 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
6533 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
6534 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6535 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6537 /* Can't set color keys. */
6539 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
6540 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
6541 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
6542 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6543 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6545 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
6546 ddsd
.lpSurface
= data
;
6547 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6548 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6550 IDirectDrawSurface4_Release(surface
);
6552 /* SetSurfaceDesc needs systemmemory surfaces.
6554 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
6555 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
6558 ddsd
.dwFlags
= DDSD_CAPS
;
6559 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
6560 ddsd
.ddsCaps
.dwCaps2
= invalid_caps_tests
[i
].caps2
;
6561 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
6563 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6566 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6567 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6568 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6569 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6570 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6571 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6574 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6575 ok(SUCCEEDED(hr
) || hr
== DDERR_NODIRECTDRAWHW
, "Failed to create surface, hr %#x.\n", hr
);
6578 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
6579 invalid_caps_tests
[i
].name
);
6584 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6585 ddsd
.lpSurface
= data
;
6586 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6587 if (invalid_caps_tests
[i
].supported
)
6589 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6593 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6594 invalid_caps_tests
[i
].name
, hr
);
6596 /* Check priority of error conditions. */
6597 ddsd
.dwFlags
= DDSD_WIDTH
;
6598 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6599 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6600 invalid_caps_tests
[i
].name
, hr
);
6603 IDirectDrawSurface4_Release(surface
);
6607 ref
= IDirectDraw4_Release(ddraw
);
6608 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6609 DestroyWindow(window
);
6612 static void test_user_memory_getdc(void)
6614 IDirectDraw4
*ddraw
;
6617 DDSURFACEDESC2 ddsd
;
6618 IDirectDrawSurface4
*surface
;
6624 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6625 0, 0, 640, 480, 0, 0, 0, 0);
6626 ddraw
= create_ddraw();
6627 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6629 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6630 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6633 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6636 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6637 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6638 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6639 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6640 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6641 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6642 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6643 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6644 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6646 memset(data
, 0xaa, sizeof(data
));
6648 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6649 ddsd
.lpSurface
= data
;
6650 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6651 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6653 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
6654 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6655 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
6656 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
6657 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
6658 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6660 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
6661 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
6663 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
6664 ddsd
.lpSurface
= data
;
6667 U1(ddsd
).lPitch
= sizeof(*data
);
6668 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6669 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6671 memset(data
, 0xaa, sizeof(data
));
6672 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
6673 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6674 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
6675 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
6676 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
6677 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6679 for (y
= 0; y
< 4; y
++)
6681 for (x
= 0; x
< 4; x
++)
6683 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
6684 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6687 ok(data
[y
][x
] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6691 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6693 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6695 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6697 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6700 IDirectDrawSurface4_Release(surface
);
6701 ref
= IDirectDraw4_Release(ddraw
);
6702 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6703 DestroyWindow(window
);
6706 static void test_sysmem_overlay(void)
6708 IDirectDraw4
*ddraw
;
6711 DDSURFACEDESC2 ddsd
;
6712 IDirectDrawSurface4
*surface
;
6715 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6716 0, 0, 640, 480, 0, 0, 0, 0);
6717 ddraw
= create_ddraw();
6718 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6720 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6721 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6724 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
6727 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
6728 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6729 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6730 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6731 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6732 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6733 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6734 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6735 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
6737 ref
= IDirectDraw4_Release(ddraw
);
6738 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6739 DestroyWindow(window
);
6742 static void test_primary_palette(void)
6744 DDSCAPS2 surface_caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
6745 IDirectDrawSurface4
*primary
, *backbuffer
;
6746 PALETTEENTRY palette_entries
[256];
6747 IDirectDrawPalette
*palette
, *tmp
;
6748 DDSURFACEDESC2 surface_desc
;
6749 IDirectDraw4
*ddraw
;
6755 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6756 0, 0, 640, 480, 0, 0, 0, 0);
6757 ddraw
= create_ddraw();
6758 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6759 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
6761 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6762 IDirectDraw4_Release(ddraw
);
6763 DestroyWindow(window
);
6766 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6767 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6769 memset(&surface_desc
, 0, sizeof(surface_desc
));
6770 surface_desc
.dwSize
= sizeof(surface_desc
);
6771 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6772 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6773 U5(surface_desc
).dwBackBufferCount
= 1;
6774 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6775 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6776 hr
= IDirectDrawSurface4_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
6777 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6779 memset(palette_entries
, 0, sizeof(palette_entries
));
6780 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
6781 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6782 refcount
= get_refcount((IUnknown
*)palette
);
6783 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6785 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6786 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6787 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6789 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
6790 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6792 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6793 * and is generally somewhat broken with respect to 8 bpp / palette
6795 if (SUCCEEDED(IDirectDrawSurface4_GetPalette(backbuffer
, &tmp
)))
6797 win_skip("Broken palette handling detected, skipping tests.\n");
6798 IDirectDrawPalette_Release(tmp
);
6799 IDirectDrawPalette_Release(palette
);
6800 /* The Windows 8 testbot keeps extra references to the primary and
6801 * backbuffer while in 8 bpp mode. */
6802 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
6803 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
6807 refcount
= get_refcount((IUnknown
*)palette
);
6808 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6810 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6811 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6812 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
6813 "Got unexpected palette caps %#x.\n", palette_caps
);
6815 hr
= IDirectDrawSurface4_SetPalette(primary
, NULL
);
6816 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6817 refcount
= get_refcount((IUnknown
*)palette
);
6818 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6820 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6821 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6822 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6824 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
6825 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6826 refcount
= get_refcount((IUnknown
*)palette
);
6827 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6829 hr
= IDirectDrawSurface4_GetPalette(primary
, &tmp
);
6830 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6831 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
6832 IDirectDrawPalette_Release(tmp
);
6833 hr
= IDirectDrawSurface4_GetPalette(backbuffer
, &tmp
);
6834 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6836 refcount
= IDirectDrawPalette_Release(palette
);
6837 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6838 refcount
= IDirectDrawPalette_Release(palette
);
6839 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6841 /* Note that this only seems to work when the palette is attached to the
6842 * primary surface. When attached to a regular surface, attempting to get
6843 * the palette here will cause an access violation. */
6844 hr
= IDirectDrawSurface4_GetPalette(primary
, &tmp
);
6845 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6848 refcount
= IDirectDrawSurface4_Release(backbuffer
);
6849 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6850 refcount
= IDirectDrawSurface4_Release(primary
);
6851 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6852 refcount
= IDirectDraw4_Release(ddraw
);
6853 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6854 DestroyWindow(window
);
6857 static HRESULT WINAPI
surface_counter(IDirectDrawSurface4
*surface
, DDSURFACEDESC2
*desc
, void *context
)
6859 UINT
*surface_count
= context
;
6862 IDirectDrawSurface_Release(surface
);
6864 return DDENUMRET_OK
;
6867 static void test_surface_attachment(void)
6869 IDirectDrawSurface4
*surface1
, *surface2
, *surface3
, *surface4
;
6870 IDirectDrawSurface
*surface1v1
, *surface2v1
;
6871 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, {0}};
6872 DDSURFACEDESC2 surface_desc
;
6873 IDirectDraw4
*ddraw
;
6879 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6880 0, 0, 640, 480, 0, 0, 0, 0);
6881 ddraw
= create_ddraw();
6882 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6883 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6884 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6886 memset(&surface_desc
, 0, sizeof(surface_desc
));
6887 surface_desc
.dwSize
= sizeof(surface_desc
);
6888 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
6889 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6890 U2(surface_desc
).dwMipMapCount
= 3;
6891 surface_desc
.dwWidth
= 128;
6892 surface_desc
.dwHeight
= 128;
6893 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6894 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6896 hr
= IDirectDrawSurface4_GetAttachedSurface(surface1
, &caps
, &surface2
);
6897 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6898 hr
= IDirectDrawSurface4_GetAttachedSurface(surface2
, &caps
, &surface3
);
6899 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6900 hr
= IDirectDrawSurface4_GetAttachedSurface(surface3
, &caps
, &surface4
);
6901 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6904 IDirectDrawSurface4_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
6905 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6907 IDirectDrawSurface4_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
6908 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6910 IDirectDrawSurface4_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
6911 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
6913 memset(&surface_desc
, 0, sizeof(surface_desc
));
6914 surface_desc
.dwSize
= sizeof(surface_desc
);
6915 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6916 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6917 surface_desc
.dwWidth
= 16;
6918 surface_desc
.dwHeight
= 16;
6919 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6920 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6922 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
);
6923 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6924 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
6925 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6926 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface4
);
6927 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6928 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface3
);
6929 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6930 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface4
);
6931 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6932 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface2
);
6933 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6935 IDirectDrawSurface4_Release(surface4
);
6937 memset(&surface_desc
, 0, sizeof(surface_desc
));
6938 surface_desc
.dwSize
= sizeof(surface_desc
);
6939 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6940 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6941 surface_desc
.dwWidth
= 16;
6942 surface_desc
.dwHeight
= 16;
6943 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6944 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6946 if (SUCCEEDED(hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
)))
6948 skip("Running on refrast, skipping some tests.\n");
6949 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface4
);
6950 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6954 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6955 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
6956 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6957 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface4
);
6958 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6959 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface3
);
6960 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6961 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface4
);
6962 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6963 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface2
);
6964 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6967 IDirectDrawSurface4_Release(surface4
);
6968 IDirectDrawSurface4_Release(surface3
);
6969 IDirectDrawSurface4_Release(surface2
);
6970 IDirectDrawSurface4_Release(surface1
);
6972 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6973 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6975 /* Try a single primary and two offscreen plain surfaces. */
6976 memset(&surface_desc
, 0, sizeof(surface_desc
));
6977 surface_desc
.dwSize
= sizeof(surface_desc
);
6978 surface_desc
.dwFlags
= DDSD_CAPS
;
6979 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6980 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6981 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6983 memset(&surface_desc
, 0, sizeof(surface_desc
));
6984 surface_desc
.dwSize
= sizeof(surface_desc
);
6985 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6986 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6987 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6988 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6989 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
6990 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6992 memset(&surface_desc
, 0, sizeof(surface_desc
));
6993 surface_desc
.dwSize
= sizeof(surface_desc
);
6994 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6995 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6996 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6997 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6998 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6999 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7001 /* This one has a different size. */
7002 memset(&surface_desc
, 0, sizeof(surface_desc
));
7003 surface_desc
.dwSize
= sizeof(surface_desc
);
7004 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7005 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7006 surface_desc
.dwWidth
= 128;
7007 surface_desc
.dwHeight
= 128;
7008 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
7009 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7011 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7012 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7013 /* Try the reverse without detaching first. */
7014 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface1
);
7015 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
7016 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7017 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7019 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface1
);
7020 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7021 /* Try to detach reversed. */
7022 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7023 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7024 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface2
, 0, surface1
);
7025 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7027 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface3
);
7028 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7029 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface2
, 0, surface3
);
7030 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7032 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
);
7033 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7034 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
7035 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7037 IDirectDrawSurface4_Release(surface4
);
7038 IDirectDrawSurface4_Release(surface3
);
7039 IDirectDrawSurface4_Release(surface2
);
7040 IDirectDrawSurface4_Release(surface1
);
7042 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
7043 memset(&surface_desc
, 0, sizeof(surface_desc
));
7044 surface_desc
.dwSize
= sizeof(surface_desc
);
7045 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7046 surface_desc
.dwWidth
= 64;
7047 surface_desc
.dwHeight
= 64;
7048 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
7049 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7050 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
7051 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
7052 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
7053 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
7054 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
7055 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7056 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7057 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
7058 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7060 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
7061 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
7062 U1(U4(surface_desc
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
7063 U3(U4(surface_desc
).ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
7064 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
7065 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7067 hr
= IDirectDrawSurface4_QueryInterface(surface1
, &IID_IDirectDrawSurface
, (void **)&surface1v1
);
7068 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
7069 hr
= IDirectDrawSurface4_QueryInterface(surface2
, &IID_IDirectDrawSurface
, (void **)&surface2v1
);
7070 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
7072 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7073 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7074 refcount
= get_refcount((IUnknown
*)surface2
);
7075 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
7076 refcount
= get_refcount((IUnknown
*)surface2v1
);
7077 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7078 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7079 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
7080 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7081 todo_wine
ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7082 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
7083 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
7085 /* Attaching while already attached to other surface. */
7086 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface2
);
7087 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7088 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface3
, 0, surface2
);
7089 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7090 IDirectDrawSurface4_Release(surface3
);
7092 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7093 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7094 refcount
= get_refcount((IUnknown
*)surface2
);
7095 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7096 refcount
= get_refcount((IUnknown
*)surface2v1
);
7097 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7099 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
7100 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7101 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7102 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7103 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
7104 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
7105 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7106 refcount
= IDirectDrawSurface4_Release(surface2
);
7107 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7108 refcount
= IDirectDrawSurface4_Release(surface1
);
7109 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7111 /* Automatic detachment on release. */
7112 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7113 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7114 refcount
= get_refcount((IUnknown
*)surface2v1
);
7115 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
7116 refcount
= IDirectDrawSurface_Release(surface1v1
);
7117 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7118 refcount
= IDirectDrawSurface_Release(surface2v1
);
7119 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7120 refcount
= IDirectDraw4_Release(ddraw
);
7121 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7122 DestroyWindow(window
);
7125 static void test_private_data(void)
7127 IDirectDraw4
*ddraw
;
7128 IDirectDrawSurface4
*surface
, *surface2
;
7129 DDSURFACEDESC2 surface_desc
;
7130 ULONG refcount
, refcount2
, refcount3
;
7132 DWORD size
= sizeof(ptr
);
7135 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7136 DWORD data
[] = {1, 2, 3, 4};
7138 static const GUID ddraw_private_data_test_guid
=
7143 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
7145 static const GUID ddraw_private_data_test_guid2
=
7150 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
7153 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7154 0, 0, 640, 480, 0, 0, 0, 0);
7155 ddraw
= create_ddraw();
7156 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7157 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7158 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7160 reset_ddsd(&surface_desc
);
7161 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
7162 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
7163 surface_desc
.dwHeight
= 4;
7164 surface_desc
.dwWidth
= 4;
7165 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7166 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7168 /* NULL pointers are not valid, but don't cause a crash. */
7169 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
,
7170 sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
7171 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7172 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 0, 0);
7173 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7174 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 1, 0);
7175 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7177 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
7178 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7179 0, DDSPD_IUNKNOWNPOINTER
);
7180 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7181 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7182 5, DDSPD_IUNKNOWNPOINTER
);
7183 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7184 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7185 sizeof(ddraw
) * 2, DDSPD_IUNKNOWNPOINTER
);
7186 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7188 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
7189 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
7190 * erases the old content and returns an error. This behavior has
7191 * been fixed in d3d8 and d3d9. Unless an application is found
7192 * that depends on this we don't care about this behavior. */
7193 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7194 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7195 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7196 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7197 0, DDSPD_IUNKNOWNPOINTER
);
7198 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7200 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7201 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7202 hr
= IDirectDrawSurface4_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7203 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7205 refcount
= get_refcount((IUnknown
*)ddraw
);
7206 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7207 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7208 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7209 refcount2
= get_refcount((IUnknown
*)ddraw
);
7210 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7212 hr
= IDirectDrawSurface4_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7213 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7214 refcount2
= get_refcount((IUnknown
*)ddraw
);
7215 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7217 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7218 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7219 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7220 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, surface
,
7221 sizeof(surface
), DDSPD_IUNKNOWNPOINTER
);
7222 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7223 refcount2
= get_refcount((IUnknown
*)ddraw
);
7224 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7226 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7227 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7228 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7229 size
= 2 * sizeof(ptr
);
7230 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7231 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7232 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7233 refcount2
= get_refcount(ptr
);
7234 /* Object is NOT addref'ed by the getter. */
7235 ok(ptr
== (IUnknown
*)ddraw
, "Returned interface pointer is %p, expected %p.\n", ptr
, ddraw
);
7236 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7238 ptr
= (IUnknown
*)0xdeadbeef;
7240 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7241 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7242 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7243 size
= 2 * sizeof(ptr
);
7244 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7245 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7246 ok(size
== 2 * sizeof(ptr
), "Got unexpected size %u.\n", size
);
7248 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7249 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7250 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7251 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7252 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, NULL
, NULL
);
7253 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7255 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, &ptr
, &size
);
7256 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7257 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7258 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
7259 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7260 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7262 refcount3
= IDirectDrawSurface4_Release(surface
);
7263 ok(!refcount3
, "Got unexpected refcount %u.\n", refcount3
);
7265 /* Destroying the surface frees the reference held on the private data. It also frees
7266 * the reference the surface is holding on its creating object. */
7267 refcount2
= get_refcount((IUnknown
*)ddraw
);
7268 ok(refcount2
== refcount
- 1, "Got unexpected refcount %u.\n", refcount2
);
7270 memset(&hal_caps
, 0, sizeof(hal_caps
));
7271 hal_caps
.dwSize
= sizeof(hal_caps
);
7272 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7273 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7274 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) == (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7276 reset_ddsd(&surface_desc
);
7277 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_MIPMAPCOUNT
;
7278 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7279 surface_desc
.dwHeight
= 4;
7280 surface_desc
.dwWidth
= 4;
7281 U2(surface_desc
).dwMipMapCount
= 2;
7282 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7283 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7284 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &surface2
);
7285 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7287 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, data
, sizeof(data
), 0);
7288 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7289 hr
= IDirectDrawSurface4_GetPrivateData(surface2
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7290 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7292 IDirectDrawSurface4_Release(surface2
);
7293 IDirectDrawSurface4_Release(surface
);
7296 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7298 refcount
= IDirectDraw4_Release(ddraw
);
7299 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7300 DestroyWindow(window
);
7303 static void test_pixel_format(void)
7305 HWND window
, window2
= NULL
;
7306 HDC hdc
, hdc2
= NULL
;
7308 int format
, test_format
;
7309 PIXELFORMATDESCRIPTOR pfd
;
7310 IDirectDraw4
*ddraw
= NULL
;
7311 IDirectDrawClipper
*clipper
= NULL
;
7312 DDSURFACEDESC2 ddsd
;
7313 IDirectDrawSurface4
*primary
= NULL
;
7317 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7318 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7321 skip("Failed to create window\n");
7325 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7326 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7328 hdc
= GetDC(window
);
7331 skip("Failed to get DC\n");
7336 hdc2
= GetDC(window2
);
7338 gl
= LoadLibraryA("opengl32.dll");
7339 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7341 format
= GetPixelFormat(hdc
);
7342 ok(format
== 0, "new window has pixel format %d\n", format
);
7344 ZeroMemory(&pfd
, sizeof(pfd
));
7345 pfd
.nSize
= sizeof(pfd
);
7347 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
7348 pfd
.iPixelType
= PFD_TYPE_RGBA
;
7349 pfd
.iLayerType
= PFD_MAIN_PLANE
;
7350 format
= ChoosePixelFormat(hdc
, &pfd
);
7353 skip("no pixel format available\n");
7357 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
7359 skip("failed to set pixel format\n");
7363 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
7365 skip("failed to set pixel format on second window\n");
7368 ReleaseDC(window2
, hdc2
);
7373 ddraw
= create_ddraw();
7374 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7376 test_format
= GetPixelFormat(hdc
);
7377 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7379 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7382 skip("Failed to set cooperative level, hr %#x.\n", hr
);
7386 test_format
= GetPixelFormat(hdc
);
7387 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7391 hr
= IDirectDraw4_CreateClipper(ddraw
, 0, &clipper
, NULL
);
7392 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
7393 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
7394 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
7396 test_format
= GetPixelFormat(hdc
);
7397 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7399 test_format
= GetPixelFormat(hdc2
);
7400 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7403 memset(&ddsd
, 0, sizeof(ddsd
));
7404 ddsd
.dwSize
= sizeof(ddsd
);
7405 ddsd
.dwFlags
= DDSD_CAPS
;
7406 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7408 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
7409 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
7411 test_format
= GetPixelFormat(hdc
);
7412 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7416 test_format
= GetPixelFormat(hdc2
);
7417 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7422 hr
= IDirectDrawSurface4_SetClipper(primary
, clipper
);
7423 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
7425 test_format
= GetPixelFormat(hdc
);
7426 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7428 test_format
= GetPixelFormat(hdc2
);
7429 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7432 memset(&fx
, 0, sizeof(fx
));
7433 fx
.dwSize
= sizeof(fx
);
7434 hr
= IDirectDrawSurface4_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7435 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
7437 test_format
= GetPixelFormat(hdc
);
7438 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7442 test_format
= GetPixelFormat(hdc2
);
7443 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7447 if (primary
) IDirectDrawSurface4_Release(primary
);
7448 if (clipper
) IDirectDrawClipper_Release(clipper
);
7449 if (ddraw
) IDirectDraw4_Release(ddraw
);
7450 if (gl
) FreeLibrary(gl
);
7451 if (hdc
) ReleaseDC(window
, hdc
);
7452 if (hdc2
) ReleaseDC(window2
, hdc2
);
7453 if (window
) DestroyWindow(window
);
7454 if (window2
) DestroyWindow(window2
);
7457 static void test_create_surface_pitch(void)
7459 IDirectDrawSurface4
*surface
;
7460 DDSURFACEDESC2 surface_desc
;
7461 IDirectDraw4
*ddraw
;
7481 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7483 DDSD_PITCH
, 0x100, 0x100},
7484 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7485 DDSD_PITCH
, 0x104, DD_OK
,
7486 DDSD_PITCH
, 0x100, 0x100},
7487 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7488 DDSD_PITCH
, 0x0f8, DD_OK
,
7489 DDSD_PITCH
, 0x100, 0x100},
7490 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7491 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7493 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7495 DDSD_PITCH
, 0x100, 0x0fc},
7497 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7498 DDSD_PITCH
, 0x104, DD_OK
,
7499 DDSD_PITCH
, 0x100, 0x0fc},
7500 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7501 DDSD_PITCH
, 0x0f8, DD_OK
,
7502 DDSD_PITCH
, 0x100, 0x0fc},
7503 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7504 DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
7505 DDSD_PITCH
, 0x100, 0x0fc},
7506 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7507 DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
7509 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7510 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7511 DDSD_PITCH
, 0x100, 0x100},
7513 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7514 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fe, DDERR_INVALIDPARAMS
,
7516 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7517 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fc, DD_OK
,
7518 DDSD_PITCH
, 0x0fc, 0x0fc},
7519 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7520 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0f8, DDERR_INVALIDPARAMS
,
7522 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7523 DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x100, DDERR_INVALIDPARAMS
,
7525 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7526 DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x3f00, DDERR_INVALIDPARAMS
,
7529 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7530 DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, 0x100, DD_OK
,
7531 DDSD_PITCH
, 0x100, 0x100},
7532 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
7533 0, 0, DDERR_INVALIDCAPS
,
7535 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7537 DDSD_PITCH
, 0x100, 0 },
7538 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7539 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7541 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
7542 0, 0, DDERR_INVALIDCAPS
,
7545 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7547 DDSD_PITCH
, 0x100, 0 },
7548 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7549 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7550 DDSD_PITCH
, 0x100, 0 },
7552 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
7554 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7555 0, 0, 640, 480, 0, 0, 0, 0);
7556 ddraw
= create_ddraw();
7557 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7558 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7559 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7561 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
7563 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
7565 memset(&surface_desc
, 0, sizeof(surface_desc
));
7566 surface_desc
.dwSize
= sizeof(surface_desc
);
7567 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
7568 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
7569 surface_desc
.dwWidth
= 63;
7570 surface_desc
.dwHeight
= 63;
7571 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
7572 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7573 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7574 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7575 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7576 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7577 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7578 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7579 if (test_data
[i
].flags_in
& DDSD_LPSURFACE
)
7581 HRESULT expected_hr
= SUCCEEDED(test_data
[i
].hr
) ? DDERR_INVALIDPARAMS
: test_data
[i
].hr
;
7582 ok(hr
== expected_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, expected_hr
);
7583 surface_desc
.lpSurface
= mem
;
7584 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7586 if ((test_data
[i
].caps
& DDSCAPS_VIDEOMEMORY
) && hr
== DDERR_NODIRECTDRAWHW
)
7588 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
7592 memset(&surface_desc
, 0, sizeof(surface_desc
));
7593 surface_desc
.dwSize
= sizeof(surface_desc
);
7594 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
7595 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7596 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
7597 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7598 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
7599 /* The pitch for textures seems to be implementation specific. */
7600 if (!(test_data
[i
].caps
& DDSCAPS_TEXTURE
))
7602 if (is_ddraw64
&& test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
7603 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
7604 "Test %u: Got unexpected pitch %u, expected %u.\n",
7605 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
7607 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
7608 "Test %u: Got unexpected pitch %u, expected %u.\n",
7609 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
7611 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
7613 IDirectDrawSurface4_Release(surface
);
7616 HeapFree(GetProcessHeap(), 0, mem
);
7617 refcount
= IDirectDraw4_Release(ddraw
);
7618 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7619 DestroyWindow(window
);
7622 static void test_mipmap(void)
7624 IDirectDrawSurface4
*surface
, *surface2
;
7625 DDSURFACEDESC2 surface_desc
;
7626 IDirectDraw4
*ddraw
;
7631 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7640 DWORD mipmap_count_in
;
7642 DWORD mipmap_count_out
;
7646 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 3, DD_OK
, 3},
7647 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDPARAMS
, 0},
7648 {0, DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 1},
7649 {0, DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDCAPS
, 0},
7650 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 6},
7651 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 32, 64, 0, DD_OK
, 6},
7654 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7655 0, 0, 640, 480, 0, 0, 0, 0);
7656 ddraw
= create_ddraw();
7657 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7658 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7659 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7661 memset(&hal_caps
, 0, sizeof(hal_caps
));
7662 hal_caps
.dwSize
= sizeof(hal_caps
);
7663 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
7664 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7665 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7667 skip("Mipmapped textures not supported, skipping tests.\n");
7668 IDirectDraw4_Release(ddraw
);
7669 DestroyWindow(window
);
7673 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
7675 memset(&surface_desc
, 0, sizeof(surface_desc
));
7676 surface_desc
.dwSize
= sizeof(surface_desc
);
7677 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| tests
[i
].flags
;
7678 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
7679 surface_desc
.dwWidth
= tests
[i
].width
;
7680 surface_desc
.dwHeight
= tests
[i
].height
;
7681 if (tests
[i
].flags
& DDSD_MIPMAPCOUNT
)
7682 U2(surface_desc
).dwMipMapCount
= tests
[i
].mipmap_count_in
;
7683 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7684 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
7688 memset(&surface_desc
, 0, sizeof(surface_desc
));
7689 surface_desc
.dwSize
= sizeof(surface_desc
);
7690 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
7691 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7692 ok(surface_desc
.dwFlags
& DDSD_MIPMAPCOUNT
,
7693 "Test %u: Got unexpected flags %#x.\n", i
, surface_desc
.dwFlags
);
7694 ok(U2(surface_desc
).dwMipMapCount
== tests
[i
].mipmap_count_out
,
7695 "Test %u: Got unexpected mipmap count %u.\n", i
, U2(surface_desc
).dwMipMapCount
);
7697 if (U2(surface_desc
).dwMipMapCount
> 1)
7699 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &surface2
);
7700 ok(SUCCEEDED(hr
), "Test %u: Failed to get attached surface, hr %#x.\n", i
, hr
);
7702 memset(&surface_desc
, 0, sizeof(surface_desc
));
7703 surface_desc
.dwSize
= sizeof(surface_desc
);
7704 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7705 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
7706 memset(&surface_desc
, 0, sizeof(surface_desc
));
7707 surface_desc
.dwSize
= sizeof(surface_desc
);
7708 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
7709 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
7710 IDirectDrawSurface4_Unlock(surface2
, NULL
);
7711 IDirectDrawSurface4_Unlock(surface
, NULL
);
7713 IDirectDrawSurface4_Release(surface2
);
7716 IDirectDrawSurface4_Release(surface
);
7719 refcount
= IDirectDraw4_Release(ddraw
);
7720 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7721 DestroyWindow(window
);
7724 static void test_palette_complex(void)
7726 IDirectDrawSurface4
*surface
, *mipmap
, *tmp
;
7727 DDSURFACEDESC2 surface_desc
;
7728 IDirectDraw4
*ddraw
;
7729 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
7733 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7735 PALETTEENTRY palette_entries
[256];
7741 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7742 0, 0, 640, 480, 0, 0, 0, 0);
7743 ddraw
= create_ddraw();
7744 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7745 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7746 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7748 memset(&hal_caps
, 0, sizeof(hal_caps
));
7749 hal_caps
.dwSize
= sizeof(hal_caps
);
7750 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
7751 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7752 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7754 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7755 IDirectDraw4_Release(ddraw
);
7756 DestroyWindow(window
);
7760 memset(&surface_desc
, 0, sizeof(surface_desc
));
7761 surface_desc
.dwSize
= sizeof(surface_desc
);
7762 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7763 surface_desc
.dwWidth
= 128;
7764 surface_desc
.dwHeight
= 128;
7765 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7766 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7767 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7768 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7769 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7770 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7772 memset(palette_entries
, 0, sizeof(palette_entries
));
7773 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7774 palette_entries
, &palette
, NULL
);
7775 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7777 memset(palette_entries
, 0, sizeof(palette_entries
));
7778 palette_entries
[1].peRed
= 0xff;
7779 palette_entries
[1].peGreen
= 0x80;
7780 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7781 palette_entries
, &palette_mipmap
, NULL
);
7782 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7784 palette2
= (void *)0xdeadbeef;
7785 hr
= IDirectDrawSurface4_GetPalette(surface
, &palette2
);
7786 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
7787 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
7788 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
7789 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7790 hr
= IDirectDrawSurface4_GetPalette(surface
, &palette2
);
7791 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
7792 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
7793 IDirectDrawPalette_Release(palette2
);
7796 IDirectDrawSurface4_AddRef(mipmap
);
7797 for (i
= 0; i
< 7; ++i
)
7799 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7800 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
7801 palette2
= (void *)0xdeadbeef;
7802 hr
= IDirectDrawSurface4_GetPalette(tmp
, &palette2
);
7803 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7804 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
7806 hr
= IDirectDrawSurface4_SetPalette(tmp
, palette_mipmap
);
7807 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
7809 hr
= IDirectDrawSurface4_GetPalette(tmp
, &palette2
);
7810 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
7811 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
7812 IDirectDrawPalette_Release(palette2
);
7814 hr
= IDirectDrawSurface4_GetDC(tmp
, &dc
);
7815 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
7816 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
7817 ok(count
== 1, "Expected count 1, got %u.\n", count
);
7818 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
7819 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
7820 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
7821 hr
= IDirectDrawSurface4_ReleaseDC(tmp
, dc
);
7822 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
7824 IDirectDrawSurface4_Release(mipmap
);
7828 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7829 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7830 IDirectDrawSurface4_Release(mipmap
);
7831 refcount
= IDirectDrawSurface4_Release(surface
);
7832 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7833 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
7834 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7835 refcount
= IDirectDrawPalette_Release(palette
);
7836 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7838 refcount
= IDirectDraw4_Release(ddraw
);
7839 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7840 DestroyWindow(window
);
7843 static void test_p8_rgb_blit(void)
7845 IDirectDrawSurface4
*src
, *dst
;
7846 DDSURFACEDESC2 surface_desc
;
7847 IDirectDraw4
*ddraw
;
7848 IDirectDrawPalette
*palette
;
7852 PALETTEENTRY palette_entries
[256];
7854 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7855 static const D3DCOLOR expected
[] =
7857 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7858 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7862 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7863 0, 0, 640, 480, 0, 0, 0, 0);
7864 ddraw
= create_ddraw();
7865 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7866 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7867 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7869 memset(palette_entries
, 0, sizeof(palette_entries
));
7870 palette_entries
[1].peGreen
= 0xff;
7871 palette_entries
[2].peBlue
= 0xff;
7872 palette_entries
[3].peFlags
= 0xff;
7873 palette_entries
[4].peRed
= 0xff;
7874 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7875 palette_entries
, &palette
, NULL
);
7876 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7878 memset(&surface_desc
, 0, sizeof(surface_desc
));
7879 surface_desc
.dwSize
= sizeof(surface_desc
);
7880 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7881 surface_desc
.dwWidth
= 8;
7882 surface_desc
.dwHeight
= 1;
7883 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7884 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7885 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7886 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7887 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
7888 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7890 memset(&surface_desc
, 0, sizeof(surface_desc
));
7891 surface_desc
.dwSize
= sizeof(surface_desc
);
7892 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7893 surface_desc
.dwWidth
= 8;
7894 surface_desc
.dwHeight
= 1;
7895 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7896 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7897 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
7898 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7899 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7900 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7901 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7902 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
7903 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
7904 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7906 memset(&surface_desc
, 0, sizeof(surface_desc
));
7907 surface_desc
.dwSize
= sizeof(surface_desc
);
7908 hr
= IDirectDrawSurface4_Lock(src
, NULL
, &surface_desc
, 0, NULL
);
7909 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
7910 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
7911 hr
= IDirectDrawSurface4_Unlock(src
, NULL
);
7912 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
7914 hr
= IDirectDrawSurface4_SetPalette(src
, palette
);
7915 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7916 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
7917 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
7918 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
7919 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
7920 "Failed to blit, hr %#x.\n", hr
);
7924 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
7926 color
= get_surface_color(dst
, x
, 0);
7927 todo_wine
ok(compare_color(color
, expected
[x
], 0),
7928 "Pixel %u: Got color %#x, expected %#x.\n",
7929 x
, color
, expected
[x
]);
7933 IDirectDrawSurface4_Release(src
);
7934 IDirectDrawSurface4_Release(dst
);
7935 IDirectDrawPalette_Release(palette
);
7937 refcount
= IDirectDraw4_Release(ddraw
);
7938 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7939 DestroyWindow(window
);
7942 static void test_material(void)
7944 D3DMATERIALHANDLE mat_handle
, tmp
;
7945 IDirect3DMaterial3
*material
;
7946 IDirect3DViewport3
*viewport
;
7947 IDirect3DDevice3
*device
;
7948 IDirectDrawSurface4
*rt
;
7958 struct vec3 position
;
7964 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7965 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7966 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7967 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7971 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7972 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7973 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7974 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7980 D3DCOLOR expected_color
;
7984 {quad1
, TRUE
, 0x0000ff00},
7985 {quad2
, TRUE
, 0x0000ff00},
7986 {quad1
, FALSE
, 0x00ffffff},
7987 {quad2
, FALSE
, 0x00ff0000},
7989 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7991 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7992 0, 0, 640, 480, 0, 0, 0, 0);
7993 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
7995 skip("Failed to create a 3D device, skipping test.\n");
7996 DestroyWindow(window
);
8000 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
8001 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8003 viewport
= create_viewport(device
, 0, 0, 640, 480);
8004 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
8005 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
8007 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
8008 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
8009 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
8011 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
8012 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
8013 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
8014 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
8015 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
8016 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
8017 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
8018 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
8019 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, 0);
8020 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
8021 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
8022 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
8023 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
8025 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
8027 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
,
8028 D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
8029 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8031 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
8032 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
8034 hr
= IDirect3DDevice3_BeginScene(device
);
8035 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8036 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
8037 D3DFVF_XYZ
| D3DFVF_NORMAL
| D3DFVF_DIFFUSE
, test_data
[i
].data
, 4, 0);
8038 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8039 hr
= IDirect3DDevice3_EndScene(device
);
8040 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8041 color
= get_surface_color(rt
, 320, 240);
8042 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
8043 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
8046 destroy_material(material
);
8047 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
8048 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
8049 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
8051 hr
= IDirect3DViewport3_SetBackground(viewport
, mat_handle
);
8052 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
8053 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
8054 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
8055 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
8056 ok(valid
, "Got unexpected valid %#x.\n", valid
);
8057 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8058 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8059 color
= get_surface_color(rt
, 320, 240);
8060 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8062 hr
= IDirect3DViewport3_SetBackground(viewport
, 0);
8063 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8064 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
8065 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
8066 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
8067 ok(valid
, "Got unexpected valid %#x.\n", valid
);
8068 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8069 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8070 color
= get_surface_color(rt
, 320, 240);
8071 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8073 destroy_viewport(device
, viewport
);
8074 viewport
= create_viewport(device
, 0, 0, 640, 480);
8076 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
8077 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
8078 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
8079 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
8080 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8081 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8082 color
= get_surface_color(rt
, 320, 240);
8083 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
8085 destroy_viewport(device
, viewport
);
8086 destroy_material(material
);
8087 IDirectDrawSurface4_Release(rt
);
8088 refcount
= IDirect3DDevice3_Release(device
);
8089 ok(!refcount
, "Device has %u references left.\n", refcount
);
8090 DestroyWindow(window
);
8093 static void test_palette_gdi(void)
8095 IDirectDrawSurface4
*surface
, *primary
;
8096 DDSURFACEDESC2 surface_desc
;
8097 IDirectDraw4
*ddraw
;
8098 IDirectDrawPalette
*palette
, *palette2
;
8102 PALETTEENTRY palette_entries
[256];
8105 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
8106 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
8107 * not the point of this test. */
8108 static const RGBQUAD expected1
[] =
8110 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8111 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
8113 static const RGBQUAD expected2
[] =
8115 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8116 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
8118 static const RGBQUAD expected3
[] =
8120 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
8121 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
8123 HPALETTE ddraw_palette_handle
;
8124 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
8125 RGBQUAD rgbquad
[255];
8126 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
8128 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8129 0, 0, 640, 480, 0, 0, 0, 0);
8130 ddraw
= create_ddraw();
8131 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8132 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8133 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8135 memset(&surface_desc
, 0, sizeof(surface_desc
));
8136 surface_desc
.dwSize
= sizeof(surface_desc
);
8137 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8138 surface_desc
.dwWidth
= 16;
8139 surface_desc
.dwHeight
= 16;
8140 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8141 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8142 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
8143 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
8144 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8145 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8147 /* Avoid colors from the Windows default palette. */
8148 memset(palette_entries
, 0, sizeof(palette_entries
));
8149 palette_entries
[1].peRed
= 0x01;
8150 palette_entries
[2].peGreen
= 0x02;
8151 palette_entries
[3].peBlue
= 0x03;
8152 palette_entries
[4].peRed
= 0x13;
8153 palette_entries
[4].peGreen
= 0x14;
8154 palette_entries
[4].peBlue
= 0x15;
8155 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
8156 palette_entries
, &palette
, NULL
);
8157 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8159 /* If there is no palette assigned and the display mode is not 8 bpp, some
8160 * drivers refuse to create a DC while others allow it. If a DC is created,
8161 * the DIB color table is uninitialized and contains random colors. No error
8162 * is generated when trying to read pixels and random garbage is returned.
8164 * The most likely explanation is that if the driver creates a DC, it (or
8165 * the higher-level runtime) uses GetSystemPaletteEntries to find the
8166 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
8167 * contains uninitialized garbage. See comments below for the P8 case. */
8169 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8170 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8171 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8172 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8173 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
8174 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
8175 "Got unexpected palette %p, expected %p.\n",
8176 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
8178 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8179 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8180 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
8182 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
8183 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8184 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8185 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
8187 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8189 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8190 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8191 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8194 /* Update the palette while the DC is in use. This does not modify the DC. */
8195 palette_entries
[4].peRed
= 0x23;
8196 palette_entries
[4].peGreen
= 0x24;
8197 palette_entries
[4].peBlue
= 0x25;
8198 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
8199 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
8201 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
8202 ok(i
== 1, "Expected count 1, got %u.\n", i
);
8203 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
8204 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8205 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
8206 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
8208 /* Neither does re-setting the palette. */
8209 hr
= IDirectDrawSurface4_SetPalette(surface
, NULL
);
8210 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8211 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8212 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8214 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
8215 ok(i
== 1, "Expected count 1, got %u.\n", i
);
8216 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
8217 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8218 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
8219 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
8221 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8222 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8224 /* Refresh the DC. This updates the palette. */
8225 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8226 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8227 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8228 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8229 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8231 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8232 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8233 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8234 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8236 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8238 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8239 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8240 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8242 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8243 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8245 refcount
= IDirectDrawSurface4_Release(surface
);
8246 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8248 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8250 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8251 IDirectDrawPalette_Release(palette
);
8252 IDirectDraw4_Release(ddraw
);
8253 DestroyWindow(window
);
8256 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
8257 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
8258 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8260 memset(&surface_desc
, 0, sizeof(surface_desc
));
8261 surface_desc
.dwSize
= sizeof(surface_desc
);
8262 surface_desc
.dwFlags
= DDSD_CAPS
;
8263 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8264 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
8265 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8267 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
8268 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8269 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
8270 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8271 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
8272 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
8273 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
8274 "Got unexpected palette %p, expected %p.\n",
8275 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
8276 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
8278 /* The primary uses the system palette. In exclusive mode, the system palette matches
8279 * the ddraw palette attached to the primary, so the result is what you would expect
8280 * from a regular surface. Tests for the interaction between the ddraw palette and
8281 * the system palette are not included pending an application that depends on this.
8282 * The relation between those causes problems on Windows Vista and newer for games
8283 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
8284 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8285 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8286 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8288 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8289 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8290 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8291 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8293 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8295 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8296 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8297 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8299 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
8300 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8302 memset(&surface_desc
, 0, sizeof(surface_desc
));
8303 surface_desc
.dwSize
= sizeof(surface_desc
);
8304 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8305 surface_desc
.dwWidth
= 16;
8306 surface_desc
.dwHeight
= 16;
8307 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8308 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8309 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8311 /* Here the offscreen surface appears to use the primary's palette,
8312 * but in all likelihood it is actually the system palette. */
8313 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8314 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8315 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8316 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8317 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8319 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8320 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8321 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8322 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8324 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8326 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8327 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8328 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8330 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8331 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8333 /* On real hardware a change to the primary surface's palette applies immediately,
8334 * even on device contexts from offscreen surfaces that do not have their own
8335 * palette. On the testbot VMs this is not the case. Don't test this until we
8336 * know of an application that depends on this. */
8338 memset(palette_entries
, 0, sizeof(palette_entries
));
8339 palette_entries
[1].peBlue
= 0x40;
8340 palette_entries
[2].peRed
= 0x40;
8341 palette_entries
[3].peGreen
= 0x40;
8342 palette_entries
[4].peRed
= 0x12;
8343 palette_entries
[4].peGreen
= 0x34;
8344 palette_entries
[4].peBlue
= 0x56;
8345 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
8346 palette_entries
, &palette2
, NULL
);
8347 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8348 hr
= IDirectDrawSurface4_SetPalette(surface
, palette2
);
8349 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8351 /* A palette assigned to the offscreen surface overrides the primary / system
8353 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8354 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8355 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8356 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8357 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
8359 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
8360 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8361 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8362 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
8364 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8366 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8367 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8368 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8370 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8371 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8373 refcount
= IDirectDrawSurface4_Release(surface
);
8374 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8376 /* The Windows 8 testbot keeps extra references to the primary and
8377 * backbuffer while in 8 bpp mode. */
8378 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
8379 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8381 refcount
= IDirectDrawSurface4_Release(primary
);
8382 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8383 refcount
= IDirectDrawPalette_Release(palette2
);
8384 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8385 refcount
= IDirectDrawPalette_Release(palette
);
8386 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8387 refcount
= IDirectDraw4_Release(ddraw
);
8388 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8389 DestroyWindow(window
);
8392 static void test_palette_alpha(void)
8394 IDirectDrawSurface4
*surface
;
8395 DDSURFACEDESC2 surface_desc
;
8396 IDirectDraw4
*ddraw
;
8397 IDirectDrawPalette
*palette
;
8401 PALETTEENTRY palette_entries
[256];
8406 BOOL attach_allowed
;
8411 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
8412 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
8413 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
8416 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8417 0, 0, 640, 480, 0, 0, 0, 0);
8418 ddraw
= create_ddraw();
8419 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8420 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8422 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8423 IDirectDraw4_Release(ddraw
);
8424 DestroyWindow(window
);
8427 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8428 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8430 memset(palette_entries
, 0, sizeof(palette_entries
));
8431 palette_entries
[1].peFlags
= 0x42;
8432 palette_entries
[2].peFlags
= 0xff;
8433 palette_entries
[3].peFlags
= 0x80;
8434 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
8435 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8437 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8438 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8439 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8440 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8441 palette_entries
[0].peFlags
);
8442 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8443 palette_entries
[1].peFlags
);
8444 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8445 palette_entries
[2].peFlags
);
8446 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8447 palette_entries
[3].peFlags
);
8449 IDirectDrawPalette_Release(palette
);
8451 memset(palette_entries
, 0, sizeof(palette_entries
));
8452 palette_entries
[1].peFlags
= 0x42;
8453 palette_entries
[1].peRed
= 0xff;
8454 palette_entries
[2].peFlags
= 0xff;
8455 palette_entries
[3].peFlags
= 0x80;
8456 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
8457 palette_entries
, &palette
, NULL
);
8458 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8460 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8461 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8462 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8463 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8464 palette_entries
[0].peFlags
);
8465 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8466 palette_entries
[1].peFlags
);
8467 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8468 palette_entries
[2].peFlags
);
8469 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8470 palette_entries
[3].peFlags
);
8472 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
8474 memset(&surface_desc
, 0, sizeof(surface_desc
));
8475 surface_desc
.dwSize
= sizeof(surface_desc
);
8476 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
8477 surface_desc
.dwWidth
= 128;
8478 surface_desc
.dwHeight
= 128;
8479 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
8480 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8481 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8483 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8484 if (test_data
[i
].attach_allowed
)
8485 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8487 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8495 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8496 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8497 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
8498 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
8499 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8500 rgbquad
.rgbRed
, test_data
[i
].name
);
8501 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8502 rgbquad
.rgbGreen
, test_data
[i
].name
);
8503 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8504 rgbquad
.rgbBlue
, test_data
[i
].name
);
8505 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8506 rgbquad
.rgbReserved
, test_data
[i
].name
);
8507 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8508 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8510 IDirectDrawSurface4_Release(surface
);
8513 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8514 memset(&surface_desc
, 0, sizeof(surface_desc
));
8515 surface_desc
.dwSize
= sizeof(surface_desc
);
8516 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8517 surface_desc
.dwWidth
= 128;
8518 surface_desc
.dwHeight
= 128;
8519 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8520 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8521 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8522 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
8523 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8524 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8525 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8526 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8527 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8528 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8529 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
8530 IDirectDrawSurface4_Release(surface
);
8532 /* The Windows 8 testbot keeps extra references to the primary
8533 * while in 8 bpp mode. */
8534 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
8535 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8537 refcount
= IDirectDrawPalette_Release(palette
);
8538 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8539 refcount
= IDirectDraw4_Release(ddraw
);
8540 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8541 DestroyWindow(window
);
8544 static void test_vb_writeonly(void)
8546 IDirect3DDevice3
*device
;
8548 IDirect3DVertexBuffer
*buffer
;
8551 D3DVERTEXBUFFERDESC desc
;
8553 static const struct vec4 quad
[] =
8555 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
8556 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
8557 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
8558 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
8561 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8562 0, 0, 640, 480, 0, 0, 0, 0);
8564 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8566 skip("Failed to create a 3D device, skipping test.\n");
8567 DestroyWindow(window
);
8571 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
8572 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
8574 memset(&desc
, 0, sizeof(desc
));
8575 desc
.dwSize
= sizeof(desc
);
8576 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
8577 desc
.dwFVF
= D3DFVF_XYZRHW
;
8578 desc
.dwNumVertices
= sizeof(quad
) / sizeof(*quad
);
8579 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0, NULL
);
8580 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
8582 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, &ptr
, NULL
);
8583 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8584 memcpy(ptr
, quad
, sizeof(quad
));
8585 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8586 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8588 hr
= IDirect3DDevice3_BeginScene(device
);
8589 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8590 hr
= IDirect3DDevice3_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
8591 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8592 hr
= IDirect3DDevice3_EndScene(device
);
8593 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8595 hr
= IDirect3DVertexBuffer_Lock(buffer
, 0, &ptr
, NULL
);
8596 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8597 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8598 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8599 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8601 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_READONLY
, &ptr
, NULL
);
8602 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8603 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8604 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8605 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8607 IDirect3DVertexBuffer_Release(buffer
);
8608 IDirect3D3_Release(d3d
);
8609 IDirect3DDevice3_Release(device
);
8610 DestroyWindow(window
);
8613 static void test_lost_device(void)
8615 IDirectDrawSurface4
*surface
;
8616 DDSURFACEDESC2 surface_desc
;
8617 HWND window1
, window2
;
8618 IDirectDraw4
*ddraw
;
8623 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8624 0, 0, 640, 480, 0, 0, 0, 0);
8625 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8626 0, 0, 640, 480, 0, 0, 0, 0);
8627 ddraw
= create_ddraw();
8628 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8629 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8630 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8632 memset(&surface_desc
, 0, sizeof(surface_desc
));
8633 surface_desc
.dwSize
= sizeof(surface_desc
);
8634 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8635 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8636 U5(surface_desc
).dwBackBufferCount
= 1;
8637 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8638 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8640 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8641 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8642 hr
= IDirectDrawSurface4_IsLost(surface
);
8643 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8644 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8645 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8647 ret
= SetForegroundWindow(GetDesktopWindow());
8648 ok(ret
, "Failed to set foreground window.\n");
8649 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8650 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8651 hr
= IDirectDrawSurface4_IsLost(surface
);
8652 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8653 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8654 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8656 ret
= SetForegroundWindow(window1
);
8657 ok(ret
, "Failed to set foreground window.\n");
8658 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8659 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8660 hr
= IDirectDrawSurface4_IsLost(surface
);
8661 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8662 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8663 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8665 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
8666 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8667 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8668 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8669 hr
= IDirectDrawSurface4_IsLost(surface
);
8670 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8671 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8672 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8674 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8675 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8676 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8677 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8678 hr
= IDirectDrawSurface4_IsLost(surface
);
8679 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8680 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8681 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8683 /* Trying to restore the primary will crash, probably because flippable
8684 * surfaces can't exist in DDSCL_NORMAL. */
8685 IDirectDrawSurface4_Release(surface
);
8686 memset(&surface_desc
, 0, sizeof(surface_desc
));
8687 surface_desc
.dwSize
= sizeof(surface_desc
);
8688 surface_desc
.dwFlags
= DDSD_CAPS
;
8689 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8690 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8691 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8693 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8694 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8695 hr
= IDirectDrawSurface4_IsLost(surface
);
8696 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8698 ret
= SetForegroundWindow(GetDesktopWindow());
8699 ok(ret
, "Failed to set foreground window.\n");
8700 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8701 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8702 hr
= IDirectDrawSurface4_IsLost(surface
);
8703 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8705 ret
= SetForegroundWindow(window1
);
8706 ok(ret
, "Failed to set foreground window.\n");
8707 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8708 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8709 hr
= IDirectDrawSurface4_IsLost(surface
);
8710 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8712 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8713 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8714 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8715 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8716 hr
= IDirectDrawSurface4_IsLost(surface
);
8717 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8719 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
8720 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8721 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8722 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8723 hr
= IDirectDrawSurface4_IsLost(surface
);
8724 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8726 IDirectDrawSurface4_Release(surface
);
8727 memset(&surface_desc
, 0, sizeof(surface_desc
));
8728 surface_desc
.dwSize
= sizeof(surface_desc
);
8729 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8730 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8731 U5(surface_desc
).dwBackBufferCount
= 1;
8732 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8733 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8735 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8736 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8737 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8738 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8739 hr
= IDirectDrawSurface4_IsLost(surface
);
8740 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8741 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8742 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8744 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8745 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8746 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8747 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8748 hr
= IDirectDrawSurface4_IsLost(surface
);
8749 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8750 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8751 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8753 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8754 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8755 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8756 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8757 hr
= IDirectDrawSurface4_IsLost(surface
);
8758 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8759 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8760 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8762 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
8763 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8764 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8765 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8766 hr
= IDirectDrawSurface4_IsLost(surface
);
8767 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8768 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8769 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8771 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8772 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8773 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8774 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8775 hr
= IDirectDrawSurface4_IsLost(surface
);
8776 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8777 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8778 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8780 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8781 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8782 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8783 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8784 hr
= IDirectDrawSurface4_IsLost(surface
);
8785 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8786 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8787 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8789 IDirectDrawSurface4_Release(surface
);
8790 refcount
= IDirectDraw4_Release(ddraw
);
8791 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8792 DestroyWindow(window2
);
8793 DestroyWindow(window1
);
8796 static void test_surface_desc_lock(void)
8798 IDirectDrawSurface4
*surface
;
8799 DDSURFACEDESC2 surface_desc
;
8800 IDirectDraw4
*ddraw
;
8805 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8806 0, 0, 640, 480, 0, 0, 0, 0);
8807 ddraw
= create_ddraw();
8808 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8809 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8810 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8812 memset(&surface_desc
, 0, sizeof(surface_desc
));
8813 surface_desc
.dwSize
= sizeof(surface_desc
);
8814 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8815 surface_desc
.dwWidth
= 16;
8816 surface_desc
.dwHeight
= 16;
8817 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8818 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8819 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8821 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8822 surface_desc
.dwSize
= sizeof(surface_desc
);
8823 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8824 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8825 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8827 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8828 surface_desc
.dwSize
= sizeof(surface_desc
);
8829 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
8830 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8831 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8832 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8833 surface_desc
.dwSize
= sizeof(surface_desc
);
8834 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8835 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8836 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8837 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
8838 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8840 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8841 surface_desc
.dwSize
= sizeof(surface_desc
);
8842 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8843 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8844 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8846 IDirectDrawSurface4_Release(surface
);
8847 refcount
= IDirectDraw4_Release(ddraw
);
8848 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8849 DestroyWindow(window
);
8852 static void test_signed_formats(void)
8855 IDirect3DDevice3
*device
;
8857 IDirectDraw4
*ddraw
;
8858 IDirectDrawSurface4
*surface
, *rt
;
8859 IDirect3DTexture2
*texture
;
8860 IDirect3DViewport3
*viewport
;
8861 DDSURFACEDESC2 surface_desc
;
8864 D3DCOLOR color
, expected_color
;
8868 struct vec3 position
;
8869 struct vec2 texcoord
;
8873 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
8874 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
8875 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
8876 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
8878 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
8879 * of these values. */
8880 static const USHORT content_v8u8
[4][4] =
8882 {0x0000, 0x7f7f, 0x8880, 0x0000},
8883 {0x0080, 0x8000, 0x7f00, 0x007f},
8884 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
8885 {0x4444, 0xc0c0, 0xa066, 0x22e0},
8887 static const DWORD content_x8l8v8u8
[4][4] =
8889 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
8890 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
8891 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
8892 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
8894 static const USHORT content_l6v5u5
[4][4] =
8896 {0x0000, 0xfdef, 0x0230, 0xfc00},
8897 {0x0010, 0x0200, 0x01e0, 0x000f},
8898 {0x4067, 0x53b9, 0x0421, 0xffff},
8899 {0x8108, 0x0318, 0xc28c, 0x909c},
8904 const void *content
;
8907 unsigned int slop
, slop_broken
;
8908 DDPIXELFORMAT format
;
8913 "D3DFMT_V8U8", content_v8u8
, sizeof(WORD
), FALSE
, 1, 0,
8915 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
, 0,
8916 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
8920 "D3DFMT_X8L8V8U8", content_x8l8v8u8
, sizeof(DWORD
), TRUE
, 1, 0,
8922 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
8923 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
8927 "D3DFMT_L6V5U5", content_l6v5u5
, sizeof(WORD
), TRUE
, 4, 7,
8929 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
8930 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
8934 /* No V16U16 or Q8W8V8U8 support in ddraw. */
8936 static const D3DCOLOR expected_colors
[4][4] =
8938 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
8939 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
8940 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
8941 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
8943 unsigned int i
, width
, x
, y
;
8944 D3DDEVICEDESC device_desc
, hel_desc
;
8946 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8947 0, 0, 640, 480, 0, 0, 0, 0);
8949 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8951 skip("Failed to create a 3D device, skipping test.\n");
8952 DestroyWindow(window
);
8956 memset(&device_desc
, 0, sizeof(device_desc
));
8957 device_desc
.dwSize
= sizeof(device_desc
);
8958 memset(&hel_desc
, 0, sizeof(hel_desc
));
8959 hel_desc
.dwSize
= sizeof(hel_desc
);
8960 hr
= IDirect3DDevice3_GetCaps(device
, &device_desc
, &hel_desc
);
8961 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8962 if (!(device_desc
.dwTextureOpCaps
& D3DTEXOPCAPS_BLENDFACTORALPHA
))
8964 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
8968 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
8969 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
8970 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
8971 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
8972 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
8973 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8975 memset(&surface_desc
, 0, sizeof(surface_desc
));
8976 surface_desc
.dwSize
= sizeof(surface_desc
);
8977 hr
= IDirectDrawSurface4_GetSurfaceDesc(rt
, &surface_desc
);
8978 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8979 viewport
= create_viewport(device
, 0, 0, surface_desc
.dwWidth
, surface_desc
.dwHeight
);
8980 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
8981 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
8982 U1(clear_rect
).x1
= 0;
8983 U2(clear_rect
).y1
= 0;
8984 U3(clear_rect
).x2
= surface_desc
.dwWidth
;
8985 U4(clear_rect
).y2
= surface_desc
.dwHeight
;
8987 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8988 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8990 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
8991 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x80ffffff);
8992 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8993 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BLENDFACTORALPHA
);
8994 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
8995 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
8996 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
8997 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
8998 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9000 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
9002 for (width
= 1; width
< 5; width
+= 3)
9004 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
9005 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
9007 memset(&surface_desc
, 0, sizeof(surface_desc
));
9008 surface_desc
.dwSize
= sizeof(surface_desc
);
9009 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
9010 surface_desc
.dwWidth
= width
;
9011 surface_desc
.dwHeight
= 4;
9012 U4(surface_desc
).ddpfPixelFormat
= formats
[i
].format
;
9013 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
9014 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9017 skip("%s textures not supported, skipping.\n", formats
[i
].name
);
9020 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9022 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
9023 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture2 interface, hr %#x, format %s.\n",
9024 hr
, formats
[i
].name
);
9025 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
9026 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9027 IDirect3DTexture2_Release(texture
);
9029 memset(&surface_desc
, 0, sizeof(surface_desc
));
9030 surface_desc
.dwSize
= sizeof(surface_desc
);
9031 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
9032 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9033 for (y
= 0; y
< 4; y
++)
9035 memcpy((char *)surface_desc
.lpSurface
+ y
* U1(surface_desc
).lPitch
,
9036 (char *)formats
[i
].content
+ y
* 4 * formats
[i
].pixel_size
,
9037 width
* formats
[i
].pixel_size
);
9039 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9040 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9042 hr
= IDirect3DDevice3_BeginScene(device
);
9043 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9044 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
9045 D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
9046 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9047 hr
= IDirect3DDevice3_EndScene(device
);
9048 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9050 for (y
= 0; y
< 4; y
++)
9052 for (x
= 0; x
< width
; x
++)
9054 expected_color
= expected_colors
[y
][x
];
9055 if (!formats
[i
].blue
)
9056 expected_color
|= 0x000000ff;
9058 color
= get_surface_color(rt
, 80 + 160 * x
, 60 + 120 * y
);
9059 ok(compare_color(color
, expected_color
, formats
[i
].slop
)
9060 || broken(compare_color(color
, expected_color
, formats
[i
].slop_broken
)),
9061 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9062 expected_color
, color
, formats
[i
].name
, x
, y
);
9066 IDirectDrawSurface4_Release(surface
);
9070 destroy_viewport(device
, viewport
);
9071 IDirectDrawSurface4_Release(rt
);
9072 IDirectDraw4_Release(ddraw
);
9073 IDirect3D3_Release(d3d
);
9076 refcount
= IDirect3DDevice3_Release(device
);
9077 ok(!refcount
, "Device has %u references left.\n", refcount
);
9078 DestroyWindow(window
);
9081 static void test_color_fill(void)
9084 IDirect3DDevice3
*device
;
9086 IDirectDraw4
*ddraw
;
9087 IDirectDrawSurface4
*surface
, *surface2
;
9088 DDSURFACEDESC2 surface_desc
;
9089 DDPIXELFORMAT z_fmt
;
9094 RECT rect
= {5, 5, 7, 7};
9096 DWORD supported_fmts
= 0, num_fourcc_codes
, *fourcc_codes
;
9101 HRESULT colorfill_hr
, depthfill_hr
;
9106 DDPIXELFORMAT format
;
9111 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9112 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9114 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9115 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9119 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9120 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9122 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9123 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9127 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9128 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
9130 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9131 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9135 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9136 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
9138 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9139 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9143 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
9144 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "managed texture RGB", 0xdeadbeef, TRUE
,
9146 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9147 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9151 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
, 0,
9152 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
9153 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9156 DDSCAPS_ZBUFFER
| DDSCAPS_SYSTEMMEMORY
, 0,
9157 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "sysmem zbuffer", 0, FALSE
,
9158 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9161 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9162 * different afterwards. DX9+ GPUs set one of the two luminance values
9163 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9164 * value they set. r200 (dx8) just sets the entire block to the clear
9166 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9167 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
9169 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9170 {0}, {0}, {0}, {0}, {0}
9174 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9175 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
9177 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9178 {0}, {0}, {0}, {0}, {0}
9182 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9183 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
9185 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9186 {0}, {0}, {0}, {0}, {0}
9190 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9191 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
9193 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9194 {0}, {0}, {0}, {0}, {0}
9198 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9199 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
9201 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9202 {0}, {0}, {0}, {0}, {0}
9206 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9207 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
9209 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9210 {0}, {0}, {0}, {0}, {0}
9214 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9215 * surface works, presumably because it is handled by the runtime instead of
9217 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9218 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
9220 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9221 {8}, {0}, {0}, {0}, {0}
9225 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9226 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
9228 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9229 {8}, {0}, {0}, {0}, {0}
9241 {SRCCOPY
, "SRCCOPY", DD_OK
},
9242 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
9243 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
9244 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
9245 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
9246 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
9247 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
9248 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
9249 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
9250 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
9251 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
9252 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
9253 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
9254 {BLACKNESS
, "BLACKNESS", DD_OK
},
9255 {WHITENESS
, "WHITENESS", DD_OK
},
9256 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
9259 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9260 0, 0, 640, 480, 0, 0, 0, 0);
9262 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9264 skip("Failed to create a 3D device, skipping test.\n");
9265 DestroyWindow(window
);
9269 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9270 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9271 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9272 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9274 memset(&z_fmt
, 0, sizeof(z_fmt
));
9275 IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
9277 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9279 IDirect3DDevice3_EnumTextureFormats(device
, test_block_formats_creation_cb
, &supported_fmts
);
9280 if (!(supported_fmts
& SUPPORT_DXT1
))
9281 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9283 IDirect3D3_Release(d3d
);
9285 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
9286 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9287 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
9288 num_fourcc_codes
* sizeof(*fourcc_codes
));
9291 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
9292 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9293 for (i
= 0; i
< num_fourcc_codes
; i
++)
9295 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9296 supported_fmts
|= SUPPORT_YUY2
;
9297 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9298 supported_fmts
|= SUPPORT_UYVY
;
9300 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
9302 memset(&hal_caps
, 0, sizeof(hal_caps
));
9303 hal_caps
.dwSize
= sizeof(hal_caps
);
9304 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
9305 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9307 if (!(supported_fmts
& (SUPPORT_YUY2
| SUPPORT_UYVY
)) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9308 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9310 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
9312 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9313 memset(&fx
, 0, sizeof(fx
));
9314 fx
.dwSize
= sizeof(fx
);
9315 U5(fx
).dwFillColor
= 0xdeadbeef;
9317 memset(&surface_desc
, 0, sizeof(surface_desc
));
9318 surface_desc
.dwSize
= sizeof(surface_desc
);
9319 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9320 surface_desc
.dwWidth
= 64;
9321 surface_desc
.dwHeight
= 64;
9322 U4(surface_desc
).ddpfPixelFormat
= tests
[i
].format
;
9323 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
9324 surface_desc
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
9326 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('D','X','T','1') && !(supported_fmts
& SUPPORT_DXT1
))
9328 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !(supported_fmts
& SUPPORT_YUY2
))
9330 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !(supported_fmts
& SUPPORT_UYVY
))
9332 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9335 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
9340 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9343 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9344 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9346 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9347 todo_wine_if (tests
[i
].format
.dwFourCC
)
9348 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9349 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9351 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9352 todo_wine_if (tests
[i
].format
.dwFourCC
)
9353 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9354 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9356 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9358 memset(&surface_desc
, 0, sizeof(surface_desc
));
9359 surface_desc
.dwSize
= sizeof(surface_desc
);
9360 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9361 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9362 color
= surface_desc
.lpSurface
;
9363 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9364 *color
, tests
[i
].result
, tests
[i
].name
);
9365 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9366 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9369 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9370 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9371 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9372 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9373 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9374 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9376 U5(fx
).dwFillColor
= 0xdeadbeef;
9377 fx
.dwROP
= BLACKNESS
;
9378 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9379 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9380 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9381 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9382 U5(fx
).dwFillColor
, tests
[i
].name
);
9384 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9386 memset(&surface_desc
, 0, sizeof(surface_desc
));
9387 surface_desc
.dwSize
= sizeof(surface_desc
);
9388 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9389 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9390 color
= surface_desc
.lpSurface
;
9391 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9392 *color
, tests
[i
].name
);
9393 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9394 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9397 fx
.dwROP
= WHITENESS
;
9398 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9399 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9400 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9401 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9402 U5(fx
).dwFillColor
, tests
[i
].name
);
9404 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9406 memset(&surface_desc
, 0, sizeof(surface_desc
));
9407 surface_desc
.dwSize
= sizeof(surface_desc
);
9408 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9409 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9410 color
= surface_desc
.lpSurface
;
9411 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9412 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9413 *color
, tests
[i
].name
);
9414 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9415 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9418 IDirectDrawSurface4_Release(surface
);
9421 memset(&fx
, 0, sizeof(fx
));
9422 fx
.dwSize
= sizeof(fx
);
9423 U5(fx
).dwFillColor
= 0xdeadbeef;
9424 fx
.dwROP
= WHITENESS
;
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
.dwWidth
= 64;
9430 surface_desc
.dwHeight
= 64;
9431 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9432 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9433 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9434 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9435 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9436 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9437 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
9438 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9439 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9440 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9441 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9444 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
9445 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9446 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
9447 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9449 /* Unused source rectangle. */
9450 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9451 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9452 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9453 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9455 /* Unused source surface. */
9456 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9457 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9458 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9459 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9460 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9461 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9462 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9463 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9465 /* Inverted destination or source rectangle. */
9466 SetRect(&rect
, 5, 7, 7, 5);
9467 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9468 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9469 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9470 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9471 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9472 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9473 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9474 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9475 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9476 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9478 /* Negative rectangle. */
9479 SetRect(&rect
, -1, -1, 5, 5);
9480 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9481 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9482 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9483 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9484 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9485 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9486 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9487 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9488 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9489 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9491 /* Out of bounds rectangle. */
9492 SetRect(&rect
, 0, 0, 65, 65);
9493 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9494 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9495 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9496 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9498 /* Combine multiple flags. */
9499 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9500 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9501 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9502 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9503 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9504 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9506 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
9508 fx
.dwROP
= rops
[i
].rop
;
9509 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9510 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
9513 IDirectDrawSurface4_Release(surface2
);
9514 IDirectDrawSurface4_Release(surface
);
9519 memset(&surface_desc
, 0, sizeof(surface_desc
));
9520 surface_desc
.dwSize
= sizeof(surface_desc
);
9521 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9522 surface_desc
.dwWidth
= 64;
9523 surface_desc
.dwHeight
= 64;
9524 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9525 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
9526 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9527 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9528 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9529 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9532 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
9533 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9535 /* Unused source rectangle. */
9536 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9537 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9539 /* Unused source surface. */
9540 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9541 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9542 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9543 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9545 /* Inverted destination or source rectangle. */
9546 SetRect(&rect
, 5, 7, 7, 5);
9547 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9548 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9549 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9550 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9551 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9552 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9553 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9554 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9556 /* Negative rectangle. */
9557 SetRect(&rect
, -1, -1, 5, 5);
9558 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9559 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9560 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9561 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9562 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9563 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9564 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9565 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9567 /* Out of bounds rectangle. */
9568 SetRect(&rect
, 0, 0, 65, 65);
9569 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9570 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9572 /* Combine multiple flags. */
9573 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9574 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9576 IDirectDrawSurface4_Release(surface2
);
9577 IDirectDrawSurface4_Release(surface
);
9580 IDirectDraw4_Release(ddraw
);
9581 refcount
= IDirect3DDevice3_Release(device
);
9582 ok(!refcount
, "Device has %u references left.\n", refcount
);
9583 DestroyWindow(window
);
9586 static void test_texcoordindex(void)
9591 struct vec2 texcoord1
;
9592 struct vec2 texcoord2
;
9593 struct vec2 texcoord3
;
9597 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}, {0.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9598 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}, {0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
9599 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9600 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 0.0f
}},
9602 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_TEX3
;
9603 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9604 IDirect3DDevice3
*device
;
9606 IDirectDraw4
*ddraw
;
9607 IDirectDrawSurface4
*rt
;
9608 IDirect3DViewport3
*viewport
;
9611 IDirectDrawSurface4
*surface1
, *surface2
;
9612 IDirect3DTexture2
*texture1
, *texture2
;
9613 DDSURFACEDESC2 surface_desc
;
9618 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9619 0, 0, 640, 480, 0, 0, 0, 0);
9620 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9622 skip("Failed to create a 3D device, skipping test.\n");
9623 DestroyWindow(window
);
9627 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9628 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
9629 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9630 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
9631 IDirect3D3_Release(d3d
);
9633 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
9634 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9636 memset(&surface_desc
, 0, sizeof(surface_desc
));
9637 surface_desc
.dwSize
= sizeof(surface_desc
);
9638 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9639 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9640 surface_desc
.dwWidth
= 2;
9641 surface_desc
.dwHeight
= 2;
9642 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9643 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
9644 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9645 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9646 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9647 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9648 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
9649 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
9650 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9651 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9652 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9654 memset(&surface_desc
, 0, sizeof(surface_desc
));
9655 surface_desc
.dwSize
= sizeof(surface_desc
);
9656 hr
= IDirectDrawSurface4_Lock(surface1
, 0, &surface_desc
, 0, NULL
);
9657 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9658 ptr
= surface_desc
.lpSurface
;
9659 ptr
[0] = 0xff000000;
9660 ptr
[1] = 0xff00ff00;
9661 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9662 ptr
[0] = 0xff0000ff;
9663 ptr
[1] = 0xff00ffff;
9664 hr
= IDirectDrawSurface4_Unlock(surface1
, NULL
);
9665 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9667 memset(&surface_desc
, 0, sizeof(surface_desc
));
9668 surface_desc
.dwSize
= sizeof(surface_desc
);
9669 hr
= IDirectDrawSurface4_Lock(surface2
, 0, &surface_desc
, 0, NULL
);
9670 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9671 ptr
= surface_desc
.lpSurface
;
9672 ptr
[0] = 0xff000000;
9673 ptr
[1] = 0xff0000ff;
9674 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9675 ptr
[0] = 0xffff0000;
9676 ptr
[1] = 0xffff00ff;
9677 hr
= IDirectDrawSurface4_Unlock(surface2
, 0);
9678 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9680 viewport
= create_viewport(device
, 0, 0, 640, 480);
9681 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
9682 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
9684 hr
= IDirectDrawSurface4_QueryInterface(surface1
, &IID_IDirect3DTexture2
, (void **)&texture1
);
9685 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9686 hr
= IDirectDrawSurface4_QueryInterface(surface2
, &IID_IDirect3DTexture2
, (void **)&texture2
);
9687 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9688 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture1
);
9689 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9690 hr
= IDirect3DDevice3_SetTexture(device
, 1, texture2
);
9691 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9692 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9693 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9694 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
9695 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9696 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9697 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9698 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_ADD
);
9699 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9700 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9701 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9702 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
9703 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9704 hr
= IDirect3DDevice3_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
9705 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9707 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_TEXCOORDINDEX
, 1);
9708 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9709 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 0);
9710 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9712 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
9713 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9715 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9716 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9718 hr
= IDirect3DDevice3_BeginScene(device
);
9719 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9720 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9721 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9722 hr
= IDirect3DDevice3_EndScene(device
);
9723 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9725 color
= get_surface_color(rt
, 160, 120);
9726 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9727 color
= get_surface_color(rt
, 480, 120);
9728 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9729 color
= get_surface_color(rt
, 160, 360);
9730 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
9731 color
= get_surface_color(rt
, 480, 360);
9732 ok(compare_color(color
, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color
);
9734 /* D3DTSS_TEXTURETRANSFORMFLAGS was introduced in D3D7, can't test it here. */
9736 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 2);
9737 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9739 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9740 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9742 hr
= IDirect3DDevice3_BeginScene(device
);
9743 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9744 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9745 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9746 hr
= IDirect3DDevice3_EndScene(device
);
9747 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9749 color
= get_surface_color(rt
, 160, 120);
9750 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9751 color
= get_surface_color(rt
, 480, 120);
9752 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9753 color
= get_surface_color(rt
, 160, 360);
9754 ok(compare_color(color
, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color
);
9755 color
= get_surface_color(rt
, 480, 360);
9756 ok(compare_color(color
, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color
);
9758 IDirect3DTexture2_Release(texture2
);
9759 IDirect3DTexture2_Release(texture1
);
9760 IDirectDrawSurface4_Release(surface2
);
9761 IDirectDrawSurface4_Release(surface1
);
9763 destroy_viewport(device
, viewport
);
9765 IDirectDrawSurface4_Release(rt
);
9766 IDirectDraw_Release(ddraw
);
9767 refcount
= IDirect3DDevice3_Release(device
);
9768 ok(!refcount
, "Device has %u references left.\n", refcount
);
9769 DestroyWindow(window
);
9772 static void test_colorkey_precision(void)
9777 struct vec2 texcoord
;
9781 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9782 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
9783 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9784 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
9786 IDirect3DDevice3
*device
;
9788 IDirectDraw4
*ddraw
;
9789 IDirectDrawSurface4
*rt
;
9790 IDirect3DViewport3
*viewport
;
9793 IDirectDrawSurface4
*src
, *dst
, *texture
;
9794 IDirect3DTexture2
*d3d_texture
;
9795 DDSURFACEDESC2 surface_desc
, lock_desc
;
9801 DWORD data
[4] = {0}, color_mask
;
9802 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9803 D3DDEVICEDESC device_desc
, hel_desc
;
9807 unsigned int max
, shift
, bpp
, clear
;
9814 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8",
9816 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9817 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
9822 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel",
9824 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9825 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9830 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel",
9832 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9833 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9838 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4",
9840 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9841 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
9847 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9848 0, 0, 640, 480, 0, 0, 0, 0);
9849 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9851 skip("Failed to create a 3D device, skipping test.\n");
9852 DestroyWindow(window
);
9856 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
9857 * (color key doesn't match although the values are equal), and a false
9858 * positive when the color key is 0 and the texture contains the value 1.
9859 * I don't want to mark this broken unconditionally since this would
9860 * essentially disable the test on Windows. Try to detect WARP (and I
9861 * guess mismatch other SW renderers) by its ability to texture from
9862 * system memory. Also on random occasions 254 == 255 and 255 != 255.*/
9863 memset(&device_desc
, 0, sizeof(device_desc
));
9864 device_desc
.dwSize
= sizeof(device_desc
);
9865 memset(&hel_desc
, 0, sizeof(hel_desc
));
9866 hel_desc
.dwSize
= sizeof(hel_desc
);
9867 hr
= IDirect3DDevice3_GetCaps(device
, &device_desc
, &hel_desc
);
9868 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9869 warp
= !!(device_desc
.dwDevCaps
& D3DDEVCAPS_TEXTURESYSTEMMEMORY
);
9871 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9872 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
9873 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9874 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
9875 IDirect3D3_Release(d3d
);
9876 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
9877 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9879 viewport
= create_viewport(device
, 0, 0, 640, 480);
9880 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
9881 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
9883 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9884 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
9885 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9886 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9887 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
9888 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
9889 /* Multiply the texture read result with 0, that way the result color if the key doesn't
9890 * match is constant. In theory color keying works without reading the texture result
9891 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
9893 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
9894 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9895 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9896 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9897 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
9898 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9899 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x00000000);
9900 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9902 memset(&fx
, 0, sizeof(fx
));
9903 fx
.dwSize
= sizeof(fx
);
9904 memset(&lock_desc
, 0, sizeof(lock_desc
));
9905 lock_desc
.dwSize
= sizeof(lock_desc
);
9907 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
9909 memset(&surface_desc
, 0, sizeof(surface_desc
));
9910 surface_desc
.dwSize
= sizeof(surface_desc
);
9911 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9912 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9913 surface_desc
.dwWidth
= 4;
9914 surface_desc
.dwHeight
= 1;
9915 U4(surface_desc
).ddpfPixelFormat
= tests
[t
].fmt
;
9916 /* Windows XP (at least with the r200 driver, other drivers untested) produces
9917 * garbage when doing color keyed texture->texture blits. */
9918 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
9919 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9920 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
9921 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9923 fx
.dwFillColor
= tests
[t
].clear
;
9924 /* On the w8 testbot (WARP driver) the blit result has different values in the
9926 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
9927 | U3(tests
[t
].fmt
).dwGBitMask
9928 | U4(tests
[t
].fmt
).dwBBitMask
;
9930 for (c
= 0; c
<= tests
[t
].max
; ++c
)
9932 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
9933 * texture after it has been set once... */
9934 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
9935 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9936 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9937 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9938 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
9939 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9940 hr
= IDirectDrawSurface4_QueryInterface(texture
, &IID_IDirect3DTexture2
, (void **)&d3d_texture
);
9941 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9942 hr
= IDirect3DDevice3_SetTexture(device
, 0, d3d_texture
);
9943 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9945 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9946 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
9948 hr
= IDirectDrawSurface4_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9949 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9950 switch (tests
[t
].bpp
)
9953 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9954 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9955 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9956 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
9960 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9961 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9962 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9963 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
9966 hr
= IDirectDrawSurface4_Unlock(src
, 0);
9967 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9968 hr
= IDirectDrawSurface4_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
9969 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9971 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9972 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9973 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
9974 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9976 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
9977 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9979 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
9980 hr
= IDirectDrawSurface4_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9981 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9982 switch (tests
[t
].bpp
)
9985 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9986 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9987 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9988 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
9992 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9993 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9994 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9995 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
9998 hr
= IDirectDrawSurface4_Unlock(dst
, 0);
9999 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10003 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10004 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
10006 if (data
[3] == tests
[t
].clear
)
10008 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10009 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10010 * even when a different surface is used. The blit itself doesn't draw anything,
10011 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10012 * never be masked out by the key.
10014 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10015 * terrible on WARP. */
10016 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10017 IDirect3DTexture2_Release(d3d_texture
);
10018 IDirectDrawSurface4_Release(texture
);
10019 IDirectDrawSurface4_Release(src
);
10020 IDirectDrawSurface4_Release(dst
);
10025 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10026 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
10028 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10029 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
10031 if (c
== tests
[t
].max
)
10032 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10033 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
10035 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10036 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
10038 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x0000ff00, 1.0f
, 0);
10039 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10041 hr
= IDirect3DDevice3_BeginScene(device
);
10042 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10043 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
10044 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10045 hr
= IDirect3DDevice3_EndScene(device
);
10046 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10048 color
= get_surface_color(rt
, 80, 240);
10050 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10051 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10052 color
, tests
[t
].name
, c
);
10054 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
10055 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10056 color
, tests
[t
].name
, c
);
10058 color
= get_surface_color(rt
, 240, 240);
10059 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10060 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10061 color
, tests
[t
].name
, c
);
10063 color
= get_surface_color(rt
, 400, 240);
10064 if (c
== tests
[t
].max
)
10065 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10066 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10067 color
, tests
[t
].name
, c
);
10069 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
10070 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10071 color
, tests
[t
].name
, c
);
10073 IDirect3DTexture2_Release(d3d_texture
);
10074 IDirectDrawSurface4_Release(texture
);
10076 IDirectDrawSurface4_Release(src
);
10077 IDirectDrawSurface4_Release(dst
);
10081 destroy_viewport(device
, viewport
);
10082 IDirectDrawSurface4_Release(rt
);
10083 IDirectDraw4_Release(ddraw
);
10084 refcount
= IDirect3DDevice3_Release(device
);
10085 ok(!refcount
, "Device has %u references left.\n", refcount
);
10086 DestroyWindow(window
);
10089 static void test_range_colorkey(void)
10091 IDirectDraw4
*ddraw
;
10094 IDirectDrawSurface4
*surface
;
10095 DDSURFACEDESC2 surface_desc
;
10099 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10100 0, 0, 640, 480, 0, 0, 0, 0);
10101 ddraw
= create_ddraw();
10102 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10103 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10104 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10106 memset(&surface_desc
, 0, sizeof(surface_desc
));
10107 surface_desc
.dwSize
= sizeof(surface_desc
);
10108 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
10109 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10110 surface_desc
.dwWidth
= 1;
10111 surface_desc
.dwHeight
= 1;
10112 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10113 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10114 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10115 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10116 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10117 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
10119 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10120 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10121 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10122 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10123 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10125 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10126 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10127 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10128 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10130 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10131 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10132 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10133 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10134 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10135 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10137 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10138 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10139 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10140 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10142 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10143 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10144 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10145 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10147 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10148 ckey
.dwColorSpaceLowValue
= 0x00000000;
10149 ckey
.dwColorSpaceHighValue
= 0x00000001;
10150 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10151 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10153 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10154 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10155 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10156 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10158 ckey
.dwColorSpaceLowValue
= 0x00000001;
10159 ckey
.dwColorSpaceHighValue
= 0x00000000;
10160 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10161 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10163 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10164 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10165 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10166 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10168 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10169 ckey
.dwColorSpaceLowValue
= 0x00000000;
10170 ckey
.dwColorSpaceHighValue
= 0x00000000;
10171 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10172 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10174 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10175 ckey
.dwColorSpaceLowValue
= 0x00000001;
10176 ckey
.dwColorSpaceHighValue
= 0x00000000;
10177 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10178 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10179 ckey
.dwColorSpaceLowValue
= 0x00000000;
10180 ckey
.dwColorSpaceHighValue
= 0x00000001;
10181 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10182 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10183 /* Range destination keys don't work either. */
10184 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
10185 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10187 /* Just to show it's not because of A, R, and G having equal values. */
10188 ckey
.dwColorSpaceLowValue
= 0x00000000;
10189 ckey
.dwColorSpaceHighValue
= 0x01010101;
10190 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10191 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10193 /* None of these operations modified the key. */
10194 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10195 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10196 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10197 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10199 IDirectDrawSurface4_Release(surface
),
10200 refcount
= IDirectDraw4_Release(ddraw
);
10201 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
10202 DestroyWindow(window
);
10205 static void test_shademode(void)
10207 IDirect3DVertexBuffer
*vb_strip
, *vb_list
, *buffer
;
10208 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10209 IDirect3DViewport3
*viewport
;
10210 IDirect3DDevice3
*device
;
10211 D3DVERTEXBUFFERDESC desc
;
10212 IDirectDrawSurface4
*rt
;
10213 DWORD color0
, color1
;
10220 static const struct
10222 struct vec3 position
;
10227 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10228 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10229 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10230 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10234 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10235 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10236 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10238 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10239 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10240 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10242 static const struct
10246 DWORD color0
, color1
;
10250 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
10251 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10252 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10253 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10254 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
10255 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10258 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10259 0, 0, 640, 480, 0, 0, 0, 0);
10261 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10263 skip("Failed to create a 3D device, skipping test.\n");
10264 DestroyWindow(window
);
10268 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
10269 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
10270 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
10271 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10273 viewport
= create_viewport(device
, 0, 0, 640, 480);
10274 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
10275 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10277 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10278 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10280 memset(&desc
, 0, sizeof(desc
));
10281 desc
.dwSize
= sizeof(desc
);
10282 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
10283 desc
.dwFVF
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
10284 desc
.dwNumVertices
= sizeof(quad_strip
) / sizeof(*quad_strip
);
10285 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &vb_strip
, 0, NULL
);
10286 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10287 hr
= IDirect3DVertexBuffer_Lock(vb_strip
, 0, &data
, NULL
);
10288 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10289 memcpy(data
, quad_strip
, sizeof(quad_strip
));
10290 hr
= IDirect3DVertexBuffer_Unlock(vb_strip
);
10291 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10293 desc
.dwNumVertices
= sizeof(quad_list
) / sizeof(*quad_list
);
10294 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &vb_list
, 0, NULL
);
10295 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10296 hr
= IDirect3DVertexBuffer_Lock(vb_list
, 0, &data
, NULL
);
10297 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10298 memcpy(data
, quad_list
, sizeof(quad_list
));
10299 hr
= IDirect3DVertexBuffer_Unlock(vb_list
);
10300 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10302 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10303 * the color fixups we have to do for FLAT shading will be dependent on that. */
10305 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
10307 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
10308 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
10310 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
10311 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
10313 hr
= IDirect3DDevice3_BeginScene(device
);
10314 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10315 buffer
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? vb_strip
: vb_list
;
10316 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
10317 hr
= IDirect3DDevice3_DrawPrimitiveVB(device
, tests
[i
].primtype
, buffer
, 0, count
, 0);
10318 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10319 hr
= IDirect3DDevice3_EndScene(device
);
10320 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10322 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
10323 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
10325 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10326 * each triangle. This requires EXT_provoking_vertex or similar
10327 * functionality being available. */
10328 /* PHONG should be the same as GOURAUD, since no hardware implements
10330 ok(compare_color(color0
, tests
[i
].color0
, 1), "Test %u shading has color0 %08x, expected %08x.\n",
10331 i
, color0
, tests
[i
].color0
);
10332 ok(compare_color(color1
, tests
[i
].color1
, 1), "Test %u shading has color1 %08x, expected %08x.\n",
10333 i
, color1
, tests
[i
].color1
);
10336 IDirect3DVertexBuffer_Release(vb_strip
);
10337 IDirect3DVertexBuffer_Release(vb_list
);
10338 destroy_viewport(device
, viewport
);
10339 IDirectDrawSurface4_Release(rt
);
10340 IDirect3D3_Release(d3d
);
10341 refcount
= IDirect3DDevice3_Release(device
);
10342 ok(!refcount
, "Device has %u references left.\n", refcount
);
10343 DestroyWindow(window
);
10346 static void test_lockrect_invalid(void)
10349 IDirectDraw4
*ddraw
;
10350 IDirectDrawSurface4
*surface
;
10353 DDSURFACEDESC2 surface_desc
;
10355 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
10356 static RECT valid
[] =
10361 {120, 60, 128, 68},
10362 {60, 120, 68, 128},
10364 static RECT invalid
[] =
10366 {68, 60, 60, 68}, /* left > right */
10367 {60, 68, 68, 60}, /* top > bottom */
10368 {-8, 60, 0, 68}, /* left < surface */
10369 {60, -8, 68, 0}, /* top < surface */
10370 {-16, 60, -8, 68}, /* right < surface */
10371 {60, -16, 68, -8}, /* bottom < surface */
10372 {60, 60, 136, 68}, /* right > surface */
10373 {60, 60, 68, 136}, /* bottom > surface */
10374 {136, 60, 144, 68}, /* left > surface */
10375 {60, 136, 68, 144}, /* top > surface */
10377 static const struct
10385 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem offscreenplain", DDERR_INVALIDPARAMS
},
10386 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem offscreenplain", DDERR_INVALIDPARAMS
},
10387 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem texture", DDERR_INVALIDPARAMS
},
10388 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem texture", DDERR_INVALIDPARAMS
},
10389 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, "managed texture", DDERR_INVALIDPARAMS
},
10392 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10393 0, 0, 640, 480, 0, 0, 0, 0);
10394 ddraw
= create_ddraw();
10395 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10396 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10397 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10399 memset(&hal_caps
, 0, sizeof(hal_caps
));
10400 hal_caps
.dwSize
= sizeof(hal_caps
);
10401 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
10402 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
10403 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
10404 || !(hal_caps
.ddsCaps
.dwCaps
& DDSCAPS2_TEXTUREMANAGE
))
10406 skip("Required surface types not supported, skipping test.\n");
10410 for (r
= 0; r
< sizeof(resources
) / sizeof(*resources
); ++r
)
10412 memset(&surface_desc
, 0, sizeof(surface_desc
));
10413 surface_desc
.dwSize
= sizeof(surface_desc
);
10414 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10415 surface_desc
.ddsCaps
.dwCaps
= resources
[r
].caps
;
10416 surface_desc
.ddsCaps
.dwCaps2
= resources
[r
].caps2
;
10417 surface_desc
.dwWidth
= 128;
10418 surface_desc
.dwHeight
= 128;
10419 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
10420 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10421 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10422 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xff0000;
10423 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x00ff00;
10424 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x0000ff;
10426 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10427 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10429 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, NULL
, DDLOCK_WAIT
, NULL
);
10430 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
10432 for (i
= 0; i
< sizeof(valid
) / sizeof(*valid
); ++i
)
10434 RECT
*rect
= &valid
[i
];
10436 memset(&surface_desc
, 0, sizeof(surface_desc
));
10437 surface_desc
.dwSize
= sizeof(surface_desc
);
10439 hr
= IDirectDrawSurface4_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10440 ok(SUCCEEDED(hr
), "Lock failed (%#x) for rect [%d, %d]->[%d, %d], type %s.\n",
10441 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, resources
[r
].name
);
10443 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10444 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10447 for (i
= 0; i
< sizeof(invalid
) / sizeof(*invalid
); ++i
)
10449 RECT
*rect
= &invalid
[i
];
10451 memset(&surface_desc
, 1, sizeof(surface_desc
));
10452 surface_desc
.dwSize
= sizeof(surface_desc
);
10454 hr
= IDirectDrawSurface4_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10455 ok(hr
== resources
[r
].hr
, "Lock returned %#x for rect [%d, %d]->[%d, %d], type %s.\n",
10456 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, resources
[r
].name
);
10459 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10460 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10463 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
10466 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10467 ok(SUCCEEDED(hr
), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
10468 hr
, resources
[r
].name
);
10469 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10470 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned %#x, type %s.\n",
10471 hr
, resources
[r
].name
);
10472 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10473 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10475 hr
= IDirectDrawSurface4_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
10476 ok(SUCCEEDED(hr
), "Lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
10477 valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, hr
);
10478 hr
= IDirectDrawSurface4_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
10479 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
10480 valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, hr
);
10482 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
10483 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
10485 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10486 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10488 IDirectDrawSurface4_Release(surface
);
10492 IDirectDraw4_Release(ddraw
);
10493 DestroyWindow(window
);
10496 static void test_yv12_overlay(void)
10498 IDirectDrawSurface4
*src_surface
, *dst_surface
;
10499 RECT rect
= {13, 17, 14, 18};
10500 unsigned int offset
, y
;
10501 DDSURFACEDESC2 desc
;
10502 unsigned char *base
;
10503 IDirectDraw4
*ddraw
;
10507 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10508 0, 0, 640, 480, 0, 0, 0, 0);
10509 ddraw
= create_ddraw();
10510 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10511 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10512 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10514 if (!(src_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
10516 skip("Failed to create a YV12 overlay, skipping test.\n");
10520 memset(&desc
, 0, sizeof(desc
));
10521 desc
.dwSize
= sizeof(desc
);
10522 hr
= IDirectDrawSurface4_Lock(src_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
10523 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10525 ok(desc
.dwFlags
== (DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_PITCH
),
10526 "Got unexpected flags %#x.\n", desc
.dwFlags
);
10527 ok(desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_HWCODEC
)
10528 || desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
10529 "Got unexpected caps %#x.\n", desc
.ddsCaps
.dwCaps
);
10530 ok(desc
.dwWidth
== 256, "Got unexpected width %u.\n", desc
.dwWidth
);
10531 ok(desc
.dwHeight
== 256, "Got unexpected height %u.\n", desc
.dwHeight
);
10532 /* The overlay pitch seems to have 256 byte alignment. */
10533 ok(!(U1(desc
).lPitch
& 0xff), "Got unexpected pitch %u.\n", U1(desc
).lPitch
);
10535 /* Fill the surface with some data for the blit test. */
10536 base
= desc
.lpSurface
;
10538 for (y
= 0; y
< desc
.dwHeight
; ++y
)
10540 memset(base
+ U1(desc
).lPitch
* y
, 0x10, desc
.dwWidth
);
10543 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 4; ++y
)
10545 memset(base
+ U1(desc
).lPitch
* y
, 0x20, desc
.dwWidth
);
10548 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 2; ++y
)
10550 memset(base
+ U1(desc
).lPitch
* y
, 0x30, desc
.dwWidth
);
10553 hr
= IDirectDrawSurface4_Unlock(src_surface
, NULL
);
10554 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10556 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
10557 * other block-based formats like DXT the entire Y channel is stored in
10558 * one big chunk of memory, followed by the chroma channels. So partial
10559 * locks do not really make sense. Show that they are allowed nevertheless
10560 * and the offset points into the luminance data. */
10561 hr
= IDirectDrawSurface4_Lock(src_surface
, &rect
, &desc
, DDLOCK_WAIT
, NULL
);
10562 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10563 offset
= ((const unsigned char *)desc
.lpSurface
- base
);
10564 ok(offset
== rect
.top
* U1(desc
).lPitch
+ rect
.left
, "Got unexpected offset %u, expected %u.\n",
10565 offset
, rect
.top
* U1(desc
).lPitch
+ rect
.left
);
10566 hr
= IDirectDrawSurface4_Unlock(src_surface
, NULL
);
10567 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10569 if (!(dst_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
10571 /* Windows XP with a Radeon X1600 GPU refuses to create a second
10572 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
10573 skip("Failed to create a second YV12 surface, skipping blit test.\n");
10574 IDirectDrawSurface4_Release(src_surface
);
10578 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, src_surface
, NULL
, DDBLT_WAIT
, NULL
);
10579 /* VMware rejects YV12 blits. This behavior has not been seen on real
10580 * hardware yet, so mark it broken. */
10581 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
), "Failed to blit, hr %#x.\n", hr
);
10585 memset(&desc
, 0, sizeof(desc
));
10586 desc
.dwSize
= sizeof(desc
);
10587 hr
= IDirectDrawSurface4_Lock(dst_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
10588 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10590 base
= desc
.lpSurface
;
10591 ok(base
[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base
[0]);
10592 base
+= desc
.dwHeight
* U1(desc
).lPitch
;
10593 todo_wine
ok(base
[0] == 0x20, "Got unexpected V data 0x%02x.\n", base
[0]);
10594 base
+= desc
.dwHeight
/ 4 * U1(desc
).lPitch
;
10595 todo_wine
ok(base
[0] == 0x30, "Got unexpected U data 0x%02x.\n", base
[0]);
10597 hr
= IDirectDrawSurface4_Unlock(dst_surface
, NULL
);
10598 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10601 IDirectDrawSurface4_Release(dst_surface
);
10602 IDirectDrawSurface4_Release(src_surface
);
10604 IDirectDraw4_Release(ddraw
);
10605 DestroyWindow(window
);
10608 static void test_offscreen_overlay(void)
10610 IDirectDrawSurface4
*overlay
, *offscreen
, *primary
;
10611 DDSURFACEDESC2 surface_desc
;
10612 IDirectDraw4
*ddraw
;
10617 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10618 0, 0, 640, 480, 0, 0, 0, 0);
10619 ddraw
= create_ddraw();
10620 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10621 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10622 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10624 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
10626 skip("Failed to create a UYVY overlay, skipping test.\n");
10630 memset(&surface_desc
, 0, sizeof(surface_desc
));
10631 surface_desc
.dwSize
= sizeof(surface_desc
);
10632 surface_desc
.dwFlags
= DDSD_CAPS
;
10633 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
10634 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
10635 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
10637 /* On Windows 7, and probably Vista, UpdateOverlay() will return
10638 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
10639 * surface prevents this by disabling the dwm. */
10640 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
10641 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
10642 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
10643 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
10645 /* Try to overlay a NULL surface. */
10646 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_SHOW
, NULL
);
10647 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10648 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_HIDE
, NULL
);
10649 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10651 /* Try to overlay an offscreen surface. */
10652 memset(&surface_desc
, 0, sizeof(surface_desc
));
10653 surface_desc
.dwSize
= sizeof(surface_desc
);
10654 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
10655 surface_desc
.dwWidth
= 64;
10656 surface_desc
.dwHeight
= 64;
10657 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10658 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
10659 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10660 U4(surface_desc
).ddpfPixelFormat
.dwFourCC
= 0;
10661 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
10662 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
10663 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
10664 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
10665 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
10666 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
10668 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, offscreen
, NULL
, DDOVER_SHOW
, NULL
);
10669 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10671 /* Try to overlay the primary with a non-overlay surface. */
10672 hr
= IDirectDrawSurface4_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
10673 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
10674 hr
= IDirectDrawSurface4_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
10675 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
10677 IDirectDrawSurface4_Release(offscreen
);
10678 IDirectDrawSurface4_Release(primary
);
10679 IDirectDrawSurface4_Release(overlay
);
10681 IDirectDraw4_Release(ddraw
);
10682 DestroyWindow(window
);
10685 static void test_overlay_rect(void)
10687 IDirectDrawSurface4
*overlay
, *primary
;
10688 DDSURFACEDESC2 surface_desc
;
10689 RECT rect
= {0, 0, 64, 64};
10690 IDirectDraw4
*ddraw
;
10696 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10697 0, 0, 640, 480, 0, 0, 0, 0);
10698 ddraw
= create_ddraw();
10699 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10700 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10701 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10703 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
10705 skip("Failed to create a UYVY overlay, skipping test.\n");
10709 memset(&surface_desc
, 0, sizeof(surface_desc
));
10710 surface_desc
.dwSize
= sizeof(surface_desc
);
10711 surface_desc
.dwFlags
= DDSD_CAPS
;
10712 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
10713 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
10714 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
10716 /* On Windows 7, and probably Vista, UpdateOverlay() will return
10717 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
10718 * surface prevents this by disabling the dwm. */
10719 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
10720 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
10721 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
10722 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
10724 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
10725 * used. This is not true in Windows Vista and earlier, but changed in
10727 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
10728 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10729 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
10730 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10731 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
10732 ok(hr
== DD_OK
|| hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10734 /* Show that the overlay position is the (top, left) coordinate of the
10735 * destination rectangle. */
10736 OffsetRect(&rect
, 32, 16);
10737 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
10738 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10739 pos_x
= -1; pos_y
= -1;
10740 hr
= IDirectDrawSurface4_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
10741 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
10742 ok(pos_x
== rect
.left
, "Got unexpected pos_x %d, expected %d.\n", pos_x
, rect
.left
);
10743 ok(pos_y
== rect
.top
, "Got unexpected pos_y %d, expected %d.\n", pos_y
, rect
.top
);
10745 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
10746 * seen that the overlay overlays the whole primary(==screen). */
10747 hr2
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, NULL
, 0, NULL
);
10748 ok(hr2
== DD_OK
|| hr2
== DDERR_INVALIDPARAMS
|| hr2
== DDERR_OUTOFCAPS
, "Got unexpected hr %#x.\n", hr2
);
10749 hr
= IDirectDrawSurface4_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
10750 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
10751 if (SUCCEEDED(hr2
))
10753 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
10754 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
10758 ok(pos_x
== 32, "Got unexpected pos_x %d.\n", pos_x
);
10759 ok(pos_y
== 16, "Got unexpected pos_y %d.\n", pos_y
);
10762 /* The position cannot be retrieved when the overlay is not shown. */
10763 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_HIDE
, NULL
);
10764 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10765 pos_x
= -1; pos_y
= -1;
10766 hr
= IDirectDrawSurface4_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
10767 ok(hr
== DDERR_OVERLAYNOTVISIBLE
, "Got unexpected hr %#x.\n", hr
);
10768 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
10769 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
10771 IDirectDrawSurface4_Release(primary
);
10772 IDirectDrawSurface4_Release(overlay
);
10774 IDirectDraw4_Release(ddraw
);
10775 DestroyWindow(window
);
10780 IDirectDraw4
*ddraw
;
10781 DEVMODEW current_mode
;
10783 if (!(ddraw
= create_ddraw()))
10785 skip("Failed to create a ddraw object, skipping tests.\n");
10788 IDirectDraw4_Release(ddraw
);
10790 memset(¤t_mode
, 0, sizeof(current_mode
));
10791 current_mode
.dmSize
= sizeof(current_mode
);
10792 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
10793 registry_mode
.dmSize
= sizeof(registry_mode
);
10794 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
10795 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
10796 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
10798 skip("Current mode does not match registry mode, skipping test.\n");
10802 test_process_vertices();
10803 test_coop_level_create_device_window();
10804 test_clipper_blt();
10805 test_coop_level_d3d_state();
10806 test_surface_interface_mismatch();
10807 test_coop_level_threaded();
10809 test_texture_load_ckey();
10818 test_window_style();
10819 test_redundant_mode_set();
10820 test_coop_level_mode_set();
10821 test_coop_level_mode_set_multi();
10823 test_coop_level_surf_create();
10825 test_coop_level_multi_window();
10826 test_draw_strided();
10828 test_specular_lighting();
10829 test_clear_rect_count();
10830 test_coop_level_versions();
10831 test_lighting_interface_versions();
10832 test_coop_level_activateapp();
10833 test_texturemanage();
10834 test_block_formats_creation();
10835 test_unsupported_formats();
10837 test_primary_caps();
10838 test_surface_lock();
10839 test_surface_discard();
10841 test_set_surface_desc();
10842 test_user_memory_getdc();
10843 test_sysmem_overlay();
10844 test_primary_palette();
10845 test_surface_attachment();
10846 test_private_data();
10847 test_pixel_format();
10848 test_create_surface_pitch();
10850 test_palette_complex();
10851 test_p8_rgb_blit();
10853 test_palette_gdi();
10854 test_palette_alpha();
10855 test_vb_writeonly();
10856 test_lost_device();
10857 test_surface_desc_lock();
10858 test_signed_formats();
10860 test_texcoordindex();
10861 test_colorkey_precision();
10862 test_range_colorkey();
10864 test_lockrect_invalid();
10865 test_yv12_overlay();
10866 test_offscreen_overlay();
10867 test_overlay_rect();