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
;
6627 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6628 0, 0, 640, 480, 0, 0, 0, 0);
6629 ddraw
= create_ddraw();
6630 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6632 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6633 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6636 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6639 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6640 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6641 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6642 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6643 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6644 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6645 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6646 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6647 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6649 memset(data
, 0xaa, sizeof(data
));
6651 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6652 ddsd
.lpSurface
= data
;
6653 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6654 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6656 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
6657 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6658 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
6659 ok(!!bitmap
, "Failed to get bitmap.\n");
6660 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
6661 ok(size
== sizeof(dib
), "Got unexpected size %d.\n", size
);
6662 ok(dib
.dsBm
.bmBits
== data
, "Got unexpected bits %p, expected %p.\n", dib
.dsBm
.bmBits
, data
);
6663 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
6664 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
6665 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
6666 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6668 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
6669 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
6671 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
6672 ddsd
.lpSurface
= data
;
6675 U1(ddsd
).lPitch
= sizeof(*data
);
6676 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6677 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6679 memset(data
, 0xaa, sizeof(data
));
6680 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
6681 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6682 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
6683 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
6684 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
6685 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6687 for (y
= 0; y
< 4; y
++)
6689 for (x
= 0; x
< 4; x
++)
6691 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
6692 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6695 ok(data
[y
][x
] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6699 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6701 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6703 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6705 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6708 IDirectDrawSurface4_Release(surface
);
6709 ref
= IDirectDraw4_Release(ddraw
);
6710 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6711 DestroyWindow(window
);
6714 static void test_sysmem_overlay(void)
6716 IDirectDraw4
*ddraw
;
6719 DDSURFACEDESC2 ddsd
;
6720 IDirectDrawSurface4
*surface
;
6723 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6724 0, 0, 640, 480, 0, 0, 0, 0);
6725 ddraw
= create_ddraw();
6726 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6728 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6729 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6732 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
6735 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
6736 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6737 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6738 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6739 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6740 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6741 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6742 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6743 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
6745 ref
= IDirectDraw4_Release(ddraw
);
6746 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6747 DestroyWindow(window
);
6750 static void test_primary_palette(void)
6752 DDSCAPS2 surface_caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
6753 IDirectDrawSurface4
*primary
, *backbuffer
;
6754 PALETTEENTRY palette_entries
[256];
6755 IDirectDrawPalette
*palette
, *tmp
;
6756 DDSURFACEDESC2 surface_desc
;
6757 IDirectDraw4
*ddraw
;
6763 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6764 0, 0, 640, 480, 0, 0, 0, 0);
6765 ddraw
= create_ddraw();
6766 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6767 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
6769 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6770 IDirectDraw4_Release(ddraw
);
6771 DestroyWindow(window
);
6774 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6775 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6777 memset(&surface_desc
, 0, sizeof(surface_desc
));
6778 surface_desc
.dwSize
= sizeof(surface_desc
);
6779 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6780 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6781 U5(surface_desc
).dwBackBufferCount
= 1;
6782 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6783 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6784 hr
= IDirectDrawSurface4_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
6785 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6787 memset(palette_entries
, 0, sizeof(palette_entries
));
6788 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
6789 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6790 refcount
= get_refcount((IUnknown
*)palette
);
6791 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6793 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6794 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6795 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6797 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
6798 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6800 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6801 * and is generally somewhat broken with respect to 8 bpp / palette
6803 if (SUCCEEDED(IDirectDrawSurface4_GetPalette(backbuffer
, &tmp
)))
6805 win_skip("Broken palette handling detected, skipping tests.\n");
6806 IDirectDrawPalette_Release(tmp
);
6807 IDirectDrawPalette_Release(palette
);
6808 /* The Windows 8 testbot keeps extra references to the primary and
6809 * backbuffer while in 8 bpp mode. */
6810 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
6811 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
6815 refcount
= get_refcount((IUnknown
*)palette
);
6816 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6818 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6819 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6820 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
6821 "Got unexpected palette caps %#x.\n", palette_caps
);
6823 hr
= IDirectDrawSurface4_SetPalette(primary
, NULL
);
6824 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6825 refcount
= get_refcount((IUnknown
*)palette
);
6826 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6828 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6829 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6830 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6832 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
6833 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6834 refcount
= get_refcount((IUnknown
*)palette
);
6835 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6837 hr
= IDirectDrawSurface4_GetPalette(primary
, &tmp
);
6838 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6839 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
6840 IDirectDrawPalette_Release(tmp
);
6841 hr
= IDirectDrawSurface4_GetPalette(backbuffer
, &tmp
);
6842 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6844 refcount
= IDirectDrawPalette_Release(palette
);
6845 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6846 refcount
= IDirectDrawPalette_Release(palette
);
6847 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6849 /* Note that this only seems to work when the palette is attached to the
6850 * primary surface. When attached to a regular surface, attempting to get
6851 * the palette here will cause an access violation. */
6852 hr
= IDirectDrawSurface4_GetPalette(primary
, &tmp
);
6853 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6856 refcount
= IDirectDrawSurface4_Release(backbuffer
);
6857 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6858 refcount
= IDirectDrawSurface4_Release(primary
);
6859 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6860 refcount
= IDirectDraw4_Release(ddraw
);
6861 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6862 DestroyWindow(window
);
6865 static HRESULT WINAPI
surface_counter(IDirectDrawSurface4
*surface
, DDSURFACEDESC2
*desc
, void *context
)
6867 UINT
*surface_count
= context
;
6870 IDirectDrawSurface_Release(surface
);
6872 return DDENUMRET_OK
;
6875 static void test_surface_attachment(void)
6877 IDirectDrawSurface4
*surface1
, *surface2
, *surface3
, *surface4
;
6878 IDirectDrawSurface
*surface1v1
, *surface2v1
;
6879 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, {0}};
6880 DDSURFACEDESC2 surface_desc
;
6881 IDirectDraw4
*ddraw
;
6887 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6888 0, 0, 640, 480, 0, 0, 0, 0);
6889 ddraw
= create_ddraw();
6890 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6891 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6892 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6894 memset(&surface_desc
, 0, sizeof(surface_desc
));
6895 surface_desc
.dwSize
= sizeof(surface_desc
);
6896 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
6897 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6898 U2(surface_desc
).dwMipMapCount
= 3;
6899 surface_desc
.dwWidth
= 128;
6900 surface_desc
.dwHeight
= 128;
6901 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6902 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6904 hr
= IDirectDrawSurface4_GetAttachedSurface(surface1
, &caps
, &surface2
);
6905 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6906 hr
= IDirectDrawSurface4_GetAttachedSurface(surface2
, &caps
, &surface3
);
6907 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6908 hr
= IDirectDrawSurface4_GetAttachedSurface(surface3
, &caps
, &surface4
);
6909 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6912 IDirectDrawSurface4_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
6913 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6915 IDirectDrawSurface4_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
6916 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6918 IDirectDrawSurface4_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
6919 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
6921 memset(&surface_desc
, 0, sizeof(surface_desc
));
6922 surface_desc
.dwSize
= sizeof(surface_desc
);
6923 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6924 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6925 surface_desc
.dwWidth
= 16;
6926 surface_desc
.dwHeight
= 16;
6927 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6928 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6930 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
);
6931 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6932 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
6933 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6934 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface4
);
6935 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6936 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface3
);
6937 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6938 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface4
);
6939 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6940 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface2
);
6941 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6943 IDirectDrawSurface4_Release(surface4
);
6945 memset(&surface_desc
, 0, sizeof(surface_desc
));
6946 surface_desc
.dwSize
= sizeof(surface_desc
);
6947 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6948 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6949 surface_desc
.dwWidth
= 16;
6950 surface_desc
.dwHeight
= 16;
6951 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6952 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6954 if (SUCCEEDED(hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
)))
6956 skip("Running on refrast, skipping some tests.\n");
6957 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface4
);
6958 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6962 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6963 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
6964 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6965 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface4
);
6966 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6967 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface3
);
6968 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6969 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface4
);
6970 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6971 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface2
);
6972 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6975 IDirectDrawSurface4_Release(surface4
);
6976 IDirectDrawSurface4_Release(surface3
);
6977 IDirectDrawSurface4_Release(surface2
);
6978 IDirectDrawSurface4_Release(surface1
);
6980 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6981 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6983 /* Try a single primary and two offscreen plain surfaces. */
6984 memset(&surface_desc
, 0, sizeof(surface_desc
));
6985 surface_desc
.dwSize
= sizeof(surface_desc
);
6986 surface_desc
.dwFlags
= DDSD_CAPS
;
6987 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6988 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6989 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6991 memset(&surface_desc
, 0, sizeof(surface_desc
));
6992 surface_desc
.dwSize
= sizeof(surface_desc
);
6993 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6994 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6995 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6996 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6997 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
6998 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7000 memset(&surface_desc
, 0, sizeof(surface_desc
));
7001 surface_desc
.dwSize
= sizeof(surface_desc
);
7002 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7003 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7004 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
7005 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
7006 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
7007 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7009 /* This one has a different size. */
7010 memset(&surface_desc
, 0, sizeof(surface_desc
));
7011 surface_desc
.dwSize
= sizeof(surface_desc
);
7012 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7013 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7014 surface_desc
.dwWidth
= 128;
7015 surface_desc
.dwHeight
= 128;
7016 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
7017 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7019 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7020 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7021 /* Try the reverse without detaching first. */
7022 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface1
);
7023 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
7024 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7025 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7027 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface1
);
7028 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7029 /* Try to detach reversed. */
7030 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7031 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7032 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface2
, 0, surface1
);
7033 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7035 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface3
);
7036 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7037 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface2
, 0, surface3
);
7038 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7040 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
);
7041 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7042 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
7043 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7045 IDirectDrawSurface4_Release(surface4
);
7046 IDirectDrawSurface4_Release(surface3
);
7047 IDirectDrawSurface4_Release(surface2
);
7048 IDirectDrawSurface4_Release(surface1
);
7050 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
7051 memset(&surface_desc
, 0, sizeof(surface_desc
));
7052 surface_desc
.dwSize
= sizeof(surface_desc
);
7053 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7054 surface_desc
.dwWidth
= 64;
7055 surface_desc
.dwHeight
= 64;
7056 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
7057 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7058 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
7059 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
7060 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
7061 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
7062 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
7063 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7064 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7065 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
7066 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7068 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
7069 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
7070 U1(U4(surface_desc
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
7071 U3(U4(surface_desc
).ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
7072 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
7073 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7075 hr
= IDirectDrawSurface4_QueryInterface(surface1
, &IID_IDirectDrawSurface
, (void **)&surface1v1
);
7076 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
7077 hr
= IDirectDrawSurface4_QueryInterface(surface2
, &IID_IDirectDrawSurface
, (void **)&surface2v1
);
7078 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
7080 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7081 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7082 refcount
= get_refcount((IUnknown
*)surface2
);
7083 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
7084 refcount
= get_refcount((IUnknown
*)surface2v1
);
7085 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7086 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7087 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
7088 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7089 todo_wine
ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7090 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
7091 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
7093 /* Attaching while already attached to other surface. */
7094 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface2
);
7095 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7096 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface3
, 0, surface2
);
7097 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7098 IDirectDrawSurface4_Release(surface3
);
7100 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7101 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7102 refcount
= get_refcount((IUnknown
*)surface2
);
7103 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7104 refcount
= get_refcount((IUnknown
*)surface2v1
);
7105 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7107 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
7108 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7109 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7110 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7111 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
7112 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
7113 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7114 refcount
= IDirectDrawSurface4_Release(surface2
);
7115 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7116 refcount
= IDirectDrawSurface4_Release(surface1
);
7117 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7119 /* Automatic detachment on release. */
7120 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7121 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7122 refcount
= get_refcount((IUnknown
*)surface2v1
);
7123 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
7124 refcount
= IDirectDrawSurface_Release(surface1v1
);
7125 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7126 refcount
= IDirectDrawSurface_Release(surface2v1
);
7127 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7128 refcount
= IDirectDraw4_Release(ddraw
);
7129 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7130 DestroyWindow(window
);
7133 static void test_private_data(void)
7135 IDirectDraw4
*ddraw
;
7136 IDirectDrawSurface4
*surface
, *surface2
;
7137 DDSURFACEDESC2 surface_desc
;
7138 ULONG refcount
, refcount2
, refcount3
;
7140 DWORD size
= sizeof(ptr
);
7143 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7144 DWORD data
[] = {1, 2, 3, 4};
7146 static const GUID ddraw_private_data_test_guid
=
7151 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
7153 static const GUID ddraw_private_data_test_guid2
=
7158 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
7161 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7162 0, 0, 640, 480, 0, 0, 0, 0);
7163 ddraw
= create_ddraw();
7164 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7165 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7166 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7168 reset_ddsd(&surface_desc
);
7169 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
7170 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
7171 surface_desc
.dwHeight
= 4;
7172 surface_desc
.dwWidth
= 4;
7173 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7174 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7176 /* NULL pointers are not valid, but don't cause a crash. */
7177 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
,
7178 sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
7179 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7180 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 0, 0);
7181 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7182 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 1, 0);
7183 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7185 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
7186 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7187 0, DDSPD_IUNKNOWNPOINTER
);
7188 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7189 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7190 5, DDSPD_IUNKNOWNPOINTER
);
7191 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7192 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7193 sizeof(ddraw
) * 2, DDSPD_IUNKNOWNPOINTER
);
7194 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7196 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
7197 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
7198 * erases the old content and returns an error. This behavior has
7199 * been fixed in d3d8 and d3d9. Unless an application is found
7200 * that depends on this we don't care about this behavior. */
7201 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7202 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7203 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7204 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7205 0, DDSPD_IUNKNOWNPOINTER
);
7206 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7208 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7209 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7210 hr
= IDirectDrawSurface4_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7211 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7213 refcount
= get_refcount((IUnknown
*)ddraw
);
7214 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7215 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7216 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7217 refcount2
= get_refcount((IUnknown
*)ddraw
);
7218 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7220 hr
= IDirectDrawSurface4_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7221 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7222 refcount2
= get_refcount((IUnknown
*)ddraw
);
7223 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7225 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7226 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7227 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7228 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, surface
,
7229 sizeof(surface
), DDSPD_IUNKNOWNPOINTER
);
7230 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7231 refcount2
= get_refcount((IUnknown
*)ddraw
);
7232 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7234 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7235 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7236 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7237 size
= 2 * sizeof(ptr
);
7238 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7239 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7240 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7241 refcount2
= get_refcount(ptr
);
7242 /* Object is NOT addref'ed by the getter. */
7243 ok(ptr
== (IUnknown
*)ddraw
, "Returned interface pointer is %p, expected %p.\n", ptr
, ddraw
);
7244 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7246 ptr
= (IUnknown
*)0xdeadbeef;
7248 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7249 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7250 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7251 size
= 2 * sizeof(ptr
);
7252 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7253 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7254 ok(size
== 2 * sizeof(ptr
), "Got unexpected size %u.\n", size
);
7256 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7257 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7258 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7259 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7260 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, NULL
, NULL
);
7261 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7263 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, &ptr
, &size
);
7264 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7265 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7266 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
7267 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7268 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7270 refcount3
= IDirectDrawSurface4_Release(surface
);
7271 ok(!refcount3
, "Got unexpected refcount %u.\n", refcount3
);
7273 /* Destroying the surface frees the reference held on the private data. It also frees
7274 * the reference the surface is holding on its creating object. */
7275 refcount2
= get_refcount((IUnknown
*)ddraw
);
7276 ok(refcount2
== refcount
- 1, "Got unexpected refcount %u.\n", refcount2
);
7278 memset(&hal_caps
, 0, sizeof(hal_caps
));
7279 hal_caps
.dwSize
= sizeof(hal_caps
);
7280 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7281 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7282 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) == (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7284 reset_ddsd(&surface_desc
);
7285 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_MIPMAPCOUNT
;
7286 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7287 surface_desc
.dwHeight
= 4;
7288 surface_desc
.dwWidth
= 4;
7289 U2(surface_desc
).dwMipMapCount
= 2;
7290 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7291 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7292 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &surface2
);
7293 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7295 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, data
, sizeof(data
), 0);
7296 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7297 hr
= IDirectDrawSurface4_GetPrivateData(surface2
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7298 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7300 IDirectDrawSurface4_Release(surface2
);
7301 IDirectDrawSurface4_Release(surface
);
7304 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7306 refcount
= IDirectDraw4_Release(ddraw
);
7307 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7308 DestroyWindow(window
);
7311 static void test_pixel_format(void)
7313 HWND window
, window2
= NULL
;
7314 HDC hdc
, hdc2
= NULL
;
7316 int format
, test_format
;
7317 PIXELFORMATDESCRIPTOR pfd
;
7318 IDirectDraw4
*ddraw
= NULL
;
7319 IDirectDrawClipper
*clipper
= NULL
;
7320 DDSURFACEDESC2 ddsd
;
7321 IDirectDrawSurface4
*primary
= NULL
;
7325 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7326 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7329 skip("Failed to create window\n");
7333 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7334 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7336 hdc
= GetDC(window
);
7339 skip("Failed to get DC\n");
7344 hdc2
= GetDC(window2
);
7346 gl
= LoadLibraryA("opengl32.dll");
7347 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7349 format
= GetPixelFormat(hdc
);
7350 ok(format
== 0, "new window has pixel format %d\n", format
);
7352 ZeroMemory(&pfd
, sizeof(pfd
));
7353 pfd
.nSize
= sizeof(pfd
);
7355 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
7356 pfd
.iPixelType
= PFD_TYPE_RGBA
;
7357 pfd
.iLayerType
= PFD_MAIN_PLANE
;
7358 format
= ChoosePixelFormat(hdc
, &pfd
);
7361 skip("no pixel format available\n");
7365 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
7367 skip("failed to set pixel format\n");
7371 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
7373 skip("failed to set pixel format on second window\n");
7376 ReleaseDC(window2
, hdc2
);
7381 ddraw
= create_ddraw();
7382 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7384 test_format
= GetPixelFormat(hdc
);
7385 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7387 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7390 skip("Failed to set cooperative level, hr %#x.\n", hr
);
7394 test_format
= GetPixelFormat(hdc
);
7395 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7399 hr
= IDirectDraw4_CreateClipper(ddraw
, 0, &clipper
, NULL
);
7400 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
7401 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
7402 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
7404 test_format
= GetPixelFormat(hdc
);
7405 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7407 test_format
= GetPixelFormat(hdc2
);
7408 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7411 memset(&ddsd
, 0, sizeof(ddsd
));
7412 ddsd
.dwSize
= sizeof(ddsd
);
7413 ddsd
.dwFlags
= DDSD_CAPS
;
7414 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7416 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
7417 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
7419 test_format
= GetPixelFormat(hdc
);
7420 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7424 test_format
= GetPixelFormat(hdc2
);
7425 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7430 hr
= IDirectDrawSurface4_SetClipper(primary
, clipper
);
7431 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
7433 test_format
= GetPixelFormat(hdc
);
7434 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7436 test_format
= GetPixelFormat(hdc2
);
7437 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7440 memset(&fx
, 0, sizeof(fx
));
7441 fx
.dwSize
= sizeof(fx
);
7442 hr
= IDirectDrawSurface4_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7443 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
7445 test_format
= GetPixelFormat(hdc
);
7446 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7450 test_format
= GetPixelFormat(hdc2
);
7451 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7455 if (primary
) IDirectDrawSurface4_Release(primary
);
7456 if (clipper
) IDirectDrawClipper_Release(clipper
);
7457 if (ddraw
) IDirectDraw4_Release(ddraw
);
7458 if (gl
) FreeLibrary(gl
);
7459 if (hdc
) ReleaseDC(window
, hdc
);
7460 if (hdc2
) ReleaseDC(window2
, hdc2
);
7461 if (window
) DestroyWindow(window
);
7462 if (window2
) DestroyWindow(window2
);
7465 static void test_create_surface_pitch(void)
7467 IDirectDrawSurface4
*surface
;
7468 DDSURFACEDESC2 surface_desc
;
7469 IDirectDraw4
*ddraw
;
7489 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7491 DDSD_PITCH
, 0x100, 0x100},
7492 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7493 DDSD_PITCH
, 0x104, DD_OK
,
7494 DDSD_PITCH
, 0x100, 0x100},
7495 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7496 DDSD_PITCH
, 0x0f8, DD_OK
,
7497 DDSD_PITCH
, 0x100, 0x100},
7498 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7499 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7501 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7503 DDSD_PITCH
, 0x100, 0x0fc},
7505 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7506 DDSD_PITCH
, 0x104, DD_OK
,
7507 DDSD_PITCH
, 0x100, 0x0fc},
7508 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7509 DDSD_PITCH
, 0x0f8, DD_OK
,
7510 DDSD_PITCH
, 0x100, 0x0fc},
7511 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7512 DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
7513 DDSD_PITCH
, 0x100, 0x0fc},
7514 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7515 DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
7517 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7518 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7519 DDSD_PITCH
, 0x100, 0x100},
7521 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7522 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fe, DDERR_INVALIDPARAMS
,
7524 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7525 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fc, DD_OK
,
7526 DDSD_PITCH
, 0x0fc, 0x0fc},
7527 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7528 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0f8, DDERR_INVALIDPARAMS
,
7530 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7531 DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x100, DDERR_INVALIDPARAMS
,
7533 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7534 DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x3f00, DDERR_INVALIDPARAMS
,
7537 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7538 DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, 0x100, DD_OK
,
7539 DDSD_PITCH
, 0x100, 0x100},
7540 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
7541 0, 0, DDERR_INVALIDCAPS
,
7543 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7545 DDSD_PITCH
, 0x100, 0 },
7546 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7547 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7549 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
7550 0, 0, DDERR_INVALIDCAPS
,
7553 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7555 DDSD_PITCH
, 0x100, 0 },
7556 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7557 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7558 DDSD_PITCH
, 0x100, 0 },
7560 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
7562 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7563 0, 0, 640, 480, 0, 0, 0, 0);
7564 ddraw
= create_ddraw();
7565 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7566 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7567 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7569 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
7571 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
7573 memset(&surface_desc
, 0, sizeof(surface_desc
));
7574 surface_desc
.dwSize
= sizeof(surface_desc
);
7575 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
7576 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
7577 surface_desc
.dwWidth
= 63;
7578 surface_desc
.dwHeight
= 63;
7579 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
7580 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7581 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7582 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7583 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7584 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7585 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7586 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7587 if (test_data
[i
].flags_in
& DDSD_LPSURFACE
)
7589 HRESULT expected_hr
= SUCCEEDED(test_data
[i
].hr
) ? DDERR_INVALIDPARAMS
: test_data
[i
].hr
;
7590 ok(hr
== expected_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, expected_hr
);
7591 surface_desc
.lpSurface
= mem
;
7592 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7594 if ((test_data
[i
].caps
& DDSCAPS_VIDEOMEMORY
) && hr
== DDERR_NODIRECTDRAWHW
)
7596 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
7600 memset(&surface_desc
, 0, sizeof(surface_desc
));
7601 surface_desc
.dwSize
= sizeof(surface_desc
);
7602 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
7603 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7604 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
7605 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7606 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
7607 /* The pitch for textures seems to be implementation specific. */
7608 if (!(test_data
[i
].caps
& DDSCAPS_TEXTURE
))
7610 if (is_ddraw64
&& test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
7611 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
7612 "Test %u: Got unexpected pitch %u, expected %u.\n",
7613 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
7615 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
7616 "Test %u: Got unexpected pitch %u, expected %u.\n",
7617 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
7619 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
7621 IDirectDrawSurface4_Release(surface
);
7624 HeapFree(GetProcessHeap(), 0, mem
);
7625 refcount
= IDirectDraw4_Release(ddraw
);
7626 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7627 DestroyWindow(window
);
7630 static void test_mipmap(void)
7632 IDirectDrawSurface4
*surface
, *surface2
;
7633 DDSURFACEDESC2 surface_desc
;
7634 IDirectDraw4
*ddraw
;
7639 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7648 DWORD mipmap_count_in
;
7650 DWORD mipmap_count_out
;
7654 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 3, DD_OK
, 3},
7655 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDPARAMS
, 0},
7656 {0, DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 1},
7657 {0, DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDCAPS
, 0},
7658 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 6},
7659 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 32, 64, 0, DD_OK
, 6},
7662 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7663 0, 0, 640, 480, 0, 0, 0, 0);
7664 ddraw
= create_ddraw();
7665 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7666 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7667 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7669 memset(&hal_caps
, 0, sizeof(hal_caps
));
7670 hal_caps
.dwSize
= sizeof(hal_caps
);
7671 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
7672 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7673 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7675 skip("Mipmapped textures not supported, skipping tests.\n");
7676 IDirectDraw4_Release(ddraw
);
7677 DestroyWindow(window
);
7681 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
7683 memset(&surface_desc
, 0, sizeof(surface_desc
));
7684 surface_desc
.dwSize
= sizeof(surface_desc
);
7685 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| tests
[i
].flags
;
7686 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
7687 surface_desc
.dwWidth
= tests
[i
].width
;
7688 surface_desc
.dwHeight
= tests
[i
].height
;
7689 if (tests
[i
].flags
& DDSD_MIPMAPCOUNT
)
7690 U2(surface_desc
).dwMipMapCount
= tests
[i
].mipmap_count_in
;
7691 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7692 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
7696 memset(&surface_desc
, 0, sizeof(surface_desc
));
7697 surface_desc
.dwSize
= sizeof(surface_desc
);
7698 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
7699 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7700 ok(surface_desc
.dwFlags
& DDSD_MIPMAPCOUNT
,
7701 "Test %u: Got unexpected flags %#x.\n", i
, surface_desc
.dwFlags
);
7702 ok(U2(surface_desc
).dwMipMapCount
== tests
[i
].mipmap_count_out
,
7703 "Test %u: Got unexpected mipmap count %u.\n", i
, U2(surface_desc
).dwMipMapCount
);
7705 if (U2(surface_desc
).dwMipMapCount
> 1)
7707 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &surface2
);
7708 ok(SUCCEEDED(hr
), "Test %u: Failed to get attached surface, hr %#x.\n", i
, hr
);
7710 memset(&surface_desc
, 0, sizeof(surface_desc
));
7711 surface_desc
.dwSize
= sizeof(surface_desc
);
7712 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7713 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
7714 memset(&surface_desc
, 0, sizeof(surface_desc
));
7715 surface_desc
.dwSize
= sizeof(surface_desc
);
7716 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
7717 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
7718 IDirectDrawSurface4_Unlock(surface2
, NULL
);
7719 IDirectDrawSurface4_Unlock(surface
, NULL
);
7721 IDirectDrawSurface4_Release(surface2
);
7724 IDirectDrawSurface4_Release(surface
);
7727 refcount
= IDirectDraw4_Release(ddraw
);
7728 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7729 DestroyWindow(window
);
7732 static void test_palette_complex(void)
7734 IDirectDrawSurface4
*surface
, *mipmap
, *tmp
;
7735 DDSURFACEDESC2 surface_desc
;
7736 IDirectDraw4
*ddraw
;
7737 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
7741 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7743 PALETTEENTRY palette_entries
[256];
7749 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7750 0, 0, 640, 480, 0, 0, 0, 0);
7751 ddraw
= create_ddraw();
7752 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7753 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7754 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7756 memset(&hal_caps
, 0, sizeof(hal_caps
));
7757 hal_caps
.dwSize
= sizeof(hal_caps
);
7758 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
7759 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7760 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7762 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7763 IDirectDraw4_Release(ddraw
);
7764 DestroyWindow(window
);
7768 memset(&surface_desc
, 0, sizeof(surface_desc
));
7769 surface_desc
.dwSize
= sizeof(surface_desc
);
7770 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7771 surface_desc
.dwWidth
= 128;
7772 surface_desc
.dwHeight
= 128;
7773 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7774 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7775 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7776 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7777 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7778 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7780 memset(palette_entries
, 0, sizeof(palette_entries
));
7781 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7782 palette_entries
, &palette
, NULL
);
7783 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7785 memset(palette_entries
, 0, sizeof(palette_entries
));
7786 palette_entries
[1].peRed
= 0xff;
7787 palette_entries
[1].peGreen
= 0x80;
7788 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7789 palette_entries
, &palette_mipmap
, NULL
);
7790 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7792 palette2
= (void *)0xdeadbeef;
7793 hr
= IDirectDrawSurface4_GetPalette(surface
, &palette2
);
7794 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
7795 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
7796 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
7797 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7798 hr
= IDirectDrawSurface4_GetPalette(surface
, &palette2
);
7799 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
7800 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
7801 IDirectDrawPalette_Release(palette2
);
7804 IDirectDrawSurface4_AddRef(mipmap
);
7805 for (i
= 0; i
< 7; ++i
)
7807 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7808 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
7809 palette2
= (void *)0xdeadbeef;
7810 hr
= IDirectDrawSurface4_GetPalette(tmp
, &palette2
);
7811 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7812 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
7814 hr
= IDirectDrawSurface4_SetPalette(tmp
, palette_mipmap
);
7815 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
7817 hr
= IDirectDrawSurface4_GetPalette(tmp
, &palette2
);
7818 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
7819 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
7820 IDirectDrawPalette_Release(palette2
);
7822 hr
= IDirectDrawSurface4_GetDC(tmp
, &dc
);
7823 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
7824 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
7825 ok(count
== 1, "Expected count 1, got %u.\n", count
);
7826 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
7827 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
7828 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
7829 hr
= IDirectDrawSurface4_ReleaseDC(tmp
, dc
);
7830 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
7832 IDirectDrawSurface4_Release(mipmap
);
7836 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7837 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7838 IDirectDrawSurface4_Release(mipmap
);
7839 refcount
= IDirectDrawSurface4_Release(surface
);
7840 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7841 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
7842 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7843 refcount
= IDirectDrawPalette_Release(palette
);
7844 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7846 refcount
= IDirectDraw4_Release(ddraw
);
7847 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7848 DestroyWindow(window
);
7851 static void test_p8_rgb_blit(void)
7853 IDirectDrawSurface4
*src
, *dst
;
7854 DDSURFACEDESC2 surface_desc
;
7855 IDirectDraw4
*ddraw
;
7856 IDirectDrawPalette
*palette
;
7860 PALETTEENTRY palette_entries
[256];
7862 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7863 static const D3DCOLOR expected
[] =
7865 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7866 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7870 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7871 0, 0, 640, 480, 0, 0, 0, 0);
7872 ddraw
= create_ddraw();
7873 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7874 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7875 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7877 memset(palette_entries
, 0, sizeof(palette_entries
));
7878 palette_entries
[1].peGreen
= 0xff;
7879 palette_entries
[2].peBlue
= 0xff;
7880 palette_entries
[3].peFlags
= 0xff;
7881 palette_entries
[4].peRed
= 0xff;
7882 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7883 palette_entries
, &palette
, NULL
);
7884 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7886 memset(&surface_desc
, 0, sizeof(surface_desc
));
7887 surface_desc
.dwSize
= sizeof(surface_desc
);
7888 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7889 surface_desc
.dwWidth
= 8;
7890 surface_desc
.dwHeight
= 1;
7891 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7892 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7893 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7894 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7895 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
7896 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7898 memset(&surface_desc
, 0, sizeof(surface_desc
));
7899 surface_desc
.dwSize
= sizeof(surface_desc
);
7900 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7901 surface_desc
.dwWidth
= 8;
7902 surface_desc
.dwHeight
= 1;
7903 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7904 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7905 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
7906 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7907 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7908 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7909 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7910 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
7911 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
7912 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7914 memset(&surface_desc
, 0, sizeof(surface_desc
));
7915 surface_desc
.dwSize
= sizeof(surface_desc
);
7916 hr
= IDirectDrawSurface4_Lock(src
, NULL
, &surface_desc
, 0, NULL
);
7917 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
7918 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
7919 hr
= IDirectDrawSurface4_Unlock(src
, NULL
);
7920 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
7922 hr
= IDirectDrawSurface4_SetPalette(src
, palette
);
7923 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7924 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
7925 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
7926 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
7927 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
7928 "Failed to blit, hr %#x.\n", hr
);
7932 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
7934 color
= get_surface_color(dst
, x
, 0);
7935 todo_wine
ok(compare_color(color
, expected
[x
], 0),
7936 "Pixel %u: Got color %#x, expected %#x.\n",
7937 x
, color
, expected
[x
]);
7941 IDirectDrawSurface4_Release(src
);
7942 IDirectDrawSurface4_Release(dst
);
7943 IDirectDrawPalette_Release(palette
);
7945 refcount
= IDirectDraw4_Release(ddraw
);
7946 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7947 DestroyWindow(window
);
7950 static void test_material(void)
7952 D3DMATERIALHANDLE mat_handle
, tmp
;
7953 IDirect3DMaterial3
*material
;
7954 IDirect3DViewport3
*viewport
;
7955 IDirect3DDevice3
*device
;
7956 IDirectDrawSurface4
*rt
;
7966 struct vec3 position
;
7972 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7973 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7974 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7975 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
7979 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7980 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7981 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7982 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
7988 D3DCOLOR expected_color
;
7992 {quad1
, TRUE
, 0x0000ff00},
7993 {quad2
, TRUE
, 0x0000ff00},
7994 {quad1
, FALSE
, 0x00ffffff},
7995 {quad2
, FALSE
, 0x00ff0000},
7997 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7999 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8000 0, 0, 640, 480, 0, 0, 0, 0);
8001 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8003 skip("Failed to create a 3D device, skipping test.\n");
8004 DestroyWindow(window
);
8008 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
8009 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8011 viewport
= create_viewport(device
, 0, 0, 640, 480);
8012 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
8013 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
8015 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
8016 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
8017 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
8019 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
8020 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
8021 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
8022 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
8023 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
8024 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
8025 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
8026 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
8027 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, 0);
8028 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
8029 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
8030 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
8031 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
8033 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
8035 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
,
8036 D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
8037 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8039 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
8040 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
8042 hr
= IDirect3DDevice3_BeginScene(device
);
8043 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8044 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
8045 D3DFVF_XYZ
| D3DFVF_NORMAL
| D3DFVF_DIFFUSE
, test_data
[i
].data
, 4, 0);
8046 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8047 hr
= IDirect3DDevice3_EndScene(device
);
8048 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8049 color
= get_surface_color(rt
, 320, 240);
8050 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
8051 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
8054 destroy_material(material
);
8055 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
8056 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
8057 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
8059 hr
= IDirect3DViewport3_SetBackground(viewport
, mat_handle
);
8060 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
8061 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
8062 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
8063 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
8064 ok(valid
, "Got unexpected valid %#x.\n", valid
);
8065 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8066 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8067 color
= get_surface_color(rt
, 320, 240);
8068 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8070 hr
= IDirect3DViewport3_SetBackground(viewport
, 0);
8071 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8072 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
8073 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
8074 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
8075 ok(valid
, "Got unexpected valid %#x.\n", valid
);
8076 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8077 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8078 color
= get_surface_color(rt
, 320, 240);
8079 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8081 destroy_viewport(device
, viewport
);
8082 viewport
= create_viewport(device
, 0, 0, 640, 480);
8084 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
8085 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
8086 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
8087 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
8088 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8089 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8090 color
= get_surface_color(rt
, 320, 240);
8091 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
8093 destroy_viewport(device
, viewport
);
8094 destroy_material(material
);
8095 IDirectDrawSurface4_Release(rt
);
8096 refcount
= IDirect3DDevice3_Release(device
);
8097 ok(!refcount
, "Device has %u references left.\n", refcount
);
8098 DestroyWindow(window
);
8101 static void test_palette_gdi(void)
8103 IDirectDrawSurface4
*surface
, *primary
;
8104 DDSURFACEDESC2 surface_desc
;
8105 IDirectDraw4
*ddraw
;
8106 IDirectDrawPalette
*palette
, *palette2
;
8110 PALETTEENTRY palette_entries
[256];
8113 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
8114 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
8115 * not the point of this test. */
8116 static const RGBQUAD expected1
[] =
8118 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8119 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
8121 static const RGBQUAD expected2
[] =
8123 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8124 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
8126 static const RGBQUAD expected3
[] =
8128 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
8129 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
8131 HPALETTE ddraw_palette_handle
;
8132 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
8133 RGBQUAD rgbquad
[255];
8134 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
8136 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8137 0, 0, 640, 480, 0, 0, 0, 0);
8138 ddraw
= create_ddraw();
8139 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8140 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8141 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8143 memset(&surface_desc
, 0, sizeof(surface_desc
));
8144 surface_desc
.dwSize
= sizeof(surface_desc
);
8145 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8146 surface_desc
.dwWidth
= 16;
8147 surface_desc
.dwHeight
= 16;
8148 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8149 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8150 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
8151 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
8152 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8153 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8155 /* Avoid colors from the Windows default palette. */
8156 memset(palette_entries
, 0, sizeof(palette_entries
));
8157 palette_entries
[1].peRed
= 0x01;
8158 palette_entries
[2].peGreen
= 0x02;
8159 palette_entries
[3].peBlue
= 0x03;
8160 palette_entries
[4].peRed
= 0x13;
8161 palette_entries
[4].peGreen
= 0x14;
8162 palette_entries
[4].peBlue
= 0x15;
8163 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
8164 palette_entries
, &palette
, NULL
);
8165 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8167 /* If there is no palette assigned and the display mode is not 8 bpp, some
8168 * drivers refuse to create a DC while others allow it. If a DC is created,
8169 * the DIB color table is uninitialized and contains random colors. No error
8170 * is generated when trying to read pixels and random garbage is returned.
8172 * The most likely explanation is that if the driver creates a DC, it (or
8173 * the higher-level runtime) uses GetSystemPaletteEntries to find the
8174 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
8175 * contains uninitialized garbage. See comments below for the P8 case. */
8177 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8178 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8179 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8180 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8181 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
8182 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
8183 "Got unexpected palette %p, expected %p.\n",
8184 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
8186 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8187 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8188 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
8190 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
8191 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8192 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8193 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
8195 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8197 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8198 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8199 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8202 /* Update the palette while the DC is in use. This does not modify the DC. */
8203 palette_entries
[4].peRed
= 0x23;
8204 palette_entries
[4].peGreen
= 0x24;
8205 palette_entries
[4].peBlue
= 0x25;
8206 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
8207 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
8209 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
8210 ok(i
== 1, "Expected count 1, got %u.\n", i
);
8211 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
8212 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8213 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
8214 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
8216 /* Neither does re-setting the palette. */
8217 hr
= IDirectDrawSurface4_SetPalette(surface
, NULL
);
8218 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8219 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8220 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8222 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
8223 ok(i
== 1, "Expected count 1, got %u.\n", i
);
8224 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
8225 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8226 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
8227 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
8229 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8230 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8232 /* Refresh the DC. This updates the palette. */
8233 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8234 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8235 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8236 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8237 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8239 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8240 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8241 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8242 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8244 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8246 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8247 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8248 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8250 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8251 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8253 refcount
= IDirectDrawSurface4_Release(surface
);
8254 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8256 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8258 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8259 IDirectDrawPalette_Release(palette
);
8260 IDirectDraw4_Release(ddraw
);
8261 DestroyWindow(window
);
8264 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
8265 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
8266 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8268 memset(&surface_desc
, 0, sizeof(surface_desc
));
8269 surface_desc
.dwSize
= sizeof(surface_desc
);
8270 surface_desc
.dwFlags
= DDSD_CAPS
;
8271 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8272 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
8273 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8275 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
8276 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8277 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
8278 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8279 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
8280 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
8281 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
8282 "Got unexpected palette %p, expected %p.\n",
8283 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
8284 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
8286 /* The primary uses the system palette. In exclusive mode, the system palette matches
8287 * the ddraw palette attached to the primary, so the result is what you would expect
8288 * from a regular surface. Tests for the interaction between the ddraw palette and
8289 * the system palette are not included pending an application that depends on this.
8290 * The relation between those causes problems on Windows Vista and newer for games
8291 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
8292 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8293 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8294 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8296 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8297 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8298 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8299 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8301 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8303 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8304 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8305 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8307 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
8308 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8310 memset(&surface_desc
, 0, sizeof(surface_desc
));
8311 surface_desc
.dwSize
= sizeof(surface_desc
);
8312 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8313 surface_desc
.dwWidth
= 16;
8314 surface_desc
.dwHeight
= 16;
8315 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8316 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8317 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8319 /* Here the offscreen surface appears to use the primary's palette,
8320 * but in all likelihood it is actually the system palette. */
8321 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8322 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8323 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8324 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8325 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8327 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8328 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8329 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8330 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8332 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8334 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8335 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8336 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8338 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8339 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8341 /* On real hardware a change to the primary surface's palette applies immediately,
8342 * even on device contexts from offscreen surfaces that do not have their own
8343 * palette. On the testbot VMs this is not the case. Don't test this until we
8344 * know of an application that depends on this. */
8346 memset(palette_entries
, 0, sizeof(palette_entries
));
8347 palette_entries
[1].peBlue
= 0x40;
8348 palette_entries
[2].peRed
= 0x40;
8349 palette_entries
[3].peGreen
= 0x40;
8350 palette_entries
[4].peRed
= 0x12;
8351 palette_entries
[4].peGreen
= 0x34;
8352 palette_entries
[4].peBlue
= 0x56;
8353 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
8354 palette_entries
, &palette2
, NULL
);
8355 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8356 hr
= IDirectDrawSurface4_SetPalette(surface
, palette2
);
8357 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8359 /* A palette assigned to the offscreen surface overrides the primary / system
8361 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8362 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8363 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8364 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8365 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
8367 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
8368 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8369 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8370 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
8372 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8374 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8375 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8376 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8378 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8379 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8381 refcount
= IDirectDrawSurface4_Release(surface
);
8382 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8384 /* The Windows 8 testbot keeps extra references to the primary and
8385 * backbuffer while in 8 bpp mode. */
8386 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
8387 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8389 refcount
= IDirectDrawSurface4_Release(primary
);
8390 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8391 refcount
= IDirectDrawPalette_Release(palette2
);
8392 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8393 refcount
= IDirectDrawPalette_Release(palette
);
8394 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8395 refcount
= IDirectDraw4_Release(ddraw
);
8396 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8397 DestroyWindow(window
);
8400 static void test_palette_alpha(void)
8402 IDirectDrawSurface4
*surface
;
8403 DDSURFACEDESC2 surface_desc
;
8404 IDirectDraw4
*ddraw
;
8405 IDirectDrawPalette
*palette
;
8409 PALETTEENTRY palette_entries
[256];
8414 BOOL attach_allowed
;
8419 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
8420 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
8421 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
8424 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8425 0, 0, 640, 480, 0, 0, 0, 0);
8426 ddraw
= create_ddraw();
8427 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8428 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8430 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8431 IDirectDraw4_Release(ddraw
);
8432 DestroyWindow(window
);
8435 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8436 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8438 memset(palette_entries
, 0, sizeof(palette_entries
));
8439 palette_entries
[1].peFlags
= 0x42;
8440 palette_entries
[2].peFlags
= 0xff;
8441 palette_entries
[3].peFlags
= 0x80;
8442 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
8443 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8445 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8446 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8447 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8448 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8449 palette_entries
[0].peFlags
);
8450 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8451 palette_entries
[1].peFlags
);
8452 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8453 palette_entries
[2].peFlags
);
8454 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8455 palette_entries
[3].peFlags
);
8457 IDirectDrawPalette_Release(palette
);
8459 memset(palette_entries
, 0, sizeof(palette_entries
));
8460 palette_entries
[1].peFlags
= 0x42;
8461 palette_entries
[1].peRed
= 0xff;
8462 palette_entries
[2].peFlags
= 0xff;
8463 palette_entries
[3].peFlags
= 0x80;
8464 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
8465 palette_entries
, &palette
, NULL
);
8466 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8468 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8469 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8470 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8471 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8472 palette_entries
[0].peFlags
);
8473 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8474 palette_entries
[1].peFlags
);
8475 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8476 palette_entries
[2].peFlags
);
8477 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8478 palette_entries
[3].peFlags
);
8480 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
8482 memset(&surface_desc
, 0, sizeof(surface_desc
));
8483 surface_desc
.dwSize
= sizeof(surface_desc
);
8484 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
8485 surface_desc
.dwWidth
= 128;
8486 surface_desc
.dwHeight
= 128;
8487 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
8488 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8489 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8491 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8492 if (test_data
[i
].attach_allowed
)
8493 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8495 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8503 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8504 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8505 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
8506 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
8507 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8508 rgbquad
.rgbRed
, test_data
[i
].name
);
8509 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8510 rgbquad
.rgbGreen
, test_data
[i
].name
);
8511 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8512 rgbquad
.rgbBlue
, test_data
[i
].name
);
8513 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8514 rgbquad
.rgbReserved
, test_data
[i
].name
);
8515 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8516 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8518 IDirectDrawSurface4_Release(surface
);
8521 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8522 memset(&surface_desc
, 0, sizeof(surface_desc
));
8523 surface_desc
.dwSize
= sizeof(surface_desc
);
8524 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8525 surface_desc
.dwWidth
= 128;
8526 surface_desc
.dwHeight
= 128;
8527 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8528 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8529 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8530 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
8531 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8532 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8533 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8534 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8535 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8536 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8537 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
8538 IDirectDrawSurface4_Release(surface
);
8540 /* The Windows 8 testbot keeps extra references to the primary
8541 * while in 8 bpp mode. */
8542 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
8543 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8545 refcount
= IDirectDrawPalette_Release(palette
);
8546 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8547 refcount
= IDirectDraw4_Release(ddraw
);
8548 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8549 DestroyWindow(window
);
8552 static void test_vb_writeonly(void)
8554 IDirect3DDevice3
*device
;
8556 IDirect3DVertexBuffer
*buffer
;
8559 D3DVERTEXBUFFERDESC desc
;
8561 static const struct vec4 quad
[] =
8563 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
8564 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
8565 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
8566 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
8569 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8570 0, 0, 640, 480, 0, 0, 0, 0);
8572 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8574 skip("Failed to create a 3D device, skipping test.\n");
8575 DestroyWindow(window
);
8579 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
8580 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
8582 memset(&desc
, 0, sizeof(desc
));
8583 desc
.dwSize
= sizeof(desc
);
8584 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
8585 desc
.dwFVF
= D3DFVF_XYZRHW
;
8586 desc
.dwNumVertices
= sizeof(quad
) / sizeof(*quad
);
8587 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0, NULL
);
8588 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
8590 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, &ptr
, NULL
);
8591 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8592 memcpy(ptr
, quad
, sizeof(quad
));
8593 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8594 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8596 hr
= IDirect3DDevice3_BeginScene(device
);
8597 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8598 hr
= IDirect3DDevice3_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
8599 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8600 hr
= IDirect3DDevice3_EndScene(device
);
8601 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8603 hr
= IDirect3DVertexBuffer_Lock(buffer
, 0, &ptr
, NULL
);
8604 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8605 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8606 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8607 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8609 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_READONLY
, &ptr
, NULL
);
8610 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8611 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8612 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8613 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8615 IDirect3DVertexBuffer_Release(buffer
);
8616 IDirect3D3_Release(d3d
);
8617 IDirect3DDevice3_Release(device
);
8618 DestroyWindow(window
);
8621 static void test_lost_device(void)
8623 IDirectDrawSurface4
*surface
;
8624 DDSURFACEDESC2 surface_desc
;
8625 HWND window1
, window2
;
8626 IDirectDraw4
*ddraw
;
8631 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8632 0, 0, 640, 480, 0, 0, 0, 0);
8633 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8634 0, 0, 640, 480, 0, 0, 0, 0);
8635 ddraw
= create_ddraw();
8636 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8637 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8638 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8640 memset(&surface_desc
, 0, sizeof(surface_desc
));
8641 surface_desc
.dwSize
= sizeof(surface_desc
);
8642 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8643 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8644 U5(surface_desc
).dwBackBufferCount
= 1;
8645 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8646 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8648 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8649 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8650 hr
= IDirectDrawSurface4_IsLost(surface
);
8651 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8652 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8653 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8655 ret
= SetForegroundWindow(GetDesktopWindow());
8656 ok(ret
, "Failed to set foreground window.\n");
8657 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8658 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8659 hr
= IDirectDrawSurface4_IsLost(surface
);
8660 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8661 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8662 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8664 ret
= SetForegroundWindow(window1
);
8665 ok(ret
, "Failed to set foreground window.\n");
8666 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8667 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8668 hr
= IDirectDrawSurface4_IsLost(surface
);
8669 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8670 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8671 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8673 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
8674 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8675 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8676 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8677 hr
= IDirectDrawSurface4_IsLost(surface
);
8678 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8679 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8680 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8682 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8683 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8684 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8685 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8686 hr
= IDirectDrawSurface4_IsLost(surface
);
8687 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8688 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8689 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8691 /* Trying to restore the primary will crash, probably because flippable
8692 * surfaces can't exist in DDSCL_NORMAL. */
8693 IDirectDrawSurface4_Release(surface
);
8694 memset(&surface_desc
, 0, sizeof(surface_desc
));
8695 surface_desc
.dwSize
= sizeof(surface_desc
);
8696 surface_desc
.dwFlags
= DDSD_CAPS
;
8697 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8698 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8699 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8701 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8702 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8703 hr
= IDirectDrawSurface4_IsLost(surface
);
8704 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8706 ret
= SetForegroundWindow(GetDesktopWindow());
8707 ok(ret
, "Failed to set foreground window.\n");
8708 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8709 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8710 hr
= IDirectDrawSurface4_IsLost(surface
);
8711 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8713 ret
= SetForegroundWindow(window1
);
8714 ok(ret
, "Failed to set foreground window.\n");
8715 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8716 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8717 hr
= IDirectDrawSurface4_IsLost(surface
);
8718 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8720 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8721 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8722 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8723 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8724 hr
= IDirectDrawSurface4_IsLost(surface
);
8725 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8727 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
8728 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8729 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8730 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8731 hr
= IDirectDrawSurface4_IsLost(surface
);
8732 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8734 IDirectDrawSurface4_Release(surface
);
8735 memset(&surface_desc
, 0, sizeof(surface_desc
));
8736 surface_desc
.dwSize
= sizeof(surface_desc
);
8737 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8738 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8739 U5(surface_desc
).dwBackBufferCount
= 1;
8740 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8741 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8743 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8744 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8745 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8746 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8747 hr
= IDirectDrawSurface4_IsLost(surface
);
8748 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8749 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8750 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8752 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8753 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8754 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8755 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8756 hr
= IDirectDrawSurface4_IsLost(surface
);
8757 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8758 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8759 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8761 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8762 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8763 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8764 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8765 hr
= IDirectDrawSurface4_IsLost(surface
);
8766 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8767 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8768 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8770 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
8771 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8772 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8773 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8774 hr
= IDirectDrawSurface4_IsLost(surface
);
8775 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8776 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8777 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8779 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8780 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8781 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8782 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8783 hr
= IDirectDrawSurface4_IsLost(surface
);
8784 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8785 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8786 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8788 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8789 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8790 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8791 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8792 hr
= IDirectDrawSurface4_IsLost(surface
);
8793 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8794 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8795 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8797 IDirectDrawSurface4_Release(surface
);
8798 refcount
= IDirectDraw4_Release(ddraw
);
8799 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8800 DestroyWindow(window2
);
8801 DestroyWindow(window1
);
8804 static void test_surface_desc_lock(void)
8806 IDirectDrawSurface4
*surface
;
8807 DDSURFACEDESC2 surface_desc
;
8808 IDirectDraw4
*ddraw
;
8813 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8814 0, 0, 640, 480, 0, 0, 0, 0);
8815 ddraw
= create_ddraw();
8816 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8817 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8818 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8820 memset(&surface_desc
, 0, sizeof(surface_desc
));
8821 surface_desc
.dwSize
= sizeof(surface_desc
);
8822 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8823 surface_desc
.dwWidth
= 16;
8824 surface_desc
.dwHeight
= 16;
8825 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8826 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8827 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8829 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8830 surface_desc
.dwSize
= sizeof(surface_desc
);
8831 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8832 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8833 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8835 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8836 surface_desc
.dwSize
= sizeof(surface_desc
);
8837 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
8838 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8839 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
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
);
8845 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
8846 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8848 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8849 surface_desc
.dwSize
= sizeof(surface_desc
);
8850 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8851 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8852 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8854 IDirectDrawSurface4_Release(surface
);
8855 refcount
= IDirectDraw4_Release(ddraw
);
8856 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8857 DestroyWindow(window
);
8860 static void test_signed_formats(void)
8863 IDirect3DDevice3
*device
;
8865 IDirectDraw4
*ddraw
;
8866 IDirectDrawSurface4
*surface
, *rt
;
8867 IDirect3DTexture2
*texture
;
8868 IDirect3DViewport3
*viewport
;
8869 DDSURFACEDESC2 surface_desc
;
8872 D3DCOLOR color
, expected_color
;
8876 struct vec3 position
;
8877 struct vec2 texcoord
;
8881 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
8882 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
8883 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
8884 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
8886 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
8887 * of these values. */
8888 static const USHORT content_v8u8
[4][4] =
8890 {0x0000, 0x7f7f, 0x8880, 0x0000},
8891 {0x0080, 0x8000, 0x7f00, 0x007f},
8892 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
8893 {0x4444, 0xc0c0, 0xa066, 0x22e0},
8895 static const DWORD content_x8l8v8u8
[4][4] =
8897 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
8898 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
8899 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
8900 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
8902 static const USHORT content_l6v5u5
[4][4] =
8904 {0x0000, 0xfdef, 0x0230, 0xfc00},
8905 {0x0010, 0x0200, 0x01e0, 0x000f},
8906 {0x4067, 0x53b9, 0x0421, 0xffff},
8907 {0x8108, 0x0318, 0xc28c, 0x909c},
8912 const void *content
;
8915 unsigned int slop
, slop_broken
;
8916 DDPIXELFORMAT format
;
8921 "D3DFMT_V8U8", content_v8u8
, sizeof(WORD
), FALSE
, 1, 0,
8923 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
, 0,
8924 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
8928 "D3DFMT_X8L8V8U8", content_x8l8v8u8
, sizeof(DWORD
), TRUE
, 1, 0,
8930 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
8931 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
8935 "D3DFMT_L6V5U5", content_l6v5u5
, sizeof(WORD
), TRUE
, 4, 7,
8937 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
8938 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
8942 /* No V16U16 or Q8W8V8U8 support in ddraw. */
8944 static const D3DCOLOR expected_colors
[4][4] =
8946 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
8947 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
8948 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
8949 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
8951 unsigned int i
, width
, x
, y
;
8952 D3DDEVICEDESC device_desc
, hel_desc
;
8954 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8955 0, 0, 640, 480, 0, 0, 0, 0);
8957 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8959 skip("Failed to create a 3D device, skipping test.\n");
8960 DestroyWindow(window
);
8964 memset(&device_desc
, 0, sizeof(device_desc
));
8965 device_desc
.dwSize
= sizeof(device_desc
);
8966 memset(&hel_desc
, 0, sizeof(hel_desc
));
8967 hel_desc
.dwSize
= sizeof(hel_desc
);
8968 hr
= IDirect3DDevice3_GetCaps(device
, &device_desc
, &hel_desc
);
8969 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8970 if (!(device_desc
.dwTextureOpCaps
& D3DTEXOPCAPS_BLENDFACTORALPHA
))
8972 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
8976 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
8977 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
8978 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
8979 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
8980 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
8981 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8983 memset(&surface_desc
, 0, sizeof(surface_desc
));
8984 surface_desc
.dwSize
= sizeof(surface_desc
);
8985 hr
= IDirectDrawSurface4_GetSurfaceDesc(rt
, &surface_desc
);
8986 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8987 viewport
= create_viewport(device
, 0, 0, surface_desc
.dwWidth
, surface_desc
.dwHeight
);
8988 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
8989 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
8990 U1(clear_rect
).x1
= 0;
8991 U2(clear_rect
).y1
= 0;
8992 U3(clear_rect
).x2
= surface_desc
.dwWidth
;
8993 U4(clear_rect
).y2
= surface_desc
.dwHeight
;
8995 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8996 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8998 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
8999 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x80ffffff);
9000 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9001 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BLENDFACTORALPHA
);
9002 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9003 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9004 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9005 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
9006 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9008 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
9010 for (width
= 1; width
< 5; width
+= 3)
9012 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
9013 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
9015 memset(&surface_desc
, 0, sizeof(surface_desc
));
9016 surface_desc
.dwSize
= sizeof(surface_desc
);
9017 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
9018 surface_desc
.dwWidth
= width
;
9019 surface_desc
.dwHeight
= 4;
9020 U4(surface_desc
).ddpfPixelFormat
= formats
[i
].format
;
9021 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
9022 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9025 skip("%s textures not supported, skipping.\n", formats
[i
].name
);
9028 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9030 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
9031 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture2 interface, hr %#x, format %s.\n",
9032 hr
, formats
[i
].name
);
9033 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
9034 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9035 IDirect3DTexture2_Release(texture
);
9037 memset(&surface_desc
, 0, sizeof(surface_desc
));
9038 surface_desc
.dwSize
= sizeof(surface_desc
);
9039 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
9040 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9041 for (y
= 0; y
< 4; y
++)
9043 memcpy((char *)surface_desc
.lpSurface
+ y
* U1(surface_desc
).lPitch
,
9044 (char *)formats
[i
].content
+ y
* 4 * formats
[i
].pixel_size
,
9045 width
* formats
[i
].pixel_size
);
9047 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9048 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9050 hr
= IDirect3DDevice3_BeginScene(device
);
9051 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9052 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
9053 D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
9054 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9055 hr
= IDirect3DDevice3_EndScene(device
);
9056 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9058 for (y
= 0; y
< 4; y
++)
9060 for (x
= 0; x
< width
; x
++)
9062 expected_color
= expected_colors
[y
][x
];
9063 if (!formats
[i
].blue
)
9064 expected_color
|= 0x000000ff;
9066 color
= get_surface_color(rt
, 80 + 160 * x
, 60 + 120 * y
);
9067 ok(compare_color(color
, expected_color
, formats
[i
].slop
)
9068 || broken(compare_color(color
, expected_color
, formats
[i
].slop_broken
)),
9069 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9070 expected_color
, color
, formats
[i
].name
, x
, y
);
9074 IDirectDrawSurface4_Release(surface
);
9078 destroy_viewport(device
, viewport
);
9079 IDirectDrawSurface4_Release(rt
);
9080 IDirectDraw4_Release(ddraw
);
9081 IDirect3D3_Release(d3d
);
9084 refcount
= IDirect3DDevice3_Release(device
);
9085 ok(!refcount
, "Device has %u references left.\n", refcount
);
9086 DestroyWindow(window
);
9089 static void test_color_fill(void)
9092 IDirect3DDevice3
*device
;
9094 IDirectDraw4
*ddraw
;
9095 IDirectDrawSurface4
*surface
, *surface2
;
9096 DDSURFACEDESC2 surface_desc
;
9097 DDPIXELFORMAT z_fmt
;
9102 RECT rect
= {5, 5, 7, 7};
9104 DWORD supported_fmts
= 0, num_fourcc_codes
, *fourcc_codes
;
9109 HRESULT colorfill_hr
, depthfill_hr
;
9114 DDPIXELFORMAT format
;
9119 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9120 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9122 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9123 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9127 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9128 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9130 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9131 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9135 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9136 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
9138 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9139 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9143 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9144 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
9146 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9147 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9151 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
9152 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "managed texture RGB", 0xdeadbeef, TRUE
,
9154 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9155 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9159 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
, 0,
9160 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
9161 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9164 DDSCAPS_ZBUFFER
| DDSCAPS_SYSTEMMEMORY
, 0,
9165 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "sysmem zbuffer", 0, FALSE
,
9166 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9169 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9170 * different afterwards. DX9+ GPUs set one of the two luminance values
9171 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9172 * value they set. r200 (dx8) just sets the entire block to the clear
9174 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9175 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
9177 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9178 {0}, {0}, {0}, {0}, {0}
9182 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9183 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
9185 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9186 {0}, {0}, {0}, {0}, {0}
9190 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9191 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
9193 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9194 {0}, {0}, {0}, {0}, {0}
9198 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9199 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
9201 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9202 {0}, {0}, {0}, {0}, {0}
9206 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9207 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
9209 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9210 {0}, {0}, {0}, {0}, {0}
9214 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9215 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
9217 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9218 {0}, {0}, {0}, {0}, {0}
9222 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9223 * surface works, presumably because it is handled by the runtime instead of
9225 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9226 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
9228 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9229 {8}, {0}, {0}, {0}, {0}
9233 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9234 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
9236 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9237 {8}, {0}, {0}, {0}, {0}
9249 {SRCCOPY
, "SRCCOPY", DD_OK
},
9250 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
9251 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
9252 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
9253 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
9254 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
9255 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
9256 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
9257 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
9258 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
9259 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
9260 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
9261 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
9262 {BLACKNESS
, "BLACKNESS", DD_OK
},
9263 {WHITENESS
, "WHITENESS", DD_OK
},
9264 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
9267 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9268 0, 0, 640, 480, 0, 0, 0, 0);
9270 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9272 skip("Failed to create a 3D device, skipping test.\n");
9273 DestroyWindow(window
);
9277 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9278 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9279 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9280 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9282 memset(&z_fmt
, 0, sizeof(z_fmt
));
9283 IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
9285 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9287 IDirect3DDevice3_EnumTextureFormats(device
, test_block_formats_creation_cb
, &supported_fmts
);
9288 if (!(supported_fmts
& SUPPORT_DXT1
))
9289 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9291 IDirect3D3_Release(d3d
);
9293 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
9294 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9295 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
9296 num_fourcc_codes
* sizeof(*fourcc_codes
));
9299 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
9300 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9301 for (i
= 0; i
< num_fourcc_codes
; i
++)
9303 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9304 supported_fmts
|= SUPPORT_YUY2
;
9305 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9306 supported_fmts
|= SUPPORT_UYVY
;
9308 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
9310 memset(&hal_caps
, 0, sizeof(hal_caps
));
9311 hal_caps
.dwSize
= sizeof(hal_caps
);
9312 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
9313 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9315 if (!(supported_fmts
& (SUPPORT_YUY2
| SUPPORT_UYVY
)) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9316 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9318 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
9320 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9321 memset(&fx
, 0, sizeof(fx
));
9322 fx
.dwSize
= sizeof(fx
);
9323 U5(fx
).dwFillColor
= 0xdeadbeef;
9325 memset(&surface_desc
, 0, sizeof(surface_desc
));
9326 surface_desc
.dwSize
= sizeof(surface_desc
);
9327 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9328 surface_desc
.dwWidth
= 64;
9329 surface_desc
.dwHeight
= 64;
9330 U4(surface_desc
).ddpfPixelFormat
= tests
[i
].format
;
9331 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
9332 surface_desc
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
9334 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('D','X','T','1') && !(supported_fmts
& SUPPORT_DXT1
))
9336 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !(supported_fmts
& SUPPORT_YUY2
))
9338 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !(supported_fmts
& SUPPORT_UYVY
))
9340 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9343 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
9348 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9351 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9352 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9354 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9355 todo_wine_if (tests
[i
].format
.dwFourCC
)
9356 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9357 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9359 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9360 todo_wine_if (tests
[i
].format
.dwFourCC
)
9361 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9362 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9364 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9366 memset(&surface_desc
, 0, sizeof(surface_desc
));
9367 surface_desc
.dwSize
= sizeof(surface_desc
);
9368 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9369 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9370 color
= surface_desc
.lpSurface
;
9371 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9372 *color
, tests
[i
].result
, tests
[i
].name
);
9373 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9374 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9377 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9378 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9379 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9380 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9381 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9382 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9384 U5(fx
).dwFillColor
= 0xdeadbeef;
9385 fx
.dwROP
= BLACKNESS
;
9386 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9387 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9388 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9389 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9390 U5(fx
).dwFillColor
, tests
[i
].name
);
9392 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9394 memset(&surface_desc
, 0, sizeof(surface_desc
));
9395 surface_desc
.dwSize
= sizeof(surface_desc
);
9396 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9397 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9398 color
= surface_desc
.lpSurface
;
9399 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9400 *color
, tests
[i
].name
);
9401 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9402 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9405 fx
.dwROP
= WHITENESS
;
9406 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9407 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9408 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9409 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9410 U5(fx
).dwFillColor
, tests
[i
].name
);
9412 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9414 memset(&surface_desc
, 0, sizeof(surface_desc
));
9415 surface_desc
.dwSize
= sizeof(surface_desc
);
9416 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9417 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9418 color
= surface_desc
.lpSurface
;
9419 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9420 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9421 *color
, tests
[i
].name
);
9422 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9423 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9426 IDirectDrawSurface4_Release(surface
);
9429 memset(&fx
, 0, sizeof(fx
));
9430 fx
.dwSize
= sizeof(fx
);
9431 U5(fx
).dwFillColor
= 0xdeadbeef;
9432 fx
.dwROP
= WHITENESS
;
9434 memset(&surface_desc
, 0, sizeof(surface_desc
));
9435 surface_desc
.dwSize
= sizeof(surface_desc
);
9436 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9437 surface_desc
.dwWidth
= 64;
9438 surface_desc
.dwHeight
= 64;
9439 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9440 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9441 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9442 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9443 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9444 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9445 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
9446 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9447 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9448 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9449 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9452 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
9453 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9454 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
9455 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9457 /* Unused source rectangle. */
9458 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9459 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9460 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9461 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9463 /* Unused source surface. */
9464 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9465 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9466 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9467 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9468 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9469 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9470 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9471 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9473 /* Inverted destination or source rectangle. */
9474 SetRect(&rect
, 5, 7, 7, 5);
9475 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9476 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9477 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9478 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9479 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9480 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9481 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9482 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9483 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9484 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9486 /* Negative rectangle. */
9487 SetRect(&rect
, -1, -1, 5, 5);
9488 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9489 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9490 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9491 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9492 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9493 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9494 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9495 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9496 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9497 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9499 /* Out of bounds rectangle. */
9500 SetRect(&rect
, 0, 0, 65, 65);
9501 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9502 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9503 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9504 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9506 /* Combine multiple flags. */
9507 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9508 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9509 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9510 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9511 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9512 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9514 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
9516 fx
.dwROP
= rops
[i
].rop
;
9517 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9518 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
9521 IDirectDrawSurface4_Release(surface2
);
9522 IDirectDrawSurface4_Release(surface
);
9527 memset(&surface_desc
, 0, sizeof(surface_desc
));
9528 surface_desc
.dwSize
= sizeof(surface_desc
);
9529 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9530 surface_desc
.dwWidth
= 64;
9531 surface_desc
.dwHeight
= 64;
9532 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9533 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
9534 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9535 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9536 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9537 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9540 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
9541 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9543 /* Unused source rectangle. */
9544 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9545 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9547 /* Unused source surface. */
9548 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9549 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9550 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9551 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9553 /* Inverted destination or source rectangle. */
9554 SetRect(&rect
, 5, 7, 7, 5);
9555 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9556 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9557 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9558 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9559 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9560 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9561 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9562 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9564 /* Negative rectangle. */
9565 SetRect(&rect
, -1, -1, 5, 5);
9566 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9567 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9568 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9569 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9570 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9571 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9572 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9573 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9575 /* Out of bounds rectangle. */
9576 SetRect(&rect
, 0, 0, 65, 65);
9577 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9578 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9580 /* Combine multiple flags. */
9581 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9582 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9584 IDirectDrawSurface4_Release(surface2
);
9585 IDirectDrawSurface4_Release(surface
);
9588 IDirectDraw4_Release(ddraw
);
9589 refcount
= IDirect3DDevice3_Release(device
);
9590 ok(!refcount
, "Device has %u references left.\n", refcount
);
9591 DestroyWindow(window
);
9594 static void test_texcoordindex(void)
9599 struct vec2 texcoord1
;
9600 struct vec2 texcoord2
;
9601 struct vec2 texcoord3
;
9605 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}, {0.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9606 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}, {0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
9607 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9608 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 0.0f
}},
9610 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_TEX3
;
9611 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9612 IDirect3DDevice3
*device
;
9614 IDirectDraw4
*ddraw
;
9615 IDirectDrawSurface4
*rt
;
9616 IDirect3DViewport3
*viewport
;
9619 IDirectDrawSurface4
*surface1
, *surface2
;
9620 IDirect3DTexture2
*texture1
, *texture2
;
9621 DDSURFACEDESC2 surface_desc
;
9626 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9627 0, 0, 640, 480, 0, 0, 0, 0);
9628 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9630 skip("Failed to create a 3D device, skipping test.\n");
9631 DestroyWindow(window
);
9635 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9636 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
9637 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9638 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
9639 IDirect3D3_Release(d3d
);
9641 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
9642 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9644 memset(&surface_desc
, 0, sizeof(surface_desc
));
9645 surface_desc
.dwSize
= sizeof(surface_desc
);
9646 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9647 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9648 surface_desc
.dwWidth
= 2;
9649 surface_desc
.dwHeight
= 2;
9650 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9651 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
9652 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9653 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9654 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9655 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9656 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
9657 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
9658 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9659 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9660 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9662 memset(&surface_desc
, 0, sizeof(surface_desc
));
9663 surface_desc
.dwSize
= sizeof(surface_desc
);
9664 hr
= IDirectDrawSurface4_Lock(surface1
, 0, &surface_desc
, 0, NULL
);
9665 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9666 ptr
= surface_desc
.lpSurface
;
9667 ptr
[0] = 0xff000000;
9668 ptr
[1] = 0xff00ff00;
9669 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9670 ptr
[0] = 0xff0000ff;
9671 ptr
[1] = 0xff00ffff;
9672 hr
= IDirectDrawSurface4_Unlock(surface1
, NULL
);
9673 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9675 memset(&surface_desc
, 0, sizeof(surface_desc
));
9676 surface_desc
.dwSize
= sizeof(surface_desc
);
9677 hr
= IDirectDrawSurface4_Lock(surface2
, 0, &surface_desc
, 0, NULL
);
9678 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9679 ptr
= surface_desc
.lpSurface
;
9680 ptr
[0] = 0xff000000;
9681 ptr
[1] = 0xff0000ff;
9682 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9683 ptr
[0] = 0xffff0000;
9684 ptr
[1] = 0xffff00ff;
9685 hr
= IDirectDrawSurface4_Unlock(surface2
, 0);
9686 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9688 viewport
= create_viewport(device
, 0, 0, 640, 480);
9689 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
9690 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
9692 hr
= IDirectDrawSurface4_QueryInterface(surface1
, &IID_IDirect3DTexture2
, (void **)&texture1
);
9693 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9694 hr
= IDirectDrawSurface4_QueryInterface(surface2
, &IID_IDirect3DTexture2
, (void **)&texture2
);
9695 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9696 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture1
);
9697 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9698 hr
= IDirect3DDevice3_SetTexture(device
, 1, texture2
);
9699 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9700 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9701 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9702 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
9703 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9704 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9705 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9706 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_ADD
);
9707 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9708 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9709 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9710 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
9711 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9712 hr
= IDirect3DDevice3_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
9713 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9715 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_TEXCOORDINDEX
, 1);
9716 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9717 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 0);
9718 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9720 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
9721 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9723 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9724 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9726 hr
= IDirect3DDevice3_BeginScene(device
);
9727 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9728 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9729 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9730 hr
= IDirect3DDevice3_EndScene(device
);
9731 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9733 color
= get_surface_color(rt
, 160, 120);
9734 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9735 color
= get_surface_color(rt
, 480, 120);
9736 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9737 color
= get_surface_color(rt
, 160, 360);
9738 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
9739 color
= get_surface_color(rt
, 480, 360);
9740 ok(compare_color(color
, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color
);
9742 /* D3DTSS_TEXTURETRANSFORMFLAGS was introduced in D3D7, can't test it here. */
9744 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 2);
9745 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9747 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9748 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9750 hr
= IDirect3DDevice3_BeginScene(device
);
9751 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9752 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9753 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9754 hr
= IDirect3DDevice3_EndScene(device
);
9755 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9757 color
= get_surface_color(rt
, 160, 120);
9758 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9759 color
= get_surface_color(rt
, 480, 120);
9760 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9761 color
= get_surface_color(rt
, 160, 360);
9762 ok(compare_color(color
, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color
);
9763 color
= get_surface_color(rt
, 480, 360);
9764 ok(compare_color(color
, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color
);
9766 IDirect3DTexture2_Release(texture2
);
9767 IDirect3DTexture2_Release(texture1
);
9768 IDirectDrawSurface4_Release(surface2
);
9769 IDirectDrawSurface4_Release(surface1
);
9771 destroy_viewport(device
, viewport
);
9773 IDirectDrawSurface4_Release(rt
);
9774 IDirectDraw_Release(ddraw
);
9775 refcount
= IDirect3DDevice3_Release(device
);
9776 ok(!refcount
, "Device has %u references left.\n", refcount
);
9777 DestroyWindow(window
);
9780 static void test_colorkey_precision(void)
9785 struct vec2 texcoord
;
9789 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9790 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
9791 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9792 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
9794 IDirect3DDevice3
*device
;
9796 IDirectDraw4
*ddraw
;
9797 IDirectDrawSurface4
*rt
;
9798 IDirect3DViewport3
*viewport
;
9801 IDirectDrawSurface4
*src
, *dst
, *texture
;
9802 IDirect3DTexture2
*d3d_texture
;
9803 DDSURFACEDESC2 surface_desc
, lock_desc
;
9809 DWORD data
[4] = {0}, color_mask
;
9810 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9811 D3DDEVICEDESC device_desc
, hel_desc
;
9815 unsigned int max
, shift
, bpp
, clear
;
9822 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8",
9824 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9825 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
9830 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel",
9832 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9833 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9838 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel",
9840 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9841 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9846 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4",
9848 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9849 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
9855 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9856 0, 0, 640, 480, 0, 0, 0, 0);
9857 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9859 skip("Failed to create a 3D device, skipping test.\n");
9860 DestroyWindow(window
);
9864 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
9865 * (color key doesn't match although the values are equal), and a false
9866 * positive when the color key is 0 and the texture contains the value 1.
9867 * I don't want to mark this broken unconditionally since this would
9868 * essentially disable the test on Windows. Try to detect WARP (and I
9869 * guess mismatch other SW renderers) by its ability to texture from
9870 * system memory. Also on random occasions 254 == 255 and 255 != 255.*/
9871 memset(&device_desc
, 0, sizeof(device_desc
));
9872 device_desc
.dwSize
= sizeof(device_desc
);
9873 memset(&hel_desc
, 0, sizeof(hel_desc
));
9874 hel_desc
.dwSize
= sizeof(hel_desc
);
9875 hr
= IDirect3DDevice3_GetCaps(device
, &device_desc
, &hel_desc
);
9876 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9877 warp
= !!(device_desc
.dwDevCaps
& D3DDEVCAPS_TEXTURESYSTEMMEMORY
);
9879 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9880 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
9881 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9882 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
9883 IDirect3D3_Release(d3d
);
9884 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
9885 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9887 viewport
= create_viewport(device
, 0, 0, 640, 480);
9888 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
9889 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
9891 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9892 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
9893 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9894 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9895 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
9896 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
9897 /* Multiply the texture read result with 0, that way the result color if the key doesn't
9898 * match is constant. In theory color keying works without reading the texture result
9899 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
9901 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
9902 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9903 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9904 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9905 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
9906 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9907 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x00000000);
9908 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9910 memset(&fx
, 0, sizeof(fx
));
9911 fx
.dwSize
= sizeof(fx
);
9912 memset(&lock_desc
, 0, sizeof(lock_desc
));
9913 lock_desc
.dwSize
= sizeof(lock_desc
);
9915 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
9917 memset(&surface_desc
, 0, sizeof(surface_desc
));
9918 surface_desc
.dwSize
= sizeof(surface_desc
);
9919 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9920 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9921 surface_desc
.dwWidth
= 4;
9922 surface_desc
.dwHeight
= 1;
9923 U4(surface_desc
).ddpfPixelFormat
= tests
[t
].fmt
;
9924 /* Windows XP (at least with the r200 driver, other drivers untested) produces
9925 * garbage when doing color keyed texture->texture blits. */
9926 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
9927 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9928 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
9929 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9931 fx
.dwFillColor
= tests
[t
].clear
;
9932 /* On the w8 testbot (WARP driver) the blit result has different values in the
9934 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
9935 | U3(tests
[t
].fmt
).dwGBitMask
9936 | U4(tests
[t
].fmt
).dwBBitMask
;
9938 for (c
= 0; c
<= tests
[t
].max
; ++c
)
9940 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
9941 * texture after it has been set once... */
9942 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
9943 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9944 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9945 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9946 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
9947 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9948 hr
= IDirectDrawSurface4_QueryInterface(texture
, &IID_IDirect3DTexture2
, (void **)&d3d_texture
);
9949 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9950 hr
= IDirect3DDevice3_SetTexture(device
, 0, d3d_texture
);
9951 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9953 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9954 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
9956 hr
= IDirectDrawSurface4_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9957 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9958 switch (tests
[t
].bpp
)
9961 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9962 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9963 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9964 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
9968 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9969 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9970 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9971 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
9974 hr
= IDirectDrawSurface4_Unlock(src
, 0);
9975 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9976 hr
= IDirectDrawSurface4_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
9977 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9979 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9980 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9981 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
9982 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9984 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
9985 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9987 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
9988 hr
= IDirectDrawSurface4_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9989 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9990 switch (tests
[t
].bpp
)
9993 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9994 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9995 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9996 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
10000 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
10001 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
10002 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
10003 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
10006 hr
= IDirectDrawSurface4_Unlock(dst
, 0);
10007 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10011 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10012 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
10014 if (data
[3] == tests
[t
].clear
)
10016 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10017 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10018 * even when a different surface is used. The blit itself doesn't draw anything,
10019 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10020 * never be masked out by the key.
10022 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10023 * terrible on WARP. */
10024 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10025 IDirect3DTexture2_Release(d3d_texture
);
10026 IDirectDrawSurface4_Release(texture
);
10027 IDirectDrawSurface4_Release(src
);
10028 IDirectDrawSurface4_Release(dst
);
10033 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10034 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
10036 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10037 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
10039 if (c
== tests
[t
].max
)
10040 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10041 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
10043 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10044 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
10046 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x0000ff00, 1.0f
, 0);
10047 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10049 hr
= IDirect3DDevice3_BeginScene(device
);
10050 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10051 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
10052 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10053 hr
= IDirect3DDevice3_EndScene(device
);
10054 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10056 color
= get_surface_color(rt
, 80, 240);
10058 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10059 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10060 color
, tests
[t
].name
, c
);
10062 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
10063 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10064 color
, tests
[t
].name
, c
);
10066 color
= get_surface_color(rt
, 240, 240);
10067 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10068 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10069 color
, tests
[t
].name
, c
);
10071 color
= get_surface_color(rt
, 400, 240);
10072 if (c
== tests
[t
].max
)
10073 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10074 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10075 color
, tests
[t
].name
, c
);
10077 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
10078 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10079 color
, tests
[t
].name
, c
);
10081 IDirect3DTexture2_Release(d3d_texture
);
10082 IDirectDrawSurface4_Release(texture
);
10084 IDirectDrawSurface4_Release(src
);
10085 IDirectDrawSurface4_Release(dst
);
10089 destroy_viewport(device
, viewport
);
10090 IDirectDrawSurface4_Release(rt
);
10091 IDirectDraw4_Release(ddraw
);
10092 refcount
= IDirect3DDevice3_Release(device
);
10093 ok(!refcount
, "Device has %u references left.\n", refcount
);
10094 DestroyWindow(window
);
10097 static void test_range_colorkey(void)
10099 IDirectDraw4
*ddraw
;
10102 IDirectDrawSurface4
*surface
;
10103 DDSURFACEDESC2 surface_desc
;
10107 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10108 0, 0, 640, 480, 0, 0, 0, 0);
10109 ddraw
= create_ddraw();
10110 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10111 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10112 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10114 memset(&surface_desc
, 0, sizeof(surface_desc
));
10115 surface_desc
.dwSize
= sizeof(surface_desc
);
10116 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
10117 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10118 surface_desc
.dwWidth
= 1;
10119 surface_desc
.dwHeight
= 1;
10120 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10121 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10122 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10123 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10124 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10125 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
10127 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10128 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10129 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10130 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10131 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10133 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10134 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10135 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10136 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10138 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10139 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10140 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10141 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10142 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10143 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10145 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10146 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10147 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10148 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10150 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10151 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10152 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10153 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10155 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10156 ckey
.dwColorSpaceLowValue
= 0x00000000;
10157 ckey
.dwColorSpaceHighValue
= 0x00000001;
10158 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10159 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10161 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10162 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10163 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10164 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10166 ckey
.dwColorSpaceLowValue
= 0x00000001;
10167 ckey
.dwColorSpaceHighValue
= 0x00000000;
10168 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10169 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10171 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10172 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10173 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10174 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10176 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10177 ckey
.dwColorSpaceLowValue
= 0x00000000;
10178 ckey
.dwColorSpaceHighValue
= 0x00000000;
10179 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10180 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10182 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10183 ckey
.dwColorSpaceLowValue
= 0x00000001;
10184 ckey
.dwColorSpaceHighValue
= 0x00000000;
10185 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10186 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10187 ckey
.dwColorSpaceLowValue
= 0x00000000;
10188 ckey
.dwColorSpaceHighValue
= 0x00000001;
10189 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10190 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10191 /* Range destination keys don't work either. */
10192 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
10193 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10195 /* Just to show it's not because of A, R, and G having equal values. */
10196 ckey
.dwColorSpaceLowValue
= 0x00000000;
10197 ckey
.dwColorSpaceHighValue
= 0x01010101;
10198 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10199 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10201 /* None of these operations modified the key. */
10202 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10203 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10204 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10205 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10207 IDirectDrawSurface4_Release(surface
),
10208 refcount
= IDirectDraw4_Release(ddraw
);
10209 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
10210 DestroyWindow(window
);
10213 static void test_shademode(void)
10215 IDirect3DVertexBuffer
*vb_strip
, *vb_list
, *buffer
;
10216 IDirect3DViewport3
*viewport
;
10217 IDirect3DDevice3
*device
;
10218 D3DVERTEXBUFFERDESC desc
;
10219 IDirectDrawSurface4
*rt
;
10220 DWORD color0
, color1
;
10227 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10228 static const struct
10230 struct vec3 position
;
10235 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10236 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10237 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10238 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10242 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10243 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10244 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10246 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10247 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10248 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10250 static const struct
10254 DWORD color0
, color1
;
10258 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
10259 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10260 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10261 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10262 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
10263 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10266 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10267 0, 0, 640, 480, 0, 0, 0, 0);
10269 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10271 skip("Failed to create a 3D device, skipping test.\n");
10272 DestroyWindow(window
);
10276 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
10277 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
10278 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
10279 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10281 viewport
= create_viewport(device
, 0, 0, 640, 480);
10282 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
10283 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10285 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10286 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10288 memset(&desc
, 0, sizeof(desc
));
10289 desc
.dwSize
= sizeof(desc
);
10290 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
10291 desc
.dwFVF
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
10292 desc
.dwNumVertices
= sizeof(quad_strip
) / sizeof(*quad_strip
);
10293 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &vb_strip
, 0, NULL
);
10294 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10295 hr
= IDirect3DVertexBuffer_Lock(vb_strip
, 0, &data
, NULL
);
10296 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10297 memcpy(data
, quad_strip
, sizeof(quad_strip
));
10298 hr
= IDirect3DVertexBuffer_Unlock(vb_strip
);
10299 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10301 desc
.dwNumVertices
= sizeof(quad_list
) / sizeof(*quad_list
);
10302 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &vb_list
, 0, NULL
);
10303 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10304 hr
= IDirect3DVertexBuffer_Lock(vb_list
, 0, &data
, NULL
);
10305 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10306 memcpy(data
, quad_list
, sizeof(quad_list
));
10307 hr
= IDirect3DVertexBuffer_Unlock(vb_list
);
10308 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10310 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10311 * the color fixups we have to do for FLAT shading will be dependent on that. */
10313 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
10315 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
10316 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
10318 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
10319 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
10321 hr
= IDirect3DDevice3_BeginScene(device
);
10322 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10323 buffer
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? vb_strip
: vb_list
;
10324 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
10325 hr
= IDirect3DDevice3_DrawPrimitiveVB(device
, tests
[i
].primtype
, buffer
, 0, count
, 0);
10326 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10327 hr
= IDirect3DDevice3_EndScene(device
);
10328 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10330 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
10331 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
10333 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10334 * each triangle. This requires EXT_provoking_vertex or similar
10335 * functionality being available. */
10336 /* PHONG should be the same as GOURAUD, since no hardware implements
10338 ok(compare_color(color0
, tests
[i
].color0
, 1), "Test %u shading has color0 %08x, expected %08x.\n",
10339 i
, color0
, tests
[i
].color0
);
10340 ok(compare_color(color1
, tests
[i
].color1
, 1), "Test %u shading has color1 %08x, expected %08x.\n",
10341 i
, color1
, tests
[i
].color1
);
10344 IDirect3DVertexBuffer_Release(vb_strip
);
10345 IDirect3DVertexBuffer_Release(vb_list
);
10346 destroy_viewport(device
, viewport
);
10347 IDirectDrawSurface4_Release(rt
);
10348 IDirect3D3_Release(d3d
);
10349 refcount
= IDirect3DDevice3_Release(device
);
10350 ok(!refcount
, "Device has %u references left.\n", refcount
);
10351 DestroyWindow(window
);
10354 static void test_lockrect_invalid(void)
10357 IDirectDraw4
*ddraw
;
10358 IDirectDrawSurface4
*surface
;
10361 DDSURFACEDESC2 surface_desc
;
10363 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
10364 static RECT valid
[] =
10369 {120, 60, 128, 68},
10370 {60, 120, 68, 128},
10372 static RECT invalid
[] =
10374 {68, 60, 60, 68}, /* left > right */
10375 {60, 68, 68, 60}, /* top > bottom */
10376 {-8, 60, 0, 68}, /* left < surface */
10377 {60, -8, 68, 0}, /* top < surface */
10378 {-16, 60, -8, 68}, /* right < surface */
10379 {60, -16, 68, -8}, /* bottom < surface */
10380 {60, 60, 136, 68}, /* right > surface */
10381 {60, 60, 68, 136}, /* bottom > surface */
10382 {136, 60, 144, 68}, /* left > surface */
10383 {60, 136, 68, 144}, /* top > surface */
10385 static const struct
10393 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem offscreenplain", DDERR_INVALIDPARAMS
},
10394 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem offscreenplain", DDERR_INVALIDPARAMS
},
10395 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem texture", DDERR_INVALIDPARAMS
},
10396 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem texture", DDERR_INVALIDPARAMS
},
10397 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, "managed texture", DDERR_INVALIDPARAMS
},
10400 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10401 0, 0, 640, 480, 0, 0, 0, 0);
10402 ddraw
= create_ddraw();
10403 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10404 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10405 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10407 memset(&hal_caps
, 0, sizeof(hal_caps
));
10408 hal_caps
.dwSize
= sizeof(hal_caps
);
10409 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
10410 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
10411 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
10412 || !(hal_caps
.ddsCaps
.dwCaps
& DDSCAPS2_TEXTUREMANAGE
))
10414 skip("Required surface types not supported, skipping test.\n");
10418 for (r
= 0; r
< sizeof(resources
) / sizeof(*resources
); ++r
)
10420 memset(&surface_desc
, 0, sizeof(surface_desc
));
10421 surface_desc
.dwSize
= sizeof(surface_desc
);
10422 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10423 surface_desc
.ddsCaps
.dwCaps
= resources
[r
].caps
;
10424 surface_desc
.ddsCaps
.dwCaps2
= resources
[r
].caps2
;
10425 surface_desc
.dwWidth
= 128;
10426 surface_desc
.dwHeight
= 128;
10427 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
10428 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10429 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10430 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xff0000;
10431 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x00ff00;
10432 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x0000ff;
10434 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10435 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10437 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, NULL
, DDLOCK_WAIT
, NULL
);
10438 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
10440 for (i
= 0; i
< sizeof(valid
) / sizeof(*valid
); ++i
)
10442 RECT
*rect
= &valid
[i
];
10444 memset(&surface_desc
, 0, sizeof(surface_desc
));
10445 surface_desc
.dwSize
= sizeof(surface_desc
);
10447 hr
= IDirectDrawSurface4_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10448 ok(SUCCEEDED(hr
), "Lock failed (%#x) for rect [%d, %d]->[%d, %d], type %s.\n",
10449 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, resources
[r
].name
);
10451 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10452 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10455 for (i
= 0; i
< sizeof(invalid
) / sizeof(*invalid
); ++i
)
10457 RECT
*rect
= &invalid
[i
];
10459 memset(&surface_desc
, 1, sizeof(surface_desc
));
10460 surface_desc
.dwSize
= sizeof(surface_desc
);
10462 hr
= IDirectDrawSurface4_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10463 ok(hr
== resources
[r
].hr
, "Lock returned %#x for rect [%d, %d]->[%d, %d], type %s.\n",
10464 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, resources
[r
].name
);
10467 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10468 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10471 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
10474 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10475 ok(SUCCEEDED(hr
), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
10476 hr
, resources
[r
].name
);
10477 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10478 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned %#x, type %s.\n",
10479 hr
, resources
[r
].name
);
10480 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10481 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10483 hr
= IDirectDrawSurface4_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
10484 ok(SUCCEEDED(hr
), "Lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
10485 valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, hr
);
10486 hr
= IDirectDrawSurface4_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
10487 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
10488 valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, hr
);
10490 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
10491 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
10493 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10494 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10496 IDirectDrawSurface4_Release(surface
);
10500 IDirectDraw4_Release(ddraw
);
10501 DestroyWindow(window
);
10504 static void test_yv12_overlay(void)
10506 IDirectDrawSurface4
*src_surface
, *dst_surface
;
10507 RECT rect
= {13, 17, 14, 18};
10508 unsigned int offset
, y
;
10509 DDSURFACEDESC2 desc
;
10510 unsigned char *base
;
10511 IDirectDraw4
*ddraw
;
10515 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10516 0, 0, 640, 480, 0, 0, 0, 0);
10517 ddraw
= create_ddraw();
10518 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10519 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10520 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10522 if (!(src_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
10524 skip("Failed to create a YV12 overlay, skipping test.\n");
10528 memset(&desc
, 0, sizeof(desc
));
10529 desc
.dwSize
= sizeof(desc
);
10530 hr
= IDirectDrawSurface4_Lock(src_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
10531 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10533 ok(desc
.dwFlags
== (DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_PITCH
),
10534 "Got unexpected flags %#x.\n", desc
.dwFlags
);
10535 ok(desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_HWCODEC
)
10536 || desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
10537 "Got unexpected caps %#x.\n", desc
.ddsCaps
.dwCaps
);
10538 ok(desc
.dwWidth
== 256, "Got unexpected width %u.\n", desc
.dwWidth
);
10539 ok(desc
.dwHeight
== 256, "Got unexpected height %u.\n", desc
.dwHeight
);
10540 /* The overlay pitch seems to have 256 byte alignment. */
10541 ok(!(U1(desc
).lPitch
& 0xff), "Got unexpected pitch %u.\n", U1(desc
).lPitch
);
10543 /* Fill the surface with some data for the blit test. */
10544 base
= desc
.lpSurface
;
10546 for (y
= 0; y
< desc
.dwHeight
; ++y
)
10548 memset(base
+ U1(desc
).lPitch
* y
, 0x10, desc
.dwWidth
);
10551 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 4; ++y
)
10553 memset(base
+ U1(desc
).lPitch
* y
, 0x20, desc
.dwWidth
);
10556 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 2; ++y
)
10558 memset(base
+ U1(desc
).lPitch
* y
, 0x30, desc
.dwWidth
);
10561 hr
= IDirectDrawSurface4_Unlock(src_surface
, NULL
);
10562 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10564 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
10565 * other block-based formats like DXT the entire Y channel is stored in
10566 * one big chunk of memory, followed by the chroma channels. So partial
10567 * locks do not really make sense. Show that they are allowed nevertheless
10568 * and the offset points into the luminance data. */
10569 hr
= IDirectDrawSurface4_Lock(src_surface
, &rect
, &desc
, DDLOCK_WAIT
, NULL
);
10570 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10571 offset
= ((const unsigned char *)desc
.lpSurface
- base
);
10572 ok(offset
== rect
.top
* U1(desc
).lPitch
+ rect
.left
, "Got unexpected offset %u, expected %u.\n",
10573 offset
, rect
.top
* U1(desc
).lPitch
+ rect
.left
);
10574 hr
= IDirectDrawSurface4_Unlock(src_surface
, NULL
);
10575 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10577 if (!(dst_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
10579 /* Windows XP with a Radeon X1600 GPU refuses to create a second
10580 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
10581 skip("Failed to create a second YV12 surface, skipping blit test.\n");
10582 IDirectDrawSurface4_Release(src_surface
);
10586 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, src_surface
, NULL
, DDBLT_WAIT
, NULL
);
10587 /* VMware rejects YV12 blits. This behavior has not been seen on real
10588 * hardware yet, so mark it broken. */
10589 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
), "Failed to blit, hr %#x.\n", hr
);
10593 memset(&desc
, 0, sizeof(desc
));
10594 desc
.dwSize
= sizeof(desc
);
10595 hr
= IDirectDrawSurface4_Lock(dst_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
10596 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10598 base
= desc
.lpSurface
;
10599 ok(base
[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base
[0]);
10600 base
+= desc
.dwHeight
* U1(desc
).lPitch
;
10601 todo_wine
ok(base
[0] == 0x20, "Got unexpected V data 0x%02x.\n", base
[0]);
10602 base
+= desc
.dwHeight
/ 4 * U1(desc
).lPitch
;
10603 todo_wine
ok(base
[0] == 0x30, "Got unexpected U data 0x%02x.\n", base
[0]);
10605 hr
= IDirectDrawSurface4_Unlock(dst_surface
, NULL
);
10606 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10609 IDirectDrawSurface4_Release(dst_surface
);
10610 IDirectDrawSurface4_Release(src_surface
);
10612 IDirectDraw4_Release(ddraw
);
10613 DestroyWindow(window
);
10616 static void test_offscreen_overlay(void)
10618 IDirectDrawSurface4
*overlay
, *offscreen
, *primary
;
10619 DDSURFACEDESC2 surface_desc
;
10620 IDirectDraw4
*ddraw
;
10625 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10626 0, 0, 640, 480, 0, 0, 0, 0);
10627 ddraw
= create_ddraw();
10628 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10629 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10630 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10632 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
10634 skip("Failed to create a UYVY overlay, skipping test.\n");
10638 memset(&surface_desc
, 0, sizeof(surface_desc
));
10639 surface_desc
.dwSize
= sizeof(surface_desc
);
10640 surface_desc
.dwFlags
= DDSD_CAPS
;
10641 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
10642 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
10643 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
10645 /* On Windows 7, and probably Vista, UpdateOverlay() will return
10646 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
10647 * surface prevents this by disabling the dwm. */
10648 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
10649 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
10650 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
10651 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
10653 /* Try to overlay a NULL surface. */
10654 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_SHOW
, NULL
);
10655 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10656 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_HIDE
, NULL
);
10657 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10659 /* Try to overlay an offscreen surface. */
10660 memset(&surface_desc
, 0, sizeof(surface_desc
));
10661 surface_desc
.dwSize
= sizeof(surface_desc
);
10662 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
10663 surface_desc
.dwWidth
= 64;
10664 surface_desc
.dwHeight
= 64;
10665 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10666 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
10667 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10668 U4(surface_desc
).ddpfPixelFormat
.dwFourCC
= 0;
10669 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
10670 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
10671 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
10672 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
10673 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
10674 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
10676 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, offscreen
, NULL
, DDOVER_SHOW
, NULL
);
10677 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10679 /* Try to overlay the primary with a non-overlay surface. */
10680 hr
= IDirectDrawSurface4_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
10681 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
10682 hr
= IDirectDrawSurface4_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
10683 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
10685 IDirectDrawSurface4_Release(offscreen
);
10686 IDirectDrawSurface4_Release(primary
);
10687 IDirectDrawSurface4_Release(overlay
);
10689 IDirectDraw4_Release(ddraw
);
10690 DestroyWindow(window
);
10693 static void test_overlay_rect(void)
10695 IDirectDrawSurface4
*overlay
, *primary
;
10696 DDSURFACEDESC2 surface_desc
;
10697 RECT rect
= {0, 0, 64, 64};
10698 IDirectDraw4
*ddraw
;
10704 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10705 0, 0, 640, 480, 0, 0, 0, 0);
10706 ddraw
= create_ddraw();
10707 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10708 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10709 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10711 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
10713 skip("Failed to create a UYVY overlay, skipping test.\n");
10717 memset(&surface_desc
, 0, sizeof(surface_desc
));
10718 surface_desc
.dwSize
= sizeof(surface_desc
);
10719 surface_desc
.dwFlags
= DDSD_CAPS
;
10720 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
10721 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
10722 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
10724 /* On Windows 7, and probably Vista, UpdateOverlay() will return
10725 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
10726 * surface prevents this by disabling the dwm. */
10727 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
10728 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
10729 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
10730 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
10732 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
10733 * used. This is not true in Windows Vista and earlier, but changed in
10735 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
10736 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10737 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
10738 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10739 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
10740 ok(hr
== DD_OK
|| hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10742 /* Show that the overlay position is the (top, left) coordinate of the
10743 * destination rectangle. */
10744 OffsetRect(&rect
, 32, 16);
10745 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
10746 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10747 pos_x
= -1; pos_y
= -1;
10748 hr
= IDirectDrawSurface4_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
10749 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
10750 ok(pos_x
== rect
.left
, "Got unexpected pos_x %d, expected %d.\n", pos_x
, rect
.left
);
10751 ok(pos_y
== rect
.top
, "Got unexpected pos_y %d, expected %d.\n", pos_y
, rect
.top
);
10753 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
10754 * seen that the overlay overlays the whole primary(==screen). */
10755 hr2
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, NULL
, 0, NULL
);
10756 ok(hr2
== DD_OK
|| hr2
== DDERR_INVALIDPARAMS
|| hr2
== DDERR_OUTOFCAPS
, "Got unexpected hr %#x.\n", hr2
);
10757 hr
= IDirectDrawSurface4_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
10758 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
10759 if (SUCCEEDED(hr2
))
10761 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
10762 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
10766 ok(pos_x
== 32, "Got unexpected pos_x %d.\n", pos_x
);
10767 ok(pos_y
== 16, "Got unexpected pos_y %d.\n", pos_y
);
10770 /* The position cannot be retrieved when the overlay is not shown. */
10771 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_HIDE
, NULL
);
10772 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10773 pos_x
= -1; pos_y
= -1;
10774 hr
= IDirectDrawSurface4_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
10775 ok(hr
== DDERR_OVERLAYNOTVISIBLE
, "Got unexpected hr %#x.\n", hr
);
10776 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
10777 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
10779 IDirectDrawSurface4_Release(primary
);
10780 IDirectDrawSurface4_Release(overlay
);
10782 IDirectDraw4_Release(ddraw
);
10783 DestroyWindow(window
);
10786 static void test_blt(void)
10788 IDirectDrawSurface4
*surface
, *rt
;
10789 DDSURFACEDESC2 surface_desc
;
10790 IDirect3DDevice3
*device
;
10791 IDirectDraw4
*ddraw
;
10806 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit. */
10807 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, flipped source. */
10808 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, mirrored source. */
10809 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched x. */
10810 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched y. */
10811 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK
}, /* Full surface blit. */
10812 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT
}, /* Full surface, flipped destination. */
10813 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored destination. */
10814 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, flipped source. */
10815 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored source. */
10818 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10819 0, 0, 640, 480, 0, 0, 0, 0);
10820 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10822 skip("Failed to create a 3D device, skipping test.\n");
10823 DestroyWindow(window
);
10827 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
10828 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
10829 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
10830 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
10831 IDirect3D3_Release(d3d
);
10832 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
10833 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10835 memset(&surface_desc
, 0, sizeof(surface_desc
));
10836 surface_desc
.dwSize
= sizeof(surface_desc
);
10837 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
10838 surface_desc
.dwWidth
= 640;
10839 surface_desc
.dwHeight
= 480;
10840 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10841 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10842 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10844 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface
, NULL
, 0, NULL
);
10845 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10847 hr
= IDirectDrawSurface_Blt(surface
, NULL
, rt
, NULL
, 0, NULL
);
10848 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10850 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
10852 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
10853 surface
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
10854 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
10856 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
10857 rt
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
10858 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
10861 IDirectDrawSurface4_Release(surface
);
10862 IDirectDrawSurface4_Release(rt
);
10863 IDirectDraw4_Release(ddraw
);
10864 refcount
= IDirect3DDevice3_Release(device
);
10865 ok(!refcount
, "Device has %u references left.\n", refcount
);
10866 DestroyWindow(window
);
10869 static void test_color_clamping(void)
10871 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10872 static D3DMATRIX mat
=
10874 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10875 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10876 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10877 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10879 static struct vec3 quad
[] =
10881 {-1.0f
, -1.0f
, 0.1f
},
10882 {-1.0f
, 1.0f
, 0.1f
},
10883 { 1.0f
, -1.0f
, 0.1f
},
10884 { 1.0f
, 1.0f
, 0.1f
},
10886 IDirect3DViewport3
*viewport
;
10887 IDirect3DDevice3
*device
;
10888 IDirectDrawSurface4
*rt
;
10894 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10895 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
10897 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10899 skip("Failed to create a 3D device, skipping test.\n");
10900 DestroyWindow(window
);
10904 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
10905 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10907 viewport
= create_viewport(device
, 0, 0, 640, 480);
10908 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
10909 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10911 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
10912 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
10913 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
10914 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
10915 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
10916 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
10917 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
10918 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
10919 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
10920 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
10921 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10922 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10923 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
10924 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
10925 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
10926 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
10927 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10928 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
10930 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0xff404040);
10931 ok(SUCCEEDED(hr
), "Failed to set texture factor, hr %#x.\n", hr
);
10932 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_ADD
);
10933 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
10934 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
);
10935 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10936 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_SPECULAR
);
10937 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10938 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
10939 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
10940 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
10941 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10942 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
10943 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10945 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
10946 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
10948 hr
= IDirect3DDevice3_BeginScene(device
);
10949 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10951 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, 0);
10952 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10954 hr
= IDirect3DDevice3_EndScene(device
);
10955 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10957 color
= get_surface_color(rt
, 320, 240);
10958 ok(compare_color(color
, 0x00404040, 1), "Got unexpected color 0x%08x.\n", color
);
10960 destroy_viewport(device
, viewport
);
10961 IDirectDrawSurface4_Release(rt
);
10962 refcount
= IDirect3DDevice3_Release(device
);
10963 ok(!refcount
, "Device has %u references left.\n", refcount
);
10964 DestroyWindow(window
);
10967 static void test_getdc(void)
10969 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
10970 IDirectDrawSurface4
*surface
, *surface2
, *tmp
;
10971 DDSURFACEDESC2 surface_desc
, map_desc
;
10972 IDirectDraw4
*ddraw
;
10978 static const struct
10981 DDPIXELFORMAT format
;
10982 BOOL getdc_supported
;
10983 HRESULT alt_result
;
10987 {"D3DFMT_A8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
10988 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE
},
10989 {"D3DFMT_X8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
10990 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE
},
10991 {"D3DFMT_R5G6B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
10992 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE
},
10993 {"D3DFMT_X1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
10994 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE
},
10995 {"D3DFMT_A1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
10996 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE
},
10997 {"D3DFMT_A4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
10998 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
10999 {"D3DFMT_X4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
11000 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11001 {"D3DFMT_A2R10G10B10", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
11002 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE
},
11003 {"D3DFMT_A8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
11004 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11005 {"D3DFMT_X8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
11006 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11007 {"D3DFMT_R3G3B2", {sizeof(test_data
->format
), DDPF_RGB
, 0, {8},
11008 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE
},
11009 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
11010 * This is not implemented in wine yet, so disable the test for now.
11011 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
11012 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
11013 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11015 {"D3DFMT_L8", {sizeof(test_data
->format
), DDPF_LUMINANCE
, 0, {8},
11016 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11017 {"D3DFMT_A8L8", {sizeof(test_data
->format
), DDPF_ALPHAPIXELS
| DDPF_LUMINANCE
, 0, {16},
11018 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE
},
11019 {"D3DFMT_DXT1", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','1'), {0},
11020 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11021 {"D3DFMT_DXT2", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','2'), {0},
11022 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11023 {"D3DFMT_DXT3", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','3'), {0},
11024 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11025 {"D3DFMT_DXT4", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','4'), {0},
11026 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11027 {"D3DFMT_DXT5", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','5'), {0},
11028 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11031 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11032 0, 0, 640, 480, 0, 0, 0, 0);
11033 ddraw
= create_ddraw();
11034 ok(!!ddraw
, "Failed to create a ddraw object.\n");
11035 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
11036 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11038 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
11040 memset(&surface_desc
, 0, sizeof(surface_desc
));
11041 surface_desc
.dwSize
= sizeof(surface_desc
);
11042 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
11043 surface_desc
.dwWidth
= 64;
11044 surface_desc
.dwHeight
= 64;
11045 U4(surface_desc
).ddpfPixelFormat
= test_data
[i
].format
;
11046 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11048 if (FAILED(IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11050 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
11051 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
11052 if (FAILED(hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11054 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data
[i
].name
, hr
);
11059 dc
= (void *)0x1234;
11060 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11061 if (test_data
[i
].getdc_supported
)
11062 ok(SUCCEEDED(hr
) || (test_data
[i
].alt_result
&& hr
== test_data
[i
].alt_result
),
11063 "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11065 ok(FAILED(hr
), "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11069 unsigned int width_bytes
;
11075 type
= GetObjectType(dc
);
11076 ok(type
== OBJ_MEMDC
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
11077 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
11078 type
= GetObjectType(bitmap
);
11079 ok(type
== OBJ_BITMAP
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
11081 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
11082 ok(size
== sizeof(dib
), "Got unexpected size %d for format %s.\n", size
, test_data
[i
].name
);
11083 ok(!dib
.dsBm
.bmType
, "Got unexpected type %#x for format %s.\n",
11084 dib
.dsBm
.bmType
, test_data
[i
].name
);
11085 ok(dib
.dsBm
.bmWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
11086 dib
.dsBm
.bmWidth
, test_data
[i
].name
);
11087 ok(dib
.dsBm
.bmHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
11088 dib
.dsBm
.bmHeight
, test_data
[i
].name
);
11089 width_bytes
= ((dib
.dsBm
.bmWidth
* U1(test_data
[i
].format
).dwRGBBitCount
+ 31) >> 3) & ~3;
11090 ok(dib
.dsBm
.bmWidthBytes
== width_bytes
, "Got unexpected width bytes %d for format %s.\n",
11091 dib
.dsBm
.bmWidthBytes
, test_data
[i
].name
);
11092 ok(dib
.dsBm
.bmPlanes
== 1, "Got unexpected plane count %d for format %s.\n",
11093 dib
.dsBm
.bmPlanes
, test_data
[i
].name
);
11094 ok(dib
.dsBm
.bmBitsPixel
== U1(test_data
[i
].format
).dwRGBBitCount
,
11095 "Got unexpected bit count %d for format %s.\n",
11096 dib
.dsBm
.bmBitsPixel
, test_data
[i
].name
);
11097 ok(!!dib
.dsBm
.bmBits
, "Got unexpected bits %p for format %s.\n",
11098 dib
.dsBm
.bmBits
, test_data
[i
].name
);
11100 ok(dib
.dsBmih
.biSize
== sizeof(dib
.dsBmih
), "Got unexpected size %u for format %s.\n",
11101 dib
.dsBmih
.biSize
, test_data
[i
].name
);
11102 ok(dib
.dsBmih
.biWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
11103 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
11104 ok(dib
.dsBmih
.biHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
11105 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
11106 ok(dib
.dsBmih
.biPlanes
== 1, "Got unexpected plane count %u for format %s.\n",
11107 dib
.dsBmih
.biPlanes
, test_data
[i
].name
);
11108 ok(dib
.dsBmih
.biBitCount
== U1(test_data
[i
].format
).dwRGBBitCount
,
11109 "Got unexpected bit count %u for format %s.\n",
11110 dib
.dsBmih
.biBitCount
, test_data
[i
].name
);
11111 ok(dib
.dsBmih
.biCompression
== (U1(test_data
[i
].format
).dwRGBBitCount
== 16 ? BI_BITFIELDS
: BI_RGB
)
11112 || broken(U2(test_data
[i
].format
).dwRGBBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_BITFIELDS
),
11113 "Got unexpected compression %#x for format %s.\n",
11114 dib
.dsBmih
.biCompression
, test_data
[i
].name
);
11115 ok(!dib
.dsBmih
.biSizeImage
, "Got unexpected image size %u for format %s.\n",
11116 dib
.dsBmih
.biSizeImage
, test_data
[i
].name
);
11117 ok(!dib
.dsBmih
.biXPelsPerMeter
, "Got unexpected horizontal resolution %d for format %s.\n",
11118 dib
.dsBmih
.biXPelsPerMeter
, test_data
[i
].name
);
11119 ok(!dib
.dsBmih
.biYPelsPerMeter
, "Got unexpected vertical resolution %d for format %s.\n",
11120 dib
.dsBmih
.biYPelsPerMeter
, test_data
[i
].name
);
11121 ok(!dib
.dsBmih
.biClrUsed
, "Got unexpected used colour count %u for format %s.\n",
11122 dib
.dsBmih
.biClrUsed
, test_data
[i
].name
);
11123 ok(!dib
.dsBmih
.biClrImportant
, "Got unexpected important colour count %u for format %s.\n",
11124 dib
.dsBmih
.biClrImportant
, test_data
[i
].name
);
11126 if (dib
.dsBmih
.biCompression
== BI_BITFIELDS
)
11128 ok((dib
.dsBitfields
[0] == U2(test_data
[i
].format
).dwRBitMask
11129 && dib
.dsBitfields
[1] == U3(test_data
[i
].format
).dwGBitMask
11130 && dib
.dsBitfields
[2] == U4(test_data
[i
].format
).dwBBitMask
)
11131 || broken(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2]),
11132 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11133 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
11137 ok(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2],
11138 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11139 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
11141 ok(!dib
.dshSection
, "Got unexpected section %p for format %s.\n", dib
.dshSection
, test_data
[i
].name
);
11142 ok(!dib
.dsOffset
, "Got unexpected offset %u for format %s.\n", dib
.dsOffset
, test_data
[i
].name
);
11144 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11145 ok(hr
== DD_OK
, "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11149 ok(!dc
, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
11152 IDirectDrawSurface4_Release(surface
);
11157 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
11158 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
11159 if (FAILED(hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11161 skip("Failed to create mip-mapped texture for format %s (hr %#x), skipping tests.\n",
11162 test_data
[i
].name
, hr
);
11166 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &tmp
);
11167 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11168 hr
= IDirectDrawSurface4_GetAttachedSurface(tmp
, &caps
, &surface2
);
11169 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11170 IDirectDrawSurface4_Release(tmp
);
11172 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11173 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11174 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11175 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11176 hr
= IDirectDrawSurface4_GetDC(surface2
, &dc
);
11177 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11178 hr
= IDirectDrawSurface4_ReleaseDC(surface2
, dc
);
11179 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11181 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11182 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11183 dc2
= (void *)0x1234;
11184 hr
= IDirectDrawSurface4_GetDC(surface
, &dc2
);
11185 ok(hr
== DDERR_DCALREADYCREATED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11186 ok(dc2
== (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
11187 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11188 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11189 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11190 ok(hr
== DDERR_NODC
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11192 map_desc
.dwSize
= sizeof(map_desc
);
11193 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11194 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11195 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11196 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11197 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11198 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11199 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11200 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11202 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11203 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11204 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11205 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11206 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11207 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11209 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11210 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11211 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11212 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11213 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11214 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11215 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11216 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11218 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11219 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11220 hr
= IDirectDrawSurface4_GetDC(surface2
, &dc2
);
11221 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11222 hr
= IDirectDrawSurface4_ReleaseDC(surface2
, dc2
);
11223 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11224 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11225 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11227 hr
= IDirectDrawSurface4_GetDC(surface2
, &dc
);
11228 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11229 hr
= IDirectDrawSurface4_GetDC(surface
, &dc2
);
11230 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11231 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc2
);
11232 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11233 hr
= IDirectDrawSurface4_ReleaseDC(surface2
, dc
);
11234 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11236 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11237 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11238 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11239 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11240 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11241 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11242 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11243 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11245 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11246 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11247 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11248 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11249 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11250 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11251 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11252 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11254 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11255 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11256 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11257 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11258 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11259 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11260 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11261 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11263 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11264 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11265 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11266 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11267 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11268 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11269 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11270 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11272 hr
= IDirectDrawSurface4_GetDC(surface2
, &dc
);
11273 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11274 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11275 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11276 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11277 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11278 hr
= IDirectDrawSurface4_ReleaseDC(surface2
, dc
);
11279 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11281 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11282 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11283 hr
= IDirectDrawSurface4_GetDC(surface2
, &dc
);
11284 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11285 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11286 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11287 hr
= IDirectDrawSurface4_ReleaseDC(surface2
, dc
);
11288 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11289 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11290 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11292 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11293 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11294 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11295 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11296 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11297 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11298 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11299 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11300 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11301 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11303 IDirectDrawSurface4_Release(surface2
);
11304 IDirectDrawSurface4_Release(surface
);
11307 IDirectDraw4_Release(ddraw
);
11308 DestroyWindow(window
);
11313 IDirectDraw4
*ddraw
;
11314 DEVMODEW current_mode
;
11316 if (!(ddraw
= create_ddraw()))
11318 skip("Failed to create a ddraw object, skipping tests.\n");
11321 IDirectDraw4_Release(ddraw
);
11323 memset(¤t_mode
, 0, sizeof(current_mode
));
11324 current_mode
.dmSize
= sizeof(current_mode
);
11325 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
11326 registry_mode
.dmSize
= sizeof(registry_mode
);
11327 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
11328 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
11329 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
11331 skip("Current mode does not match registry mode, skipping test.\n");
11335 test_process_vertices();
11336 test_coop_level_create_device_window();
11337 test_clipper_blt();
11338 test_coop_level_d3d_state();
11339 test_surface_interface_mismatch();
11340 test_coop_level_threaded();
11342 test_texture_load_ckey();
11351 test_window_style();
11352 test_redundant_mode_set();
11353 test_coop_level_mode_set();
11354 test_coop_level_mode_set_multi();
11356 test_coop_level_surf_create();
11358 test_coop_level_multi_window();
11359 test_draw_strided();
11361 test_specular_lighting();
11362 test_clear_rect_count();
11363 test_coop_level_versions();
11364 test_lighting_interface_versions();
11365 test_coop_level_activateapp();
11366 test_texturemanage();
11367 test_block_formats_creation();
11368 test_unsupported_formats();
11370 test_primary_caps();
11371 test_surface_lock();
11372 test_surface_discard();
11374 test_set_surface_desc();
11375 test_user_memory_getdc();
11376 test_sysmem_overlay();
11377 test_primary_palette();
11378 test_surface_attachment();
11379 test_private_data();
11380 test_pixel_format();
11381 test_create_surface_pitch();
11383 test_palette_complex();
11384 test_p8_rgb_blit();
11386 test_palette_gdi();
11387 test_palette_alpha();
11388 test_vb_writeonly();
11389 test_lost_device();
11390 test_surface_desc_lock();
11391 test_signed_formats();
11393 test_texcoordindex();
11394 test_colorkey_precision();
11395 test_range_colorkey();
11397 test_lockrect_invalid();
11398 test_yv12_overlay();
11399 test_offscreen_overlay();
11400 test_overlay_rect();
11402 test_color_clamping();