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
*frontbuffer
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
6124 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
6125 DDSURFACEDESC2 surface_desc
;
6126 BOOL sysmem_primary
;
6127 IDirectDraw4
*ddraw
;
6128 DWORD expected_caps
;
6143 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE
},
6144 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN
},
6145 {"TEXTURE", DDSCAPS_TEXTURE
},
6148 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6149 0, 0, 640, 480, 0, 0, 0, 0);
6150 ddraw
= create_ddraw();
6151 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6153 hr
= set_display_mode(ddraw
, 640, 480);
6154 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
6155 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6156 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6158 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6160 memset(&surface_desc
, 0, sizeof(surface_desc
));
6161 surface_desc
.dwSize
= sizeof(surface_desc
);
6162 surface_desc
.dwFlags
= DDSD_CAPS
;
6163 if (!(test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
6164 surface_desc
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
6165 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
6166 surface_desc
.dwWidth
= 512;
6167 surface_desc
.dwHeight
= 512;
6168 U5(surface_desc
).dwBackBufferCount
= 3;
6169 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6170 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6172 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_FLIP
;
6173 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
6174 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6175 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6177 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_COMPLEX
;
6178 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_FLIP
;
6179 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6180 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6182 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_COMPLEX
;
6183 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
6184 todo_wine_if(test_data
[i
].caps
& DDSCAPS_TEXTURE
)
6185 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
6189 memset(&surface_desc
, 0, sizeof(surface_desc
));
6190 surface_desc
.dwSize
= sizeof(surface_desc
);
6191 hr
= IDirectDrawSurface4_GetSurfaceDesc(frontbuffer
, &surface_desc
);
6192 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
6193 expected_caps
= DDSCAPS_FRONTBUFFER
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
6194 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
6195 expected_caps
|= DDSCAPS_VISIBLE
;
6196 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
6197 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
6198 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
6200 hr
= IDirectDrawSurface4_GetAttachedSurface(frontbuffer
, &caps
, &backbuffer1
);
6201 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
6202 memset(&surface_desc
, 0, sizeof(surface_desc
));
6203 surface_desc
.dwSize
= sizeof(surface_desc
);
6204 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer1
, &surface_desc
);
6205 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
6206 ok(!U5(surface_desc
).dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
6207 test_data
[i
].name
, U5(surface_desc
).dwBackBufferCount
);
6208 expected_caps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
);
6209 expected_caps
|= DDSCAPS_BACKBUFFER
;
6210 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
6211 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
6213 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
6214 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
6215 memset(&surface_desc
, 0, sizeof(surface_desc
));
6216 surface_desc
.dwSize
= sizeof(surface_desc
);
6217 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer2
, &surface_desc
);
6218 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
6219 ok(!U5(surface_desc
).dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
6220 test_data
[i
].name
, U5(surface_desc
).dwBackBufferCount
);
6221 expected_caps
&= ~DDSCAPS_BACKBUFFER
;
6222 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
6223 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
6225 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
6226 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
6227 memset(&surface_desc
, 0, sizeof(surface_desc
));
6228 surface_desc
.dwSize
= sizeof(surface_desc
);
6229 hr
= IDirectDrawSurface4_GetSurfaceDesc(backbuffer3
, &surface_desc
);
6230 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
6231 ok(!U5(surface_desc
).dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
6232 test_data
[i
].name
, U5(surface_desc
).dwBackBufferCount
);
6233 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
6234 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
6236 hr
= IDirectDrawSurface4_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
6237 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
6238 ok(surface
== frontbuffer
, "%s: Got unexpected surface %p, expected %p.\n",
6239 test_data
[i
].name
, surface
, frontbuffer
);
6240 IDirectDrawSurface4_Release(surface
);
6242 memset(&surface_desc
, 0, sizeof(surface_desc
));
6243 surface_desc
.dwSize
= sizeof(surface_desc
);
6244 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6245 surface_desc
.ddsCaps
.dwCaps
= 0;
6246 surface_desc
.dwWidth
= 640;
6247 surface_desc
.dwHeight
= 480;
6248 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6249 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
6250 hr
= IDirectDrawSurface4_Flip(frontbuffer
, surface
, DDFLIP_WAIT
);
6251 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6252 IDirectDrawSurface4_Release(surface
);
6254 hr
= IDirectDrawSurface4_Flip(frontbuffer
, frontbuffer
, DDFLIP_WAIT
);
6255 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6256 hr
= IDirectDrawSurface4_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
6257 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6258 hr
= IDirectDrawSurface4_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
6259 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6260 hr
= IDirectDrawSurface4_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
6261 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
6263 memset(&fx
, 0, sizeof(fx
));
6264 fx
.dwSize
= sizeof(fx
);
6265 U5(fx
).dwFillColor
= 0xffff0000;
6266 hr
= IDirectDrawSurface4_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6267 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6268 U5(fx
).dwFillColor
= 0xff00ff00;
6269 hr
= IDirectDrawSurface4_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6270 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6271 U5(fx
).dwFillColor
= 0xff0000ff;
6272 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6273 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6275 hr
= IDirectDrawSurface4_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
6276 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6277 color
= get_surface_color(backbuffer1
, 320, 240);
6278 /* The testbot seems to just copy the contents of one surface to all the
6279 * others, instead of properly flipping. */
6280 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6281 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6282 color
= get_surface_color(backbuffer2
, 320, 240);
6283 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6284 U5(fx
).dwFillColor
= 0xffff0000;
6285 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6286 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6288 hr
= IDirectDrawSurface4_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
6289 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6290 color
= get_surface_color(backbuffer1
, 320, 240);
6291 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6292 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6293 color
= get_surface_color(backbuffer2
, 320, 240);
6294 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6295 U5(fx
).dwFillColor
= 0xff00ff00;
6296 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6297 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6299 hr
= IDirectDrawSurface4_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
6300 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6301 color
= get_surface_color(backbuffer1
, 320, 240);
6302 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6303 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6304 color
= get_surface_color(backbuffer2
, 320, 240);
6305 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6306 U5(fx
).dwFillColor
= 0xff0000ff;
6307 hr
= IDirectDrawSurface4_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6308 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6310 hr
= IDirectDrawSurface4_Flip(frontbuffer
, backbuffer1
, DDFLIP_WAIT
);
6311 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6312 color
= get_surface_color(backbuffer2
, 320, 240);
6313 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6314 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6315 color
= get_surface_color(backbuffer3
, 320, 240);
6316 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6317 U5(fx
).dwFillColor
= 0xffff0000;
6318 hr
= IDirectDrawSurface4_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6319 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6321 hr
= IDirectDrawSurface4_Flip(frontbuffer
, backbuffer2
, DDFLIP_WAIT
);
6322 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6323 color
= get_surface_color(backbuffer1
, 320, 240);
6324 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6325 color
= get_surface_color(backbuffer3
, 320, 240);
6326 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6327 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6328 U5(fx
).dwFillColor
= 0xff00ff00;
6329 hr
= IDirectDrawSurface4_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6330 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
6332 hr
= IDirectDrawSurface4_Flip(frontbuffer
, backbuffer3
, DDFLIP_WAIT
);
6333 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
6334 color
= get_surface_color(backbuffer1
, 320, 240);
6335 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6336 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6337 color
= get_surface_color(backbuffer2
, 320, 240);
6338 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
6340 IDirectDrawSurface4_Release(backbuffer3
);
6341 IDirectDrawSurface4_Release(backbuffer2
);
6342 IDirectDrawSurface4_Release(backbuffer1
);
6343 IDirectDrawSurface4_Release(frontbuffer
);
6346 refcount
= IDirectDraw4_Release(ddraw
);
6347 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
6348 DestroyWindow(window
);
6351 static void reset_ddsd(DDSURFACEDESC2
*ddsd
)
6353 memset(ddsd
, 0, sizeof(*ddsd
));
6354 ddsd
->dwSize
= sizeof(*ddsd
);
6357 static void test_set_surface_desc(void)
6359 IDirectDraw4
*ddraw
;
6362 DDSURFACEDESC2 ddsd
;
6363 IDirectDrawSurface4
*surface
;
6373 invalid_caps_tests
[] =
6375 {DDSCAPS_VIDEOMEMORY
, 0, FALSE
, "videomemory plain"},
6376 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, TRUE
, "systemmemory texture"},
6377 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
, "managed texture"},
6378 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
, "managed texture"},
6379 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
, "systemmemory primary"},
6382 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6383 0, 0, 640, 480, 0, 0, 0, 0);
6384 ddraw
= create_ddraw();
6385 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6386 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6387 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6390 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6393 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6394 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6395 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6396 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6397 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6398 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6399 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6401 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6402 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6405 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6406 ddsd
.lpSurface
= data
;
6407 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6408 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6410 /* Redundantly setting the same lpSurface is not an error. */
6411 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6412 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6413 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6414 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6415 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6416 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
6418 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
6419 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6420 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6421 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
6422 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
6423 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6426 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6427 ddsd
.lpSurface
= data
;
6428 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 1);
6429 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
6431 ddsd
.lpSurface
= NULL
;
6432 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6433 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
6435 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, NULL
, 0);
6436 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
6438 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6439 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6440 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6441 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6442 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6444 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
6445 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6446 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
6448 ddsd
.dwFlags
= DDSD_CAPS
;
6449 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6450 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6452 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
6453 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
6454 ddsd
.lpSurface
= data
;
6455 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6456 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6457 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6458 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6459 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6460 ddsd
.ddsCaps
.dwCaps
= 0;
6461 ddsd
.ddsCaps
.dwCaps2
= 0xdeadbeef;
6462 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6463 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6465 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6466 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6467 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6468 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6469 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6471 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
6473 ddsd
.dwFlags
= DDSD_HEIGHT
;
6475 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6476 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
6478 ddsd
.lpSurface
= data
;
6479 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
6480 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6481 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6484 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6485 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
6488 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6489 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
6490 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6491 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6493 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0 */
6495 ddsd
.dwFlags
= DDSD_PITCH
;
6496 U1(ddsd
).lPitch
= 8 * 4;
6497 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6498 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
6500 ddsd
.dwFlags
= DDSD_WIDTH
;
6502 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6503 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
6505 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
6506 ddsd
.lpSurface
= data
;
6507 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6508 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
6510 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
6511 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6512 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
6514 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6515 U1(ddsd
).lPitch
= 16 * 4;
6517 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6518 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6521 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &ddsd
);
6522 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6523 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6524 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6525 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
6527 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
6529 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
6530 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6531 U1(ddsd
).lPitch
= 4 * 4;
6532 ddsd
.lpSurface
= data
;
6533 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6534 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6536 U1(ddsd
).lPitch
= 4;
6537 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6538 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6540 U1(ddsd
).lPitch
= 16 * 4 + 1;
6541 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6542 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6544 U1(ddsd
).lPitch
= 16 * 4 + 3;
6545 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6546 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6548 U1(ddsd
).lPitch
= -4;
6549 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6550 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
6552 U1(ddsd
).lPitch
= 16 * 4;
6553 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6554 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6557 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6558 U1(ddsd
).lPitch
= 0;
6560 ddsd
.lpSurface
= data
;
6561 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6562 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
6564 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6565 U1(ddsd
).lPitch
= 16 * 4;
6567 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6568 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
6570 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
6571 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
6572 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6573 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6574 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6575 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6576 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6577 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6578 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6579 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
6581 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
6582 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6583 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6585 /* Can't set color keys. */
6587 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
6588 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
6589 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
6590 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6591 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6593 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
6594 ddsd
.lpSurface
= data
;
6595 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6596 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6598 IDirectDrawSurface4_Release(surface
);
6600 /* SetSurfaceDesc needs systemmemory surfaces.
6602 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
6603 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
6606 ddsd
.dwFlags
= DDSD_CAPS
;
6607 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
6608 ddsd
.ddsCaps
.dwCaps2
= invalid_caps_tests
[i
].caps2
;
6609 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
6611 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6614 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6615 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6616 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6617 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6618 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6619 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6622 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6623 ok(SUCCEEDED(hr
) || hr
== DDERR_NODIRECTDRAWHW
, "Failed to create surface, hr %#x.\n", hr
);
6626 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
6627 invalid_caps_tests
[i
].name
);
6632 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6633 ddsd
.lpSurface
= data
;
6634 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6635 if (invalid_caps_tests
[i
].supported
)
6637 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6641 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6642 invalid_caps_tests
[i
].name
, hr
);
6644 /* Check priority of error conditions. */
6645 ddsd
.dwFlags
= DDSD_WIDTH
;
6646 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6647 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6648 invalid_caps_tests
[i
].name
, hr
);
6651 IDirectDrawSurface4_Release(surface
);
6655 ref
= IDirectDraw4_Release(ddraw
);
6656 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6657 DestroyWindow(window
);
6660 static void test_user_memory_getdc(void)
6662 IDirectDraw4
*ddraw
;
6665 DDSURFACEDESC2 ddsd
;
6666 IDirectDrawSurface4
*surface
;
6675 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6676 0, 0, 640, 480, 0, 0, 0, 0);
6677 ddraw
= create_ddraw();
6678 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6680 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6681 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6684 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6687 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6688 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6689 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6690 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6691 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6692 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6693 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6694 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6695 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6697 memset(data
, 0xaa, sizeof(data
));
6699 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6700 ddsd
.lpSurface
= data
;
6701 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6702 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6704 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
6705 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6706 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
6707 ok(!!bitmap
, "Failed to get bitmap.\n");
6708 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
6709 ok(size
== sizeof(dib
), "Got unexpected size %d.\n", size
);
6710 ok(dib
.dsBm
.bmBits
== data
, "Got unexpected bits %p, expected %p.\n", dib
.dsBm
.bmBits
, data
);
6711 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
6712 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
6713 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
6714 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6716 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
6717 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
6719 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
6720 ddsd
.lpSurface
= data
;
6723 U1(ddsd
).lPitch
= sizeof(*data
);
6724 hr
= IDirectDrawSurface4_SetSurfaceDesc(surface
, &ddsd
, 0);
6725 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6727 memset(data
, 0xaa, sizeof(data
));
6728 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
6729 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6730 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
6731 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
6732 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
6733 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6735 for (y
= 0; y
< 4; y
++)
6737 for (x
= 0; x
< 4; x
++)
6739 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
6740 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6743 ok(data
[y
][x
] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6747 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6749 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6751 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6753 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6756 IDirectDrawSurface4_Release(surface
);
6757 ref
= IDirectDraw4_Release(ddraw
);
6758 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6759 DestroyWindow(window
);
6762 static void test_sysmem_overlay(void)
6764 IDirectDraw4
*ddraw
;
6767 DDSURFACEDESC2 ddsd
;
6768 IDirectDrawSurface4
*surface
;
6771 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6772 0, 0, 640, 480, 0, 0, 0, 0);
6773 ddraw
= create_ddraw();
6774 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6776 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6777 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6780 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
6783 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
6784 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6785 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6786 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6787 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6788 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6789 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6790 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6791 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
6793 ref
= IDirectDraw4_Release(ddraw
);
6794 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6795 DestroyWindow(window
);
6798 static void test_primary_palette(void)
6800 DDSCAPS2 surface_caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
6801 IDirectDrawSurface4
*primary
, *backbuffer
;
6802 PALETTEENTRY palette_entries
[256];
6803 IDirectDrawPalette
*palette
, *tmp
;
6804 DDSURFACEDESC2 surface_desc
;
6805 IDirectDraw4
*ddraw
;
6811 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6812 0, 0, 640, 480, 0, 0, 0, 0);
6813 ddraw
= create_ddraw();
6814 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6815 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
6817 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6818 IDirectDraw4_Release(ddraw
);
6819 DestroyWindow(window
);
6822 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6823 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6825 memset(&surface_desc
, 0, sizeof(surface_desc
));
6826 surface_desc
.dwSize
= sizeof(surface_desc
);
6827 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6828 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6829 U5(surface_desc
).dwBackBufferCount
= 1;
6830 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6831 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6832 hr
= IDirectDrawSurface4_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
6833 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6835 memset(palette_entries
, 0, sizeof(palette_entries
));
6836 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
6837 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6838 refcount
= get_refcount((IUnknown
*)palette
);
6839 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6841 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6842 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6843 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6845 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
6846 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6848 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6849 * and is generally somewhat broken with respect to 8 bpp / palette
6851 if (SUCCEEDED(IDirectDrawSurface4_GetPalette(backbuffer
, &tmp
)))
6853 win_skip("Broken palette handling detected, skipping tests.\n");
6854 IDirectDrawPalette_Release(tmp
);
6855 IDirectDrawPalette_Release(palette
);
6856 /* The Windows 8 testbot keeps extra references to the primary and
6857 * backbuffer while in 8 bpp mode. */
6858 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
6859 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
6863 refcount
= get_refcount((IUnknown
*)palette
);
6864 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6866 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6867 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6868 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
6869 "Got unexpected palette caps %#x.\n", palette_caps
);
6871 hr
= IDirectDrawSurface4_SetPalette(primary
, NULL
);
6872 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6873 refcount
= get_refcount((IUnknown
*)palette
);
6874 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6876 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6877 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6878 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6880 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
6881 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6882 refcount
= get_refcount((IUnknown
*)palette
);
6883 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6885 hr
= IDirectDrawSurface4_GetPalette(primary
, &tmp
);
6886 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6887 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
6888 IDirectDrawPalette_Release(tmp
);
6889 hr
= IDirectDrawSurface4_GetPalette(backbuffer
, &tmp
);
6890 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6892 refcount
= IDirectDrawPalette_Release(palette
);
6893 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6894 refcount
= IDirectDrawPalette_Release(palette
);
6895 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6897 /* Note that this only seems to work when the palette is attached to the
6898 * primary surface. When attached to a regular surface, attempting to get
6899 * the palette here will cause an access violation. */
6900 hr
= IDirectDrawSurface4_GetPalette(primary
, &tmp
);
6901 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6904 refcount
= IDirectDrawSurface4_Release(backbuffer
);
6905 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6906 refcount
= IDirectDrawSurface4_Release(primary
);
6907 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6908 refcount
= IDirectDraw4_Release(ddraw
);
6909 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6910 DestroyWindow(window
);
6913 static HRESULT WINAPI
surface_counter(IDirectDrawSurface4
*surface
, DDSURFACEDESC2
*desc
, void *context
)
6915 UINT
*surface_count
= context
;
6918 IDirectDrawSurface_Release(surface
);
6920 return DDENUMRET_OK
;
6923 static void test_surface_attachment(void)
6925 IDirectDrawSurface4
*surface1
, *surface2
, *surface3
, *surface4
;
6926 IDirectDrawSurface
*surface1v1
, *surface2v1
;
6927 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, {0}};
6928 DDSURFACEDESC2 surface_desc
;
6929 IDirectDraw4
*ddraw
;
6935 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6936 0, 0, 640, 480, 0, 0, 0, 0);
6937 ddraw
= create_ddraw();
6938 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6939 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6940 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6942 memset(&surface_desc
, 0, sizeof(surface_desc
));
6943 surface_desc
.dwSize
= sizeof(surface_desc
);
6944 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
6945 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6946 U2(surface_desc
).dwMipMapCount
= 3;
6947 surface_desc
.dwWidth
= 128;
6948 surface_desc
.dwHeight
= 128;
6949 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6950 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6952 hr
= IDirectDrawSurface4_GetAttachedSurface(surface1
, &caps
, &surface2
);
6953 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6954 hr
= IDirectDrawSurface4_GetAttachedSurface(surface2
, &caps
, &surface3
);
6955 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6956 hr
= IDirectDrawSurface4_GetAttachedSurface(surface3
, &caps
, &surface4
);
6957 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6960 IDirectDrawSurface4_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
6961 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6963 IDirectDrawSurface4_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
6964 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6966 IDirectDrawSurface4_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
6967 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
6969 memset(&surface_desc
, 0, sizeof(surface_desc
));
6970 surface_desc
.dwSize
= sizeof(surface_desc
);
6971 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6972 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6973 surface_desc
.dwWidth
= 16;
6974 surface_desc
.dwHeight
= 16;
6975 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6976 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6978 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
);
6979 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6980 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
6981 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6982 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface4
);
6983 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6984 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface3
);
6985 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6986 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface4
);
6987 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6988 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface2
);
6989 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6991 IDirectDrawSurface4_Release(surface4
);
6993 memset(&surface_desc
, 0, sizeof(surface_desc
));
6994 surface_desc
.dwSize
= sizeof(surface_desc
);
6995 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6996 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6997 surface_desc
.dwWidth
= 16;
6998 surface_desc
.dwHeight
= 16;
6999 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
7000 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7002 if (SUCCEEDED(hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
)))
7004 skip("Running on refrast, skipping some tests.\n");
7005 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface4
);
7006 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7010 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7011 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
7012 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7013 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface4
);
7014 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7015 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface3
);
7016 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7017 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface4
);
7018 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7019 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface2
);
7020 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7023 IDirectDrawSurface4_Release(surface4
);
7024 IDirectDrawSurface4_Release(surface3
);
7025 IDirectDrawSurface4_Release(surface2
);
7026 IDirectDrawSurface4_Release(surface1
);
7028 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7029 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7031 /* Try a single primary and two offscreen plain surfaces. */
7032 memset(&surface_desc
, 0, sizeof(surface_desc
));
7033 surface_desc
.dwSize
= sizeof(surface_desc
);
7034 surface_desc
.dwFlags
= DDSD_CAPS
;
7035 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7036 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7037 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7039 memset(&surface_desc
, 0, sizeof(surface_desc
));
7040 surface_desc
.dwSize
= sizeof(surface_desc
);
7041 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7042 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7043 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
7044 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
7045 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
7046 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7048 memset(&surface_desc
, 0, sizeof(surface_desc
));
7049 surface_desc
.dwSize
= sizeof(surface_desc
);
7050 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7051 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7052 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
7053 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
7054 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
7055 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7057 /* This one has a different size. */
7058 memset(&surface_desc
, 0, sizeof(surface_desc
));
7059 surface_desc
.dwSize
= sizeof(surface_desc
);
7060 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7061 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7062 surface_desc
.dwWidth
= 128;
7063 surface_desc
.dwHeight
= 128;
7064 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
7065 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7067 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7068 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7069 /* Try the reverse without detaching first. */
7070 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface1
);
7071 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
7072 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7073 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7075 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface1
);
7076 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7077 /* Try to detach reversed. */
7078 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7079 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7080 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface2
, 0, surface1
);
7081 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7083 hr
= IDirectDrawSurface4_AddAttachedSurface(surface2
, surface3
);
7084 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7085 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface2
, 0, surface3
);
7086 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7088 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface4
);
7089 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7090 hr
= IDirectDrawSurface4_AddAttachedSurface(surface4
, surface1
);
7091 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7093 IDirectDrawSurface4_Release(surface4
);
7094 IDirectDrawSurface4_Release(surface3
);
7095 IDirectDrawSurface4_Release(surface2
);
7096 IDirectDrawSurface4_Release(surface1
);
7098 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
7099 memset(&surface_desc
, 0, sizeof(surface_desc
));
7100 surface_desc
.dwSize
= sizeof(surface_desc
);
7101 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7102 surface_desc
.dwWidth
= 64;
7103 surface_desc
.dwHeight
= 64;
7104 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
7105 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7106 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
7107 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
7108 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
7109 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
7110 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
7111 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7112 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7113 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
7114 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7116 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
7117 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
7118 U1(U4(surface_desc
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
7119 U3(U4(surface_desc
).ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
7120 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
7121 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7123 hr
= IDirectDrawSurface4_QueryInterface(surface1
, &IID_IDirectDrawSurface
, (void **)&surface1v1
);
7124 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
7125 hr
= IDirectDrawSurface4_QueryInterface(surface2
, &IID_IDirectDrawSurface
, (void **)&surface2v1
);
7126 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
7128 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7129 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7130 refcount
= get_refcount((IUnknown
*)surface2
);
7131 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
7132 refcount
= get_refcount((IUnknown
*)surface2v1
);
7133 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7134 hr
= IDirectDrawSurface4_AddAttachedSurface(surface1
, surface2
);
7135 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
7136 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7137 todo_wine
ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
7138 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
7139 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
7141 /* Attaching while already attached to other surface. */
7142 hr
= IDirectDrawSurface4_AddAttachedSurface(surface3
, surface2
);
7143 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7144 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface3
, 0, surface2
);
7145 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7146 IDirectDrawSurface4_Release(surface3
);
7148 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7149 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7150 refcount
= get_refcount((IUnknown
*)surface2
);
7151 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7152 refcount
= get_refcount((IUnknown
*)surface2v1
);
7153 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
7155 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
7156 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7157 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7158 hr
= IDirectDrawSurface4_DeleteAttachedSurface(surface1
, 0, surface2
);
7159 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
7160 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
7161 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
7162 refcount
= IDirectDrawSurface4_Release(surface2
);
7163 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7164 refcount
= IDirectDrawSurface4_Release(surface1
);
7165 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7167 /* Automatic detachment on release. */
7168 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
7169 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
7170 refcount
= get_refcount((IUnknown
*)surface2v1
);
7171 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
7172 refcount
= IDirectDrawSurface_Release(surface1v1
);
7173 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7174 refcount
= IDirectDrawSurface_Release(surface2v1
);
7175 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7176 refcount
= IDirectDraw4_Release(ddraw
);
7177 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7178 DestroyWindow(window
);
7181 static void test_private_data(void)
7183 IDirectDraw4
*ddraw
;
7184 IDirectDrawSurface4
*surface
, *surface2
;
7185 DDSURFACEDESC2 surface_desc
;
7186 ULONG refcount
, refcount2
, refcount3
;
7188 DWORD size
= sizeof(ptr
);
7191 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7192 DWORD data
[] = {1, 2, 3, 4};
7194 static const GUID ddraw_private_data_test_guid
=
7199 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
7201 static const GUID ddraw_private_data_test_guid2
=
7206 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
7209 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7210 0, 0, 640, 480, 0, 0, 0, 0);
7211 ddraw
= create_ddraw();
7212 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7213 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7214 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7216 reset_ddsd(&surface_desc
);
7217 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
7218 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
7219 surface_desc
.dwHeight
= 4;
7220 surface_desc
.dwWidth
= 4;
7221 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7222 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7224 /* NULL pointers are not valid, but don't cause a crash. */
7225 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
,
7226 sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
7227 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7228 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 0, 0);
7229 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7230 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 1, 0);
7231 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7233 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
7234 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7235 0, DDSPD_IUNKNOWNPOINTER
);
7236 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7237 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7238 5, DDSPD_IUNKNOWNPOINTER
);
7239 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7240 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7241 sizeof(ddraw
) * 2, DDSPD_IUNKNOWNPOINTER
);
7242 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7244 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
7245 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
7246 * erases the old content and returns an error. This behavior has
7247 * been fixed in d3d8 and d3d9. Unless an application is found
7248 * that depends on this we don't care about this behavior. */
7249 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7250 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7251 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7252 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7253 0, DDSPD_IUNKNOWNPOINTER
);
7254 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7256 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7257 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7258 hr
= IDirectDrawSurface4_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7259 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7261 refcount
= get_refcount((IUnknown
*)ddraw
);
7262 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7263 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7264 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7265 refcount2
= get_refcount((IUnknown
*)ddraw
);
7266 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7268 hr
= IDirectDrawSurface4_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7269 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7270 refcount2
= get_refcount((IUnknown
*)ddraw
);
7271 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7273 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7274 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7275 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7276 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, surface
,
7277 sizeof(surface
), DDSPD_IUNKNOWNPOINTER
);
7278 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7279 refcount2
= get_refcount((IUnknown
*)ddraw
);
7280 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7282 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7283 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7284 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7285 size
= 2 * sizeof(ptr
);
7286 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7287 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7288 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7289 refcount2
= get_refcount(ptr
);
7290 /* Object is NOT addref'ed by the getter. */
7291 ok(ptr
== (IUnknown
*)ddraw
, "Returned interface pointer is %p, expected %p.\n", ptr
, ddraw
);
7292 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7294 ptr
= (IUnknown
*)0xdeadbeef;
7296 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7297 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7298 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7299 size
= 2 * sizeof(ptr
);
7300 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7301 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7302 ok(size
== 2 * sizeof(ptr
), "Got unexpected size %u.\n", size
);
7304 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7305 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7306 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7307 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7308 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, NULL
, NULL
);
7309 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7311 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, &ptr
, &size
);
7312 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7313 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7314 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
7315 hr
= IDirectDrawSurface4_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7316 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7318 refcount3
= IDirectDrawSurface4_Release(surface
);
7319 ok(!refcount3
, "Got unexpected refcount %u.\n", refcount3
);
7321 /* Destroying the surface frees the reference held on the private data. It also frees
7322 * the reference the surface is holding on its creating object. */
7323 refcount2
= get_refcount((IUnknown
*)ddraw
);
7324 ok(refcount2
== refcount
- 1, "Got unexpected refcount %u.\n", refcount2
);
7326 memset(&hal_caps
, 0, sizeof(hal_caps
));
7327 hal_caps
.dwSize
= sizeof(hal_caps
);
7328 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7329 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7330 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) == (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7332 reset_ddsd(&surface_desc
);
7333 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_MIPMAPCOUNT
;
7334 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7335 surface_desc
.dwHeight
= 4;
7336 surface_desc
.dwWidth
= 4;
7337 U2(surface_desc
).dwMipMapCount
= 2;
7338 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7339 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7340 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &surface2
);
7341 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7343 hr
= IDirectDrawSurface4_SetPrivateData(surface
, &ddraw_private_data_test_guid
, data
, sizeof(data
), 0);
7344 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7345 hr
= IDirectDrawSurface4_GetPrivateData(surface2
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7346 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7348 IDirectDrawSurface4_Release(surface2
);
7349 IDirectDrawSurface4_Release(surface
);
7352 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7354 refcount
= IDirectDraw4_Release(ddraw
);
7355 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7356 DestroyWindow(window
);
7359 static void test_pixel_format(void)
7361 HWND window
, window2
= NULL
;
7362 HDC hdc
, hdc2
= NULL
;
7364 int format
, test_format
;
7365 PIXELFORMATDESCRIPTOR pfd
;
7366 IDirectDraw4
*ddraw
= NULL
;
7367 IDirectDrawClipper
*clipper
= NULL
;
7368 DDSURFACEDESC2 ddsd
;
7369 IDirectDrawSurface4
*primary
= NULL
;
7373 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7374 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7377 skip("Failed to create window\n");
7381 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7382 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7384 hdc
= GetDC(window
);
7387 skip("Failed to get DC\n");
7392 hdc2
= GetDC(window2
);
7394 gl
= LoadLibraryA("opengl32.dll");
7395 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7397 format
= GetPixelFormat(hdc
);
7398 ok(format
== 0, "new window has pixel format %d\n", format
);
7400 ZeroMemory(&pfd
, sizeof(pfd
));
7401 pfd
.nSize
= sizeof(pfd
);
7403 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
7404 pfd
.iPixelType
= PFD_TYPE_RGBA
;
7405 pfd
.iLayerType
= PFD_MAIN_PLANE
;
7406 format
= ChoosePixelFormat(hdc
, &pfd
);
7409 skip("no pixel format available\n");
7413 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
7415 skip("failed to set pixel format\n");
7419 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
7421 skip("failed to set pixel format on second window\n");
7424 ReleaseDC(window2
, hdc2
);
7429 ddraw
= create_ddraw();
7430 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7432 test_format
= GetPixelFormat(hdc
);
7433 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7435 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7438 skip("Failed to set cooperative level, hr %#x.\n", hr
);
7442 test_format
= GetPixelFormat(hdc
);
7443 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7447 hr
= IDirectDraw4_CreateClipper(ddraw
, 0, &clipper
, NULL
);
7448 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
7449 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
7450 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
7452 test_format
= GetPixelFormat(hdc
);
7453 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7455 test_format
= GetPixelFormat(hdc2
);
7456 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7459 memset(&ddsd
, 0, sizeof(ddsd
));
7460 ddsd
.dwSize
= sizeof(ddsd
);
7461 ddsd
.dwFlags
= DDSD_CAPS
;
7462 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7464 hr
= IDirectDraw4_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
7465 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
7467 test_format
= GetPixelFormat(hdc
);
7468 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7472 test_format
= GetPixelFormat(hdc2
);
7473 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7478 hr
= IDirectDrawSurface4_SetClipper(primary
, clipper
);
7479 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
7481 test_format
= GetPixelFormat(hdc
);
7482 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7484 test_format
= GetPixelFormat(hdc2
);
7485 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7488 memset(&fx
, 0, sizeof(fx
));
7489 fx
.dwSize
= sizeof(fx
);
7490 hr
= IDirectDrawSurface4_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7491 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
7493 test_format
= GetPixelFormat(hdc
);
7494 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7498 test_format
= GetPixelFormat(hdc2
);
7499 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7503 if (primary
) IDirectDrawSurface4_Release(primary
);
7504 if (clipper
) IDirectDrawClipper_Release(clipper
);
7505 if (ddraw
) IDirectDraw4_Release(ddraw
);
7506 if (gl
) FreeLibrary(gl
);
7507 if (hdc
) ReleaseDC(window
, hdc
);
7508 if (hdc2
) ReleaseDC(window2
, hdc2
);
7509 if (window
) DestroyWindow(window
);
7510 if (window2
) DestroyWindow(window2
);
7513 static void test_create_surface_pitch(void)
7515 IDirectDrawSurface4
*surface
;
7516 DDSURFACEDESC2 surface_desc
;
7517 IDirectDraw4
*ddraw
;
7537 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7539 DDSD_PITCH
, 0x100, 0x100},
7540 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7541 DDSD_PITCH
, 0x104, DD_OK
,
7542 DDSD_PITCH
, 0x100, 0x100},
7543 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7544 DDSD_PITCH
, 0x0f8, DD_OK
,
7545 DDSD_PITCH
, 0x100, 0x100},
7546 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7547 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7549 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7551 DDSD_PITCH
, 0x100, 0x0fc},
7553 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7554 DDSD_PITCH
, 0x104, DD_OK
,
7555 DDSD_PITCH
, 0x100, 0x0fc},
7556 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7557 DDSD_PITCH
, 0x0f8, DD_OK
,
7558 DDSD_PITCH
, 0x100, 0x0fc},
7559 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7560 DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
7561 DDSD_PITCH
, 0x100, 0x0fc},
7562 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7563 DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
7565 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7566 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7567 DDSD_PITCH
, 0x100, 0x100},
7569 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7570 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fe, DDERR_INVALIDPARAMS
,
7572 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7573 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fc, DD_OK
,
7574 DDSD_PITCH
, 0x0fc, 0x0fc},
7575 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7576 DDSD_LPSURFACE
| DDSD_PITCH
, 0x0f8, DDERR_INVALIDPARAMS
,
7578 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7579 DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x100, DDERR_INVALIDPARAMS
,
7581 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7582 DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x3f00, DDERR_INVALIDPARAMS
,
7585 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
7586 DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, 0x100, DD_OK
,
7587 DDSD_PITCH
, 0x100, 0x100},
7588 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
7589 0, 0, DDERR_INVALIDCAPS
,
7591 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7593 DDSD_PITCH
, 0x100, 0 },
7594 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7595 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7597 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
7598 0, 0, DDERR_INVALIDCAPS
,
7601 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7603 DDSD_PITCH
, 0x100, 0 },
7604 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
7605 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7606 DDSD_PITCH
, 0x100, 0 },
7608 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
7610 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7611 0, 0, 640, 480, 0, 0, 0, 0);
7612 ddraw
= create_ddraw();
7613 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7614 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7615 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7617 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
7619 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
7621 memset(&surface_desc
, 0, sizeof(surface_desc
));
7622 surface_desc
.dwSize
= sizeof(surface_desc
);
7623 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
7624 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
7625 surface_desc
.dwWidth
= 63;
7626 surface_desc
.dwHeight
= 63;
7627 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
7628 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7629 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7630 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7631 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7632 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7633 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7634 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7635 if (test_data
[i
].flags_in
& DDSD_LPSURFACE
)
7637 HRESULT expected_hr
= SUCCEEDED(test_data
[i
].hr
) ? DDERR_INVALIDPARAMS
: test_data
[i
].hr
;
7638 ok(hr
== expected_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, expected_hr
);
7639 surface_desc
.lpSurface
= mem
;
7640 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7642 if ((test_data
[i
].caps
& DDSCAPS_VIDEOMEMORY
) && hr
== DDERR_NODIRECTDRAWHW
)
7644 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
7648 memset(&surface_desc
, 0, sizeof(surface_desc
));
7649 surface_desc
.dwSize
= sizeof(surface_desc
);
7650 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
7651 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7652 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
7653 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7654 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
7655 /* The pitch for textures seems to be implementation specific. */
7656 if (!(test_data
[i
].caps
& DDSCAPS_TEXTURE
))
7658 if (is_ddraw64
&& test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
7659 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
7660 "Test %u: Got unexpected pitch %u, expected %u.\n",
7661 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
7663 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
7664 "Test %u: Got unexpected pitch %u, expected %u.\n",
7665 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
7667 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
7669 IDirectDrawSurface4_Release(surface
);
7672 HeapFree(GetProcessHeap(), 0, mem
);
7673 refcount
= IDirectDraw4_Release(ddraw
);
7674 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7675 DestroyWindow(window
);
7678 static void test_mipmap(void)
7680 IDirectDrawSurface4
*surface
, *surface2
;
7681 DDSURFACEDESC2 surface_desc
;
7682 IDirectDraw4
*ddraw
;
7687 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7696 DWORD mipmap_count_in
;
7698 DWORD mipmap_count_out
;
7702 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 3, DD_OK
, 3},
7703 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDPARAMS
, 0},
7704 {0, DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 1},
7705 {0, DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDCAPS
, 0},
7706 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 6},
7707 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 32, 64, 0, DD_OK
, 6},
7710 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7711 0, 0, 640, 480, 0, 0, 0, 0);
7712 ddraw
= create_ddraw();
7713 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7714 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7715 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7717 memset(&hal_caps
, 0, sizeof(hal_caps
));
7718 hal_caps
.dwSize
= sizeof(hal_caps
);
7719 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
7720 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7721 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7723 skip("Mipmapped textures not supported, skipping tests.\n");
7724 IDirectDraw4_Release(ddraw
);
7725 DestroyWindow(window
);
7729 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
7731 memset(&surface_desc
, 0, sizeof(surface_desc
));
7732 surface_desc
.dwSize
= sizeof(surface_desc
);
7733 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| tests
[i
].flags
;
7734 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
7735 surface_desc
.dwWidth
= tests
[i
].width
;
7736 surface_desc
.dwHeight
= tests
[i
].height
;
7737 if (tests
[i
].flags
& DDSD_MIPMAPCOUNT
)
7738 U2(surface_desc
).dwMipMapCount
= tests
[i
].mipmap_count_in
;
7739 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7740 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
7744 memset(&surface_desc
, 0, sizeof(surface_desc
));
7745 surface_desc
.dwSize
= sizeof(surface_desc
);
7746 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
7747 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7748 ok(surface_desc
.dwFlags
& DDSD_MIPMAPCOUNT
,
7749 "Test %u: Got unexpected flags %#x.\n", i
, surface_desc
.dwFlags
);
7750 ok(U2(surface_desc
).dwMipMapCount
== tests
[i
].mipmap_count_out
,
7751 "Test %u: Got unexpected mipmap count %u.\n", i
, U2(surface_desc
).dwMipMapCount
);
7753 if (U2(surface_desc
).dwMipMapCount
> 1)
7755 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &surface2
);
7756 ok(SUCCEEDED(hr
), "Test %u: Failed to get attached surface, hr %#x.\n", i
, hr
);
7758 memset(&surface_desc
, 0, sizeof(surface_desc
));
7759 surface_desc
.dwSize
= sizeof(surface_desc
);
7760 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7761 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
7762 memset(&surface_desc
, 0, sizeof(surface_desc
));
7763 surface_desc
.dwSize
= sizeof(surface_desc
);
7764 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
7765 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
7766 IDirectDrawSurface4_Unlock(surface2
, NULL
);
7767 IDirectDrawSurface4_Unlock(surface
, NULL
);
7769 IDirectDrawSurface4_Release(surface2
);
7772 IDirectDrawSurface4_Release(surface
);
7775 refcount
= IDirectDraw4_Release(ddraw
);
7776 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7777 DestroyWindow(window
);
7780 static void test_palette_complex(void)
7782 IDirectDrawSurface4
*surface
, *mipmap
, *tmp
;
7783 DDSURFACEDESC2 surface_desc
;
7784 IDirectDraw4
*ddraw
;
7785 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
7789 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7791 PALETTEENTRY palette_entries
[256];
7797 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7798 0, 0, 640, 480, 0, 0, 0, 0);
7799 ddraw
= create_ddraw();
7800 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7801 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7802 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7804 memset(&hal_caps
, 0, sizeof(hal_caps
));
7805 hal_caps
.dwSize
= sizeof(hal_caps
);
7806 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
7807 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7808 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
7810 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7811 IDirectDraw4_Release(ddraw
);
7812 DestroyWindow(window
);
7816 memset(&surface_desc
, 0, sizeof(surface_desc
));
7817 surface_desc
.dwSize
= sizeof(surface_desc
);
7818 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7819 surface_desc
.dwWidth
= 128;
7820 surface_desc
.dwHeight
= 128;
7821 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7822 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7823 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7824 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7825 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7826 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7828 memset(palette_entries
, 0, sizeof(palette_entries
));
7829 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7830 palette_entries
, &palette
, NULL
);
7831 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7833 memset(palette_entries
, 0, sizeof(palette_entries
));
7834 palette_entries
[1].peRed
= 0xff;
7835 palette_entries
[1].peGreen
= 0x80;
7836 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7837 palette_entries
, &palette_mipmap
, NULL
);
7838 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7840 palette2
= (void *)0xdeadbeef;
7841 hr
= IDirectDrawSurface4_GetPalette(surface
, &palette2
);
7842 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
7843 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
7844 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
7845 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7846 hr
= IDirectDrawSurface4_GetPalette(surface
, &palette2
);
7847 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
7848 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
7849 IDirectDrawPalette_Release(palette2
);
7852 IDirectDrawSurface4_AddRef(mipmap
);
7853 for (i
= 0; i
< 7; ++i
)
7855 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7856 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
7857 palette2
= (void *)0xdeadbeef;
7858 hr
= IDirectDrawSurface4_GetPalette(tmp
, &palette2
);
7859 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7860 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
7862 hr
= IDirectDrawSurface4_SetPalette(tmp
, palette_mipmap
);
7863 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
7865 hr
= IDirectDrawSurface4_GetPalette(tmp
, &palette2
);
7866 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
7867 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
7868 IDirectDrawPalette_Release(palette2
);
7870 hr
= IDirectDrawSurface4_GetDC(tmp
, &dc
);
7871 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
7872 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
7873 ok(count
== 1, "Expected count 1, got %u.\n", count
);
7874 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
7875 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
7876 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
7877 hr
= IDirectDrawSurface4_ReleaseDC(tmp
, dc
);
7878 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
7880 IDirectDrawSurface4_Release(mipmap
);
7884 hr
= IDirectDrawSurface4_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7885 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7886 IDirectDrawSurface4_Release(mipmap
);
7887 refcount
= IDirectDrawSurface4_Release(surface
);
7888 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7889 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
7890 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7891 refcount
= IDirectDrawPalette_Release(palette
);
7892 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7894 refcount
= IDirectDraw4_Release(ddraw
);
7895 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7896 DestroyWindow(window
);
7899 static void test_p8_rgb_blit(void)
7901 IDirectDrawSurface4
*src
, *dst
;
7902 DDSURFACEDESC2 surface_desc
;
7903 IDirectDraw4
*ddraw
;
7904 IDirectDrawPalette
*palette
;
7908 PALETTEENTRY palette_entries
[256];
7910 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7911 static const D3DCOLOR expected
[] =
7913 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7914 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7918 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7919 0, 0, 640, 480, 0, 0, 0, 0);
7920 ddraw
= create_ddraw();
7921 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7922 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7923 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7925 memset(palette_entries
, 0, sizeof(palette_entries
));
7926 palette_entries
[1].peGreen
= 0xff;
7927 palette_entries
[2].peBlue
= 0xff;
7928 palette_entries
[3].peFlags
= 0xff;
7929 palette_entries
[4].peRed
= 0xff;
7930 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7931 palette_entries
, &palette
, NULL
);
7932 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7934 memset(&surface_desc
, 0, sizeof(surface_desc
));
7935 surface_desc
.dwSize
= sizeof(surface_desc
);
7936 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7937 surface_desc
.dwWidth
= 8;
7938 surface_desc
.dwHeight
= 1;
7939 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7940 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7941 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7942 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7943 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
7944 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7946 memset(&surface_desc
, 0, sizeof(surface_desc
));
7947 surface_desc
.dwSize
= sizeof(surface_desc
);
7948 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7949 surface_desc
.dwWidth
= 8;
7950 surface_desc
.dwHeight
= 1;
7951 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7952 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7953 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
7954 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7955 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7956 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7957 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7958 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
7959 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
7960 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7962 memset(&surface_desc
, 0, sizeof(surface_desc
));
7963 surface_desc
.dwSize
= sizeof(surface_desc
);
7964 hr
= IDirectDrawSurface4_Lock(src
, NULL
, &surface_desc
, 0, NULL
);
7965 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
7966 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
7967 hr
= IDirectDrawSurface4_Unlock(src
, NULL
);
7968 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
7970 hr
= IDirectDrawSurface4_SetPalette(src
, palette
);
7971 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7972 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
7973 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
7974 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
7975 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
7976 "Failed to blit, hr %#x.\n", hr
);
7980 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
7982 color
= get_surface_color(dst
, x
, 0);
7983 todo_wine
ok(compare_color(color
, expected
[x
], 0),
7984 "Pixel %u: Got color %#x, expected %#x.\n",
7985 x
, color
, expected
[x
]);
7989 IDirectDrawSurface4_Release(src
);
7990 IDirectDrawSurface4_Release(dst
);
7991 IDirectDrawPalette_Release(palette
);
7993 refcount
= IDirectDraw4_Release(ddraw
);
7994 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7995 DestroyWindow(window
);
7998 static void test_material(void)
8000 D3DMATERIALHANDLE mat_handle
, tmp
;
8001 IDirect3DMaterial3
*material
;
8002 IDirect3DViewport3
*viewport
;
8003 IDirect3DDevice3
*device
;
8004 IDirectDrawSurface4
*rt
;
8014 struct vec3 position
;
8020 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
8021 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
8022 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
8023 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffffffff},
8027 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8028 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8029 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8030 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8036 D3DCOLOR expected_color
;
8040 {quad1
, TRUE
, 0x0000ff00},
8041 {quad2
, TRUE
, 0x0000ff00},
8042 {quad1
, FALSE
, 0x00ffffff},
8043 {quad2
, FALSE
, 0x00ff0000},
8045 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8047 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8048 0, 0, 640, 480, 0, 0, 0, 0);
8049 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8051 skip("Failed to create a 3D device, skipping test.\n");
8052 DestroyWindow(window
);
8056 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
8057 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8059 viewport
= create_viewport(device
, 0, 0, 640, 480);
8060 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
8061 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
8063 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
8064 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
8065 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
8067 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
8068 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
8069 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
8070 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
8071 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
8072 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
8073 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
8074 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
8075 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, 0);
8076 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
8077 hr
= IDirect3DDevice3_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
8078 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
8079 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
8081 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
8083 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
,
8084 D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xff0000ff, 1.0f
, 0);
8085 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8087 hr
= IDirect3DDevice3_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
8088 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
8090 hr
= IDirect3DDevice3_BeginScene(device
);
8091 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8092 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
8093 D3DFVF_XYZ
| D3DFVF_NORMAL
| D3DFVF_DIFFUSE
, test_data
[i
].data
, 4, 0);
8094 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8095 hr
= IDirect3DDevice3_EndScene(device
);
8096 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8097 color
= get_surface_color(rt
, 320, 240);
8098 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
8099 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
8102 destroy_material(material
);
8103 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
8104 hr
= IDirect3DMaterial3_GetHandle(material
, device
, &mat_handle
);
8105 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
8107 hr
= IDirect3DViewport3_SetBackground(viewport
, mat_handle
);
8108 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
8109 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
8110 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
8111 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
8112 ok(valid
, "Got unexpected valid %#x.\n", valid
);
8113 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8114 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8115 color
= get_surface_color(rt
, 320, 240);
8116 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8118 hr
= IDirect3DViewport3_SetBackground(viewport
, 0);
8119 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8120 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
8121 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
8122 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
8123 ok(valid
, "Got unexpected valid %#x.\n", valid
);
8124 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8125 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8126 color
= get_surface_color(rt
, 320, 240);
8127 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8129 destroy_viewport(device
, viewport
);
8130 viewport
= create_viewport(device
, 0, 0, 640, 480);
8132 hr
= IDirect3DViewport3_GetBackground(viewport
, &tmp
, &valid
);
8133 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
8134 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
8135 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
8136 hr
= IDirect3DViewport3_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8137 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8138 color
= get_surface_color(rt
, 320, 240);
8139 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
8141 destroy_viewport(device
, viewport
);
8142 destroy_material(material
);
8143 IDirectDrawSurface4_Release(rt
);
8144 refcount
= IDirect3DDevice3_Release(device
);
8145 ok(!refcount
, "Device has %u references left.\n", refcount
);
8146 DestroyWindow(window
);
8149 static void test_palette_gdi(void)
8151 IDirectDrawSurface4
*surface
, *primary
;
8152 DDSURFACEDESC2 surface_desc
;
8153 IDirectDraw4
*ddraw
;
8154 IDirectDrawPalette
*palette
, *palette2
;
8158 PALETTEENTRY palette_entries
[256];
8161 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
8162 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
8163 * not the point of this test. */
8164 static const RGBQUAD expected1
[] =
8166 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8167 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
8169 static const RGBQUAD expected2
[] =
8171 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
8172 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
8174 static const RGBQUAD expected3
[] =
8176 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
8177 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
8179 HPALETTE ddraw_palette_handle
;
8180 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
8181 RGBQUAD rgbquad
[255];
8182 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
8184 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8185 0, 0, 640, 480, 0, 0, 0, 0);
8186 ddraw
= create_ddraw();
8187 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8188 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8189 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8191 memset(&surface_desc
, 0, sizeof(surface_desc
));
8192 surface_desc
.dwSize
= sizeof(surface_desc
);
8193 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8194 surface_desc
.dwWidth
= 16;
8195 surface_desc
.dwHeight
= 16;
8196 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8197 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8198 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
8199 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
8200 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8201 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8203 /* Avoid colors from the Windows default palette. */
8204 memset(palette_entries
, 0, sizeof(palette_entries
));
8205 palette_entries
[1].peRed
= 0x01;
8206 palette_entries
[2].peGreen
= 0x02;
8207 palette_entries
[3].peBlue
= 0x03;
8208 palette_entries
[4].peRed
= 0x13;
8209 palette_entries
[4].peGreen
= 0x14;
8210 palette_entries
[4].peBlue
= 0x15;
8211 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
8212 palette_entries
, &palette
, NULL
);
8213 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8215 /* If there is no palette assigned and the display mode is not 8 bpp, some
8216 * drivers refuse to create a DC while others allow it. If a DC is created,
8217 * the DIB color table is uninitialized and contains random colors. No error
8218 * is generated when trying to read pixels and random garbage is returned.
8220 * The most likely explanation is that if the driver creates a DC, it (or
8221 * the higher-level runtime) uses GetSystemPaletteEntries to find the
8222 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
8223 * contains uninitialized garbage. See comments below for the P8 case. */
8225 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8226 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8227 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8228 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8229 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
8230 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
8231 "Got unexpected palette %p, expected %p.\n",
8232 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
8234 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8235 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8236 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
8238 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
8239 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8240 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8241 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
8243 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8245 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8246 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8247 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8250 /* Update the palette while the DC is in use. This does not modify the DC. */
8251 palette_entries
[4].peRed
= 0x23;
8252 palette_entries
[4].peGreen
= 0x24;
8253 palette_entries
[4].peBlue
= 0x25;
8254 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
8255 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
8257 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
8258 ok(i
== 1, "Expected count 1, got %u.\n", i
);
8259 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
8260 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8261 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
8262 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
8264 /* Neither does re-setting the palette. */
8265 hr
= IDirectDrawSurface4_SetPalette(surface
, NULL
);
8266 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8267 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8268 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8270 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
8271 ok(i
== 1, "Expected count 1, got %u.\n", i
);
8272 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
8273 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8274 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
8275 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
8277 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8278 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8280 /* Refresh the DC. This updates the palette. */
8281 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8282 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8283 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8284 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8285 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8287 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8288 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8289 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8290 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8292 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8294 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8295 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8296 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8298 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8299 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8301 refcount
= IDirectDrawSurface4_Release(surface
);
8302 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8304 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8306 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8307 IDirectDrawPalette_Release(palette
);
8308 IDirectDraw4_Release(ddraw
);
8309 DestroyWindow(window
);
8312 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
8313 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
8314 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8316 memset(&surface_desc
, 0, sizeof(surface_desc
));
8317 surface_desc
.dwSize
= sizeof(surface_desc
);
8318 surface_desc
.dwFlags
= DDSD_CAPS
;
8319 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8320 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
8321 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8323 hr
= IDirectDrawSurface4_SetPalette(primary
, palette
);
8324 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8325 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
8326 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8327 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
8328 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
8329 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
8330 "Got unexpected palette %p, expected %p.\n",
8331 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
8332 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
8334 /* The primary uses the system palette. In exclusive mode, the system palette matches
8335 * the ddraw palette attached to the primary, so the result is what you would expect
8336 * from a regular surface. Tests for the interaction between the ddraw palette and
8337 * the system palette are not included pending an application that depends on this.
8338 * The relation between those causes problems on Windows Vista and newer for games
8339 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
8340 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8341 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8342 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8344 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8345 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8346 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8347 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8349 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8351 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8352 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8353 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8355 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
8356 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8358 memset(&surface_desc
, 0, sizeof(surface_desc
));
8359 surface_desc
.dwSize
= sizeof(surface_desc
);
8360 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8361 surface_desc
.dwWidth
= 16;
8362 surface_desc
.dwHeight
= 16;
8363 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8364 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8365 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8367 /* Here the offscreen surface appears to use the primary's palette,
8368 * but in all likelihood it is actually the system palette. */
8369 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8370 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8371 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8372 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8373 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
8375 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
8376 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8377 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8378 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
8380 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8382 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8383 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8384 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8386 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8387 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8389 /* On real hardware a change to the primary surface's palette applies immediately,
8390 * even on device contexts from offscreen surfaces that do not have their own
8391 * palette. On the testbot VMs this is not the case. Don't test this until we
8392 * know of an application that depends on this. */
8394 memset(palette_entries
, 0, sizeof(palette_entries
));
8395 palette_entries
[1].peBlue
= 0x40;
8396 palette_entries
[2].peRed
= 0x40;
8397 palette_entries
[3].peGreen
= 0x40;
8398 palette_entries
[4].peRed
= 0x12;
8399 palette_entries
[4].peGreen
= 0x34;
8400 palette_entries
[4].peBlue
= 0x56;
8401 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
8402 palette_entries
, &palette2
, NULL
);
8403 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8404 hr
= IDirectDrawSurface4_SetPalette(surface
, palette2
);
8405 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
8407 /* A palette assigned to the offscreen surface overrides the primary / system
8409 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8410 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8411 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
8412 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
8413 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
8415 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
8416 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
8417 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
8418 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
8420 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
8422 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
8423 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
8424 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
8426 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8427 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8429 refcount
= IDirectDrawSurface4_Release(surface
);
8430 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8432 /* The Windows 8 testbot keeps extra references to the primary and
8433 * backbuffer while in 8 bpp mode. */
8434 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
8435 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8437 refcount
= IDirectDrawSurface4_Release(primary
);
8438 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8439 refcount
= IDirectDrawPalette_Release(palette2
);
8440 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8441 refcount
= IDirectDrawPalette_Release(palette
);
8442 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8443 refcount
= IDirectDraw4_Release(ddraw
);
8444 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8445 DestroyWindow(window
);
8448 static void test_palette_alpha(void)
8450 IDirectDrawSurface4
*surface
;
8451 DDSURFACEDESC2 surface_desc
;
8452 IDirectDraw4
*ddraw
;
8453 IDirectDrawPalette
*palette
;
8457 PALETTEENTRY palette_entries
[256];
8462 BOOL attach_allowed
;
8467 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
8468 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
8469 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
8472 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8473 0, 0, 640, 480, 0, 0, 0, 0);
8474 ddraw
= create_ddraw();
8475 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8476 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8478 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8479 IDirectDraw4_Release(ddraw
);
8480 DestroyWindow(window
);
8483 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8484 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8486 memset(palette_entries
, 0, sizeof(palette_entries
));
8487 palette_entries
[1].peFlags
= 0x42;
8488 palette_entries
[2].peFlags
= 0xff;
8489 palette_entries
[3].peFlags
= 0x80;
8490 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
8491 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8493 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8494 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8495 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8496 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8497 palette_entries
[0].peFlags
);
8498 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8499 palette_entries
[1].peFlags
);
8500 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8501 palette_entries
[2].peFlags
);
8502 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8503 palette_entries
[3].peFlags
);
8505 IDirectDrawPalette_Release(palette
);
8507 memset(palette_entries
, 0, sizeof(palette_entries
));
8508 palette_entries
[1].peFlags
= 0x42;
8509 palette_entries
[1].peRed
= 0xff;
8510 palette_entries
[2].peFlags
= 0xff;
8511 palette_entries
[3].peFlags
= 0x80;
8512 hr
= IDirectDraw4_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
8513 palette_entries
, &palette
, NULL
);
8514 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8516 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8517 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8518 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8519 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8520 palette_entries
[0].peFlags
);
8521 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8522 palette_entries
[1].peFlags
);
8523 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8524 palette_entries
[2].peFlags
);
8525 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8526 palette_entries
[3].peFlags
);
8528 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
8530 memset(&surface_desc
, 0, sizeof(surface_desc
));
8531 surface_desc
.dwSize
= sizeof(surface_desc
);
8532 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
8533 surface_desc
.dwWidth
= 128;
8534 surface_desc
.dwHeight
= 128;
8535 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
8536 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8537 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8539 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8540 if (test_data
[i
].attach_allowed
)
8541 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8543 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8551 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
8552 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8553 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
8554 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
8555 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8556 rgbquad
.rgbRed
, test_data
[i
].name
);
8557 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8558 rgbquad
.rgbGreen
, test_data
[i
].name
);
8559 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8560 rgbquad
.rgbBlue
, test_data
[i
].name
);
8561 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8562 rgbquad
.rgbReserved
, test_data
[i
].name
);
8563 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
8564 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8566 IDirectDrawSurface4_Release(surface
);
8569 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8570 memset(&surface_desc
, 0, sizeof(surface_desc
));
8571 surface_desc
.dwSize
= sizeof(surface_desc
);
8572 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8573 surface_desc
.dwWidth
= 128;
8574 surface_desc
.dwHeight
= 128;
8575 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8576 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8577 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8578 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
8579 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8580 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8581 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8582 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8583 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8584 hr
= IDirectDrawSurface4_SetPalette(surface
, palette
);
8585 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
8586 IDirectDrawSurface4_Release(surface
);
8588 /* The Windows 8 testbot keeps extra references to the primary
8589 * while in 8 bpp mode. */
8590 hr
= IDirectDraw4_RestoreDisplayMode(ddraw
);
8591 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8593 refcount
= IDirectDrawPalette_Release(palette
);
8594 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8595 refcount
= IDirectDraw4_Release(ddraw
);
8596 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8597 DestroyWindow(window
);
8600 static void test_vb_writeonly(void)
8602 IDirect3DDevice3
*device
;
8604 IDirect3DVertexBuffer
*buffer
;
8607 D3DVERTEXBUFFERDESC desc
;
8609 static const struct vec4 quad
[] =
8611 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
8612 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
8613 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
8614 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
8617 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8618 0, 0, 640, 480, 0, 0, 0, 0);
8620 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8622 skip("Failed to create a 3D device, skipping test.\n");
8623 DestroyWindow(window
);
8627 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
8628 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
8630 memset(&desc
, 0, sizeof(desc
));
8631 desc
.dwSize
= sizeof(desc
);
8632 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
8633 desc
.dwFVF
= D3DFVF_XYZRHW
;
8634 desc
.dwNumVertices
= sizeof(quad
) / sizeof(*quad
);
8635 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0, NULL
);
8636 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
8638 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, &ptr
, NULL
);
8639 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8640 memcpy(ptr
, quad
, sizeof(quad
));
8641 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8642 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8644 hr
= IDirect3DDevice3_BeginScene(device
);
8645 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8646 hr
= IDirect3DDevice3_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
8647 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8648 hr
= IDirect3DDevice3_EndScene(device
);
8649 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8651 hr
= IDirect3DVertexBuffer_Lock(buffer
, 0, &ptr
, NULL
);
8652 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8653 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8654 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8655 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8657 hr
= IDirect3DVertexBuffer_Lock(buffer
, DDLOCK_READONLY
, &ptr
, NULL
);
8658 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8659 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8660 hr
= IDirect3DVertexBuffer_Unlock(buffer
);
8661 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8663 IDirect3DVertexBuffer_Release(buffer
);
8664 IDirect3D3_Release(d3d
);
8665 IDirect3DDevice3_Release(device
);
8666 DestroyWindow(window
);
8669 static void test_lost_device(void)
8671 IDirectDrawSurface4
*surface
;
8672 DDSURFACEDESC2 surface_desc
;
8673 HWND window1
, window2
;
8674 IDirectDraw4
*ddraw
;
8679 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8680 0, 0, 640, 480, 0, 0, 0, 0);
8681 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8682 0, 0, 640, 480, 0, 0, 0, 0);
8683 ddraw
= create_ddraw();
8684 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8685 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8686 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8688 memset(&surface_desc
, 0, sizeof(surface_desc
));
8689 surface_desc
.dwSize
= sizeof(surface_desc
);
8690 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8691 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8692 U5(surface_desc
).dwBackBufferCount
= 1;
8693 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8694 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8696 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8697 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8698 hr
= IDirectDrawSurface4_IsLost(surface
);
8699 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8700 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8701 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8703 ret
= SetForegroundWindow(GetDesktopWindow());
8704 ok(ret
, "Failed to set foreground window.\n");
8705 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8706 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8707 hr
= IDirectDrawSurface4_IsLost(surface
);
8708 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8709 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8710 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8712 ret
= SetForegroundWindow(window1
);
8713 ok(ret
, "Failed to set foreground window.\n");
8714 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8715 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8716 hr
= IDirectDrawSurface4_IsLost(surface
);
8717 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8718 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8719 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8721 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
8722 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8723 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8724 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8725 hr
= IDirectDrawSurface4_IsLost(surface
);
8726 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8727 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8728 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8730 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8731 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8732 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8733 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8734 hr
= IDirectDrawSurface4_IsLost(surface
);
8735 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8736 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8737 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8739 /* Trying to restore the primary will crash, probably because flippable
8740 * surfaces can't exist in DDSCL_NORMAL. */
8741 IDirectDrawSurface4_Release(surface
);
8742 memset(&surface_desc
, 0, sizeof(surface_desc
));
8743 surface_desc
.dwSize
= sizeof(surface_desc
);
8744 surface_desc
.dwFlags
= DDSD_CAPS
;
8745 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8746 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8747 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8749 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8750 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8751 hr
= IDirectDrawSurface4_IsLost(surface
);
8752 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8754 ret
= SetForegroundWindow(GetDesktopWindow());
8755 ok(ret
, "Failed to set foreground window.\n");
8756 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8757 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8758 hr
= IDirectDrawSurface4_IsLost(surface
);
8759 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8761 ret
= SetForegroundWindow(window1
);
8762 ok(ret
, "Failed to set foreground window.\n");
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
);
8768 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8769 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8770 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8771 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8772 hr
= IDirectDrawSurface4_IsLost(surface
);
8773 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8775 hr
= IDirectDraw4_RestoreAllSurfaces(ddraw
);
8776 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8777 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8778 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8779 hr
= IDirectDrawSurface4_IsLost(surface
);
8780 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8782 IDirectDrawSurface4_Release(surface
);
8783 memset(&surface_desc
, 0, sizeof(surface_desc
));
8784 surface_desc
.dwSize
= sizeof(surface_desc
);
8785 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8786 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8787 U5(surface_desc
).dwBackBufferCount
= 1;
8788 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8789 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8791 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8792 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8793 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8794 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8795 hr
= IDirectDrawSurface4_IsLost(surface
);
8796 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8797 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8798 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8800 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8801 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8802 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8803 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8804 hr
= IDirectDrawSurface4_IsLost(surface
);
8805 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8806 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8807 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8809 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8810 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8811 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8812 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8813 hr
= IDirectDrawSurface4_IsLost(surface
);
8814 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8815 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8816 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8818 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
8819 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8820 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8821 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8822 hr
= IDirectDrawSurface4_IsLost(surface
);
8823 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8824 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8825 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8827 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8828 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8829 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8830 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8831 hr
= IDirectDrawSurface4_IsLost(surface
);
8832 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8833 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8834 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8836 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8837 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8838 hr
= IDirectDraw4_TestCooperativeLevel(ddraw
);
8839 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8840 hr
= IDirectDrawSurface4_IsLost(surface
);
8841 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8842 hr
= IDirectDrawSurface4_Flip(surface
, NULL
, DDFLIP_WAIT
);
8843 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8845 IDirectDrawSurface4_Release(surface
);
8846 refcount
= IDirectDraw4_Release(ddraw
);
8847 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8848 DestroyWindow(window2
);
8849 DestroyWindow(window1
);
8852 static void test_surface_desc_lock(void)
8854 IDirectDrawSurface4
*surface
;
8855 DDSURFACEDESC2 surface_desc
;
8856 IDirectDraw4
*ddraw
;
8861 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8862 0, 0, 640, 480, 0, 0, 0, 0);
8863 ddraw
= create_ddraw();
8864 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8865 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8866 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8868 memset(&surface_desc
, 0, sizeof(surface_desc
));
8869 surface_desc
.dwSize
= sizeof(surface_desc
);
8870 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8871 surface_desc
.dwWidth
= 16;
8872 surface_desc
.dwHeight
= 16;
8873 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8874 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8875 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8877 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8878 surface_desc
.dwSize
= sizeof(surface_desc
);
8879 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8880 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8881 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8883 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8884 surface_desc
.dwSize
= sizeof(surface_desc
);
8885 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
8886 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8887 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8888 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8889 surface_desc
.dwSize
= sizeof(surface_desc
);
8890 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8891 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8892 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8893 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
8894 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8896 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8897 surface_desc
.dwSize
= sizeof(surface_desc
);
8898 hr
= IDirectDrawSurface4_GetSurfaceDesc(surface
, &surface_desc
);
8899 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8900 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8902 IDirectDrawSurface4_Release(surface
);
8903 refcount
= IDirectDraw4_Release(ddraw
);
8904 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8905 DestroyWindow(window
);
8908 static void test_signed_formats(void)
8911 IDirect3DDevice3
*device
;
8913 IDirectDraw4
*ddraw
;
8914 IDirectDrawSurface4
*surface
, *rt
;
8915 IDirect3DTexture2
*texture
;
8916 IDirect3DViewport3
*viewport
;
8917 DDSURFACEDESC2 surface_desc
;
8920 D3DCOLOR color
, expected_color
;
8924 struct vec3 position
;
8925 struct vec2 texcoord
;
8929 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
8930 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
8931 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
8932 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
8934 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
8935 * of these values. */
8936 static const USHORT content_v8u8
[4][4] =
8938 {0x0000, 0x7f7f, 0x8880, 0x0000},
8939 {0x0080, 0x8000, 0x7f00, 0x007f},
8940 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
8941 {0x4444, 0xc0c0, 0xa066, 0x22e0},
8943 static const DWORD content_x8l8v8u8
[4][4] =
8945 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
8946 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
8947 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
8948 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
8950 static const USHORT content_l6v5u5
[4][4] =
8952 {0x0000, 0xfdef, 0x0230, 0xfc00},
8953 {0x0010, 0x0200, 0x01e0, 0x000f},
8954 {0x4067, 0x53b9, 0x0421, 0xffff},
8955 {0x8108, 0x0318, 0xc28c, 0x909c},
8960 const void *content
;
8963 unsigned int slop
, slop_broken
;
8964 DDPIXELFORMAT format
;
8969 "D3DFMT_V8U8", content_v8u8
, sizeof(WORD
), FALSE
, 1, 0,
8971 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
, 0,
8972 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
8976 "D3DFMT_X8L8V8U8", content_x8l8v8u8
, sizeof(DWORD
), TRUE
, 1, 0,
8978 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
8979 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
8983 "D3DFMT_L6V5U5", content_l6v5u5
, sizeof(WORD
), TRUE
, 4, 7,
8985 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
8986 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
8990 /* No V16U16 or Q8W8V8U8 support in ddraw. */
8992 static const D3DCOLOR expected_colors
[4][4] =
8994 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
8995 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
8996 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
8997 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
8999 unsigned int i
, width
, x
, y
;
9000 D3DDEVICEDESC device_desc
, hel_desc
;
9002 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9003 0, 0, 640, 480, 0, 0, 0, 0);
9005 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9007 skip("Failed to create a 3D device, skipping test.\n");
9008 DestroyWindow(window
);
9012 memset(&device_desc
, 0, sizeof(device_desc
));
9013 device_desc
.dwSize
= sizeof(device_desc
);
9014 memset(&hel_desc
, 0, sizeof(hel_desc
));
9015 hel_desc
.dwSize
= sizeof(hel_desc
);
9016 hr
= IDirect3DDevice3_GetCaps(device
, &device_desc
, &hel_desc
);
9017 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9018 if (!(device_desc
.dwTextureOpCaps
& D3DTEXOPCAPS_BLENDFACTORALPHA
))
9020 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
9024 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9025 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9026 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9027 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9028 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
9029 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9031 memset(&surface_desc
, 0, sizeof(surface_desc
));
9032 surface_desc
.dwSize
= sizeof(surface_desc
);
9033 hr
= IDirectDrawSurface4_GetSurfaceDesc(rt
, &surface_desc
);
9034 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
9035 viewport
= create_viewport(device
, 0, 0, surface_desc
.dwWidth
, surface_desc
.dwHeight
);
9036 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
9037 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
9038 U1(clear_rect
).x1
= 0;
9039 U2(clear_rect
).y1
= 0;
9040 U3(clear_rect
).x2
= surface_desc
.dwWidth
;
9041 U4(clear_rect
).y2
= surface_desc
.dwHeight
;
9043 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9044 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9046 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
9047 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x80ffffff);
9048 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9049 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BLENDFACTORALPHA
);
9050 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9051 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9052 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9053 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
9054 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9056 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
9058 for (width
= 1; width
< 5; width
+= 3)
9060 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
9061 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
9063 memset(&surface_desc
, 0, sizeof(surface_desc
));
9064 surface_desc
.dwSize
= sizeof(surface_desc
);
9065 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
9066 surface_desc
.dwWidth
= width
;
9067 surface_desc
.dwHeight
= 4;
9068 U4(surface_desc
).ddpfPixelFormat
= formats
[i
].format
;
9069 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
9070 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9073 skip("%s textures not supported, skipping.\n", formats
[i
].name
);
9076 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9078 hr
= IDirectDrawSurface4_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
9079 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture2 interface, hr %#x, format %s.\n",
9080 hr
, formats
[i
].name
);
9081 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture
);
9082 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9083 IDirect3DTexture2_Release(texture
);
9085 memset(&surface_desc
, 0, sizeof(surface_desc
));
9086 surface_desc
.dwSize
= sizeof(surface_desc
);
9087 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
9088 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9089 for (y
= 0; y
< 4; y
++)
9091 memcpy((char *)surface_desc
.lpSurface
+ y
* U1(surface_desc
).lPitch
,
9092 (char *)formats
[i
].content
+ y
* 4 * formats
[i
].pixel_size
,
9093 width
* formats
[i
].pixel_size
);
9095 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9096 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9098 hr
= IDirect3DDevice3_BeginScene(device
);
9099 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9100 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
9101 D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
9102 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9103 hr
= IDirect3DDevice3_EndScene(device
);
9104 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9106 for (y
= 0; y
< 4; y
++)
9108 for (x
= 0; x
< width
; x
++)
9110 expected_color
= expected_colors
[y
][x
];
9111 if (!formats
[i
].blue
)
9112 expected_color
|= 0x000000ff;
9114 color
= get_surface_color(rt
, 80 + 160 * x
, 60 + 120 * y
);
9115 ok(compare_color(color
, expected_color
, formats
[i
].slop
)
9116 || broken(compare_color(color
, expected_color
, formats
[i
].slop_broken
)),
9117 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9118 expected_color
, color
, formats
[i
].name
, x
, y
);
9122 IDirectDrawSurface4_Release(surface
);
9126 destroy_viewport(device
, viewport
);
9127 IDirectDrawSurface4_Release(rt
);
9128 IDirectDraw4_Release(ddraw
);
9129 IDirect3D3_Release(d3d
);
9132 refcount
= IDirect3DDevice3_Release(device
);
9133 ok(!refcount
, "Device has %u references left.\n", refcount
);
9134 DestroyWindow(window
);
9137 static void test_color_fill(void)
9140 IDirect3DDevice3
*device
;
9142 IDirectDraw4
*ddraw
;
9143 IDirectDrawSurface4
*surface
, *surface2
;
9144 DDSURFACEDESC2 surface_desc
;
9145 DDPIXELFORMAT z_fmt
;
9150 RECT rect
= {5, 5, 7, 7};
9152 DWORD supported_fmts
= 0, num_fourcc_codes
, *fourcc_codes
;
9157 HRESULT colorfill_hr
, depthfill_hr
;
9162 DDPIXELFORMAT format
;
9167 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9168 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9170 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9171 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9175 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9176 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9178 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9179 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9183 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9184 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
9186 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9187 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9191 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9192 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
9194 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9195 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9199 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
9200 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "managed texture RGB", 0xdeadbeef, TRUE
,
9202 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9203 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9207 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
, 0,
9208 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
9209 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9212 DDSCAPS_ZBUFFER
| DDSCAPS_SYSTEMMEMORY
, 0,
9213 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "sysmem zbuffer", 0, FALSE
,
9214 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9217 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9218 * different afterwards. DX9+ GPUs set one of the two luminance values
9219 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9220 * value they set. r200 (dx8) just sets the entire block to the clear
9222 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9223 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
9225 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9226 {0}, {0}, {0}, {0}, {0}
9230 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9231 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
9233 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9234 {0}, {0}, {0}, {0}, {0}
9238 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9239 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
9241 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9242 {0}, {0}, {0}, {0}, {0}
9246 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9247 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
9249 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9250 {0}, {0}, {0}, {0}, {0}
9254 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9255 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
9257 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9258 {0}, {0}, {0}, {0}, {0}
9262 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9263 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
9265 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9266 {0}, {0}, {0}, {0}, {0}
9270 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9271 * surface works, presumably because it is handled by the runtime instead of
9273 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9274 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
9276 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9277 {8}, {0}, {0}, {0}, {0}
9281 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9282 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
9284 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9285 {8}, {0}, {0}, {0}, {0}
9297 {SRCCOPY
, "SRCCOPY", DD_OK
},
9298 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
9299 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
9300 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
9301 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
9302 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
9303 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
9304 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
9305 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
9306 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
9307 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
9308 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
9309 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
9310 {BLACKNESS
, "BLACKNESS", DD_OK
},
9311 {WHITENESS
, "WHITENESS", DD_OK
},
9312 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
9315 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9316 0, 0, 640, 480, 0, 0, 0, 0);
9318 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9320 skip("Failed to create a 3D device, skipping test.\n");
9321 DestroyWindow(window
);
9325 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9326 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9327 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9328 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9330 memset(&z_fmt
, 0, sizeof(z_fmt
));
9331 IDirect3D3_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
9333 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9335 IDirect3DDevice3_EnumTextureFormats(device
, test_block_formats_creation_cb
, &supported_fmts
);
9336 if (!(supported_fmts
& SUPPORT_DXT1
))
9337 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9339 IDirect3D3_Release(d3d
);
9341 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
9342 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9343 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
9344 num_fourcc_codes
* sizeof(*fourcc_codes
));
9347 hr
= IDirectDraw4_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
9348 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9349 for (i
= 0; i
< num_fourcc_codes
; i
++)
9351 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9352 supported_fmts
|= SUPPORT_YUY2
;
9353 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9354 supported_fmts
|= SUPPORT_UYVY
;
9356 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
9358 memset(&hal_caps
, 0, sizeof(hal_caps
));
9359 hal_caps
.dwSize
= sizeof(hal_caps
);
9360 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
9361 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9363 if (!(supported_fmts
& (SUPPORT_YUY2
| SUPPORT_UYVY
)) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9364 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9366 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
9368 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9369 memset(&fx
, 0, sizeof(fx
));
9370 fx
.dwSize
= sizeof(fx
);
9371 U5(fx
).dwFillColor
= 0xdeadbeef;
9373 memset(&surface_desc
, 0, sizeof(surface_desc
));
9374 surface_desc
.dwSize
= sizeof(surface_desc
);
9375 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9376 surface_desc
.dwWidth
= 64;
9377 surface_desc
.dwHeight
= 64;
9378 U4(surface_desc
).ddpfPixelFormat
= tests
[i
].format
;
9379 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
9380 surface_desc
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
9382 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('D','X','T','1') && !(supported_fmts
& SUPPORT_DXT1
))
9384 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !(supported_fmts
& SUPPORT_YUY2
))
9386 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !(supported_fmts
& SUPPORT_UYVY
))
9388 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9391 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
9396 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9399 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9400 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9402 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9403 todo_wine_if (tests
[i
].format
.dwFourCC
)
9404 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9405 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9407 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9408 todo_wine_if (tests
[i
].format
.dwFourCC
)
9409 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9410 hr
, tests
[i
].colorfill_hr
, 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 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9420 *color
, tests
[i
].result
, tests
[i
].name
);
9421 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9422 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9425 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9426 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9427 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9428 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9429 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9430 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9432 U5(fx
).dwFillColor
= 0xdeadbeef;
9433 fx
.dwROP
= BLACKNESS
;
9434 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9435 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9436 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9437 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9438 U5(fx
).dwFillColor
, tests
[i
].name
);
9440 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9442 memset(&surface_desc
, 0, sizeof(surface_desc
));
9443 surface_desc
.dwSize
= sizeof(surface_desc
);
9444 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9445 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9446 color
= surface_desc
.lpSurface
;
9447 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9448 *color
, tests
[i
].name
);
9449 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9450 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9453 fx
.dwROP
= WHITENESS
;
9454 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9455 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9456 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9457 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9458 U5(fx
).dwFillColor
, tests
[i
].name
);
9460 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9462 memset(&surface_desc
, 0, sizeof(surface_desc
));
9463 surface_desc
.dwSize
= sizeof(surface_desc
);
9464 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9465 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9466 color
= surface_desc
.lpSurface
;
9467 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9468 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9469 *color
, tests
[i
].name
);
9470 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
9471 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9474 IDirectDrawSurface4_Release(surface
);
9477 memset(&fx
, 0, sizeof(fx
));
9478 fx
.dwSize
= sizeof(fx
);
9479 U5(fx
).dwFillColor
= 0xdeadbeef;
9480 fx
.dwROP
= WHITENESS
;
9482 memset(&surface_desc
, 0, sizeof(surface_desc
));
9483 surface_desc
.dwSize
= sizeof(surface_desc
);
9484 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9485 surface_desc
.dwWidth
= 64;
9486 surface_desc
.dwHeight
= 64;
9487 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9488 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9489 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9490 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9491 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9492 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9493 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
9494 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9495 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9496 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9497 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9500 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
9501 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9502 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
9503 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9505 /* Unused source rectangle. */
9506 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9507 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9508 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9509 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9511 /* Unused source surface. */
9512 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9513 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9514 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9515 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9516 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9517 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9518 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9519 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9521 /* Inverted destination or source rectangle. */
9522 SetRect(&rect
, 5, 7, 7, 5);
9523 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9524 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9525 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9526 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9527 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9528 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9529 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9530 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9531 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9532 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9534 /* Negative rectangle. */
9535 SetRect(&rect
, -1, -1, 5, 5);
9536 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9537 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9538 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9539 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9540 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9541 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9542 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9543 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9544 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9545 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9547 /* Out of bounds rectangle. */
9548 SetRect(&rect
, 0, 0, 65, 65);
9549 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9550 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9551 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9552 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9554 /* Combine multiple flags. */
9555 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9556 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9557 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9558 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9559 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9560 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9562 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
9564 fx
.dwROP
= rops
[i
].rop
;
9565 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9566 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
9569 IDirectDrawSurface4_Release(surface2
);
9570 IDirectDrawSurface4_Release(surface
);
9575 memset(&surface_desc
, 0, sizeof(surface_desc
));
9576 surface_desc
.dwSize
= sizeof(surface_desc
);
9577 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9578 surface_desc
.dwWidth
= 64;
9579 surface_desc
.dwHeight
= 64;
9580 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9581 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
9582 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9583 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9584 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9585 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9588 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
9589 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9591 /* Unused source rectangle. */
9592 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9593 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9595 /* Unused source surface. */
9596 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9597 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9598 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9599 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9601 /* Inverted destination or source rectangle. */
9602 SetRect(&rect
, 5, 7, 7, 5);
9603 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9604 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9605 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9606 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9607 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9608 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9609 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9610 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9612 /* Negative rectangle. */
9613 SetRect(&rect
, -1, -1, 5, 5);
9614 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9615 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9616 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9617 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9618 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9619 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9620 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9621 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9623 /* Out of bounds rectangle. */
9624 SetRect(&rect
, 0, 0, 65, 65);
9625 hr
= IDirectDrawSurface4_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9626 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9628 /* Combine multiple flags. */
9629 hr
= IDirectDrawSurface4_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9630 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9632 IDirectDrawSurface4_Release(surface2
);
9633 IDirectDrawSurface4_Release(surface
);
9636 IDirectDraw4_Release(ddraw
);
9637 refcount
= IDirect3DDevice3_Release(device
);
9638 ok(!refcount
, "Device has %u references left.\n", refcount
);
9639 DestroyWindow(window
);
9642 static void test_texcoordindex(void)
9647 struct vec2 texcoord1
;
9648 struct vec2 texcoord2
;
9649 struct vec2 texcoord3
;
9653 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}, {0.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9654 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}, {0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
9655 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9656 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 0.0f
}},
9658 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_TEX3
;
9659 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9660 IDirect3DDevice3
*device
;
9662 IDirectDraw4
*ddraw
;
9663 IDirectDrawSurface4
*rt
;
9664 IDirect3DViewport3
*viewport
;
9667 IDirectDrawSurface4
*surface1
, *surface2
;
9668 IDirect3DTexture2
*texture1
, *texture2
;
9669 DDSURFACEDESC2 surface_desc
;
9674 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9675 0, 0, 640, 480, 0, 0, 0, 0);
9676 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9678 skip("Failed to create a 3D device, skipping test.\n");
9679 DestroyWindow(window
);
9683 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9684 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
9685 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9686 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
9687 IDirect3D3_Release(d3d
);
9689 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
9690 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9692 memset(&surface_desc
, 0, sizeof(surface_desc
));
9693 surface_desc
.dwSize
= sizeof(surface_desc
);
9694 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9695 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9696 surface_desc
.dwWidth
= 2;
9697 surface_desc
.dwHeight
= 2;
9698 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9699 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
9700 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9701 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9702 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9703 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9704 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
9705 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
9706 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9707 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9708 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9710 memset(&surface_desc
, 0, sizeof(surface_desc
));
9711 surface_desc
.dwSize
= sizeof(surface_desc
);
9712 hr
= IDirectDrawSurface4_Lock(surface1
, 0, &surface_desc
, 0, NULL
);
9713 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9714 ptr
= surface_desc
.lpSurface
;
9715 ptr
[0] = 0xff000000;
9716 ptr
[1] = 0xff00ff00;
9717 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9718 ptr
[0] = 0xff0000ff;
9719 ptr
[1] = 0xff00ffff;
9720 hr
= IDirectDrawSurface4_Unlock(surface1
, NULL
);
9721 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9723 memset(&surface_desc
, 0, sizeof(surface_desc
));
9724 surface_desc
.dwSize
= sizeof(surface_desc
);
9725 hr
= IDirectDrawSurface4_Lock(surface2
, 0, &surface_desc
, 0, NULL
);
9726 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9727 ptr
= surface_desc
.lpSurface
;
9728 ptr
[0] = 0xff000000;
9729 ptr
[1] = 0xff0000ff;
9730 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9731 ptr
[0] = 0xffff0000;
9732 ptr
[1] = 0xffff00ff;
9733 hr
= IDirectDrawSurface4_Unlock(surface2
, 0);
9734 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9736 viewport
= create_viewport(device
, 0, 0, 640, 480);
9737 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
9738 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
9740 hr
= IDirectDrawSurface4_QueryInterface(surface1
, &IID_IDirect3DTexture2
, (void **)&texture1
);
9741 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9742 hr
= IDirectDrawSurface4_QueryInterface(surface2
, &IID_IDirect3DTexture2
, (void **)&texture2
);
9743 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9744 hr
= IDirect3DDevice3_SetTexture(device
, 0, texture1
);
9745 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9746 hr
= IDirect3DDevice3_SetTexture(device
, 1, texture2
);
9747 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9748 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9749 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9750 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
9751 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9752 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9753 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9754 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_ADD
);
9755 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9756 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9757 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9758 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
9759 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9760 hr
= IDirect3DDevice3_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
9761 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9763 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_TEXCOORDINDEX
, 1);
9764 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9765 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 0);
9766 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9768 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
9769 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9771 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9772 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9774 hr
= IDirect3DDevice3_BeginScene(device
);
9775 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9776 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9777 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9778 hr
= IDirect3DDevice3_EndScene(device
);
9779 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9781 color
= get_surface_color(rt
, 160, 120);
9782 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9783 color
= get_surface_color(rt
, 480, 120);
9784 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9785 color
= get_surface_color(rt
, 160, 360);
9786 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
9787 color
= get_surface_color(rt
, 480, 360);
9788 ok(compare_color(color
, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color
);
9790 /* D3DTSS_TEXTURETRANSFORMFLAGS was introduced in D3D7, can't test it here. */
9792 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 2);
9793 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9795 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9796 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9798 hr
= IDirect3DDevice3_BeginScene(device
);
9799 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9800 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9801 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9802 hr
= IDirect3DDevice3_EndScene(device
);
9803 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9805 color
= get_surface_color(rt
, 160, 120);
9806 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9807 color
= get_surface_color(rt
, 480, 120);
9808 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9809 color
= get_surface_color(rt
, 160, 360);
9810 ok(compare_color(color
, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color
);
9811 color
= get_surface_color(rt
, 480, 360);
9812 ok(compare_color(color
, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color
);
9814 IDirect3DTexture2_Release(texture2
);
9815 IDirect3DTexture2_Release(texture1
);
9816 IDirectDrawSurface4_Release(surface2
);
9817 IDirectDrawSurface4_Release(surface1
);
9819 destroy_viewport(device
, viewport
);
9821 IDirectDrawSurface4_Release(rt
);
9822 IDirectDraw_Release(ddraw
);
9823 refcount
= IDirect3DDevice3_Release(device
);
9824 ok(!refcount
, "Device has %u references left.\n", refcount
);
9825 DestroyWindow(window
);
9828 static void test_colorkey_precision(void)
9833 struct vec2 texcoord
;
9837 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9838 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
9839 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9840 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
9842 IDirect3DDevice3
*device
;
9844 IDirectDraw4
*ddraw
;
9845 IDirectDrawSurface4
*rt
;
9846 IDirect3DViewport3
*viewport
;
9849 IDirectDrawSurface4
*src
, *dst
, *texture
;
9850 IDirect3DTexture2
*d3d_texture
;
9851 DDSURFACEDESC2 surface_desc
, lock_desc
;
9857 DWORD data
[4] = {0}, color_mask
;
9858 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9859 D3DDEVICEDESC device_desc
, hel_desc
;
9863 unsigned int max
, shift
, bpp
, clear
;
9870 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8",
9872 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9873 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
9878 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel",
9880 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9881 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9886 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel",
9888 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9889 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9894 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4",
9896 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9897 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
9903 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9904 0, 0, 640, 480, 0, 0, 0, 0);
9905 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9907 skip("Failed to create a 3D device, skipping test.\n");
9908 DestroyWindow(window
);
9912 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
9913 * (color key doesn't match although the values are equal), and a false
9914 * positive when the color key is 0 and the texture contains the value 1.
9915 * I don't want to mark this broken unconditionally since this would
9916 * essentially disable the test on Windows. Try to detect WARP (and I
9917 * guess mismatch other SW renderers) by its ability to texture from
9918 * system memory. Also on random occasions 254 == 255 and 255 != 255.*/
9919 memset(&device_desc
, 0, sizeof(device_desc
));
9920 device_desc
.dwSize
= sizeof(device_desc
);
9921 memset(&hel_desc
, 0, sizeof(hel_desc
));
9922 hel_desc
.dwSize
= sizeof(hel_desc
);
9923 hr
= IDirect3DDevice3_GetCaps(device
, &device_desc
, &hel_desc
);
9924 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9925 warp
= !!(device_desc
.dwDevCaps
& D3DDEVCAPS_TEXTURESYSTEMMEMORY
);
9927 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
9928 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
9929 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
9930 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
9931 IDirect3D3_Release(d3d
);
9932 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
9933 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9935 viewport
= create_viewport(device
, 0, 0, 640, 480);
9936 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
9937 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
9939 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9940 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
9941 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9942 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9943 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
9944 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
9945 /* Multiply the texture read result with 0, that way the result color if the key doesn't
9946 * match is constant. In theory color keying works without reading the texture result
9947 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
9949 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
9950 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9951 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9952 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9953 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
9954 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9955 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x00000000);
9956 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9958 memset(&fx
, 0, sizeof(fx
));
9959 fx
.dwSize
= sizeof(fx
);
9960 memset(&lock_desc
, 0, sizeof(lock_desc
));
9961 lock_desc
.dwSize
= sizeof(lock_desc
);
9963 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
9965 memset(&surface_desc
, 0, sizeof(surface_desc
));
9966 surface_desc
.dwSize
= sizeof(surface_desc
);
9967 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9968 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9969 surface_desc
.dwWidth
= 4;
9970 surface_desc
.dwHeight
= 1;
9971 U4(surface_desc
).ddpfPixelFormat
= tests
[t
].fmt
;
9972 /* Windows XP (at least with the r200 driver, other drivers untested) produces
9973 * garbage when doing color keyed texture->texture blits. */
9974 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
9975 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9976 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
9977 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9979 fx
.dwFillColor
= tests
[t
].clear
;
9980 /* On the w8 testbot (WARP driver) the blit result has different values in the
9982 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
9983 | U3(tests
[t
].fmt
).dwGBitMask
9984 | U4(tests
[t
].fmt
).dwBBitMask
;
9986 for (c
= 0; c
<= tests
[t
].max
; ++c
)
9988 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
9989 * texture after it has been set once... */
9990 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
9991 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9992 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9993 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9994 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
9995 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9996 hr
= IDirectDrawSurface4_QueryInterface(texture
, &IID_IDirect3DTexture2
, (void **)&d3d_texture
);
9997 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9998 hr
= IDirect3DDevice3_SetTexture(device
, 0, d3d_texture
);
9999 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
10001 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
10002 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
10004 hr
= IDirectDrawSurface4_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
10005 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10006 switch (tests
[t
].bpp
)
10009 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
10010 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
10011 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
10012 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
10016 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
10017 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
10018 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
10019 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
10022 hr
= IDirectDrawSurface4_Unlock(src
, 0);
10023 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10024 hr
= IDirectDrawSurface4_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
10025 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10027 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
10028 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
10029 hr
= IDirectDrawSurface4_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
10030 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10032 hr
= IDirectDrawSurface4_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
10033 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10035 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
10036 hr
= IDirectDrawSurface4_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
10037 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10038 switch (tests
[t
].bpp
)
10041 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
10042 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
10043 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
10044 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
10048 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
10049 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
10050 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
10051 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
10054 hr
= IDirectDrawSurface4_Unlock(dst
, 0);
10055 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10059 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10060 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
10062 if (data
[3] == tests
[t
].clear
)
10064 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10065 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10066 * even when a different surface is used. The blit itself doesn't draw anything,
10067 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10068 * never be masked out by the key.
10070 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10071 * terrible on WARP. */
10072 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10073 IDirect3DTexture2_Release(d3d_texture
);
10074 IDirectDrawSurface4_Release(texture
);
10075 IDirectDrawSurface4_Release(src
);
10076 IDirectDrawSurface4_Release(dst
);
10081 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10082 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
10084 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10085 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
10087 if (c
== tests
[t
].max
)
10088 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10089 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
10091 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10092 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
10094 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0x0000ff00, 1.0f
, 0);
10095 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10097 hr
= IDirect3DDevice3_BeginScene(device
);
10098 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10099 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
10100 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10101 hr
= IDirect3DDevice3_EndScene(device
);
10102 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10104 color
= get_surface_color(rt
, 80, 240);
10106 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10107 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10108 color
, tests
[t
].name
, c
);
10110 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
10111 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10112 color
, tests
[t
].name
, c
);
10114 color
= get_surface_color(rt
, 240, 240);
10115 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10116 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10117 color
, tests
[t
].name
, c
);
10119 color
= get_surface_color(rt
, 400, 240);
10120 if (c
== tests
[t
].max
)
10121 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10122 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10123 color
, tests
[t
].name
, c
);
10125 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
10126 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10127 color
, tests
[t
].name
, c
);
10129 IDirect3DTexture2_Release(d3d_texture
);
10130 IDirectDrawSurface4_Release(texture
);
10132 IDirectDrawSurface4_Release(src
);
10133 IDirectDrawSurface4_Release(dst
);
10137 destroy_viewport(device
, viewport
);
10138 IDirectDrawSurface4_Release(rt
);
10139 IDirectDraw4_Release(ddraw
);
10140 refcount
= IDirect3DDevice3_Release(device
);
10141 ok(!refcount
, "Device has %u references left.\n", refcount
);
10142 DestroyWindow(window
);
10145 static void test_range_colorkey(void)
10147 IDirectDraw4
*ddraw
;
10150 IDirectDrawSurface4
*surface
;
10151 DDSURFACEDESC2 surface_desc
;
10155 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10156 0, 0, 640, 480, 0, 0, 0, 0);
10157 ddraw
= create_ddraw();
10158 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10159 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10160 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10162 memset(&surface_desc
, 0, sizeof(surface_desc
));
10163 surface_desc
.dwSize
= sizeof(surface_desc
);
10164 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
10165 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10166 surface_desc
.dwWidth
= 1;
10167 surface_desc
.dwHeight
= 1;
10168 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10169 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10170 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10171 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10172 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10173 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
10175 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10176 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10177 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10178 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10179 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10181 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10182 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10183 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10184 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10186 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10187 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10188 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10189 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10190 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10191 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10193 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10194 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10195 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10196 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10198 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10199 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10200 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10201 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10203 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10204 ckey
.dwColorSpaceLowValue
= 0x00000000;
10205 ckey
.dwColorSpaceHighValue
= 0x00000001;
10206 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10207 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10209 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10210 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10211 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10212 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10214 ckey
.dwColorSpaceLowValue
= 0x00000001;
10215 ckey
.dwColorSpaceHighValue
= 0x00000000;
10216 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10217 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10219 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10220 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10221 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10222 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10224 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10225 ckey
.dwColorSpaceLowValue
= 0x00000000;
10226 ckey
.dwColorSpaceHighValue
= 0x00000000;
10227 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10228 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10230 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10231 ckey
.dwColorSpaceLowValue
= 0x00000001;
10232 ckey
.dwColorSpaceHighValue
= 0x00000000;
10233 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10234 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10235 ckey
.dwColorSpaceLowValue
= 0x00000000;
10236 ckey
.dwColorSpaceHighValue
= 0x00000001;
10237 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10238 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10239 /* Range destination keys don't work either. */
10240 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
10241 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10243 /* Just to show it's not because of A, R, and G having equal values. */
10244 ckey
.dwColorSpaceLowValue
= 0x00000000;
10245 ckey
.dwColorSpaceHighValue
= 0x01010101;
10246 hr
= IDirectDrawSurface4_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10247 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10249 /* None of these operations modified the key. */
10250 hr
= IDirectDrawSurface4_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10251 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10252 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10253 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10255 IDirectDrawSurface4_Release(surface
),
10256 refcount
= IDirectDraw4_Release(ddraw
);
10257 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
10258 DestroyWindow(window
);
10261 static void test_shademode(void)
10263 IDirect3DVertexBuffer
*vb_strip
, *vb_list
, *buffer
;
10264 IDirect3DViewport3
*viewport
;
10265 IDirect3DDevice3
*device
;
10266 D3DVERTEXBUFFERDESC desc
;
10267 IDirectDrawSurface4
*rt
;
10268 DWORD color0
, color1
;
10275 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10276 static const struct
10278 struct vec3 position
;
10283 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10284 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10285 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10286 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10290 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10291 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10292 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10294 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10295 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10296 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10298 static const struct
10302 DWORD color0
, color1
;
10306 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
10307 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10308 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10309 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10310 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
10311 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10314 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10315 0, 0, 640, 480, 0, 0, 0, 0);
10317 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10319 skip("Failed to create a 3D device, skipping test.\n");
10320 DestroyWindow(window
);
10324 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
10325 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
10326 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
10327 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10329 viewport
= create_viewport(device
, 0, 0, 640, 480);
10330 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
10331 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10333 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10334 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10336 memset(&desc
, 0, sizeof(desc
));
10337 desc
.dwSize
= sizeof(desc
);
10338 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
10339 desc
.dwFVF
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
10340 desc
.dwNumVertices
= sizeof(quad_strip
) / sizeof(*quad_strip
);
10341 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &vb_strip
, 0, NULL
);
10342 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10343 hr
= IDirect3DVertexBuffer_Lock(vb_strip
, 0, &data
, NULL
);
10344 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10345 memcpy(data
, quad_strip
, sizeof(quad_strip
));
10346 hr
= IDirect3DVertexBuffer_Unlock(vb_strip
);
10347 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10349 desc
.dwNumVertices
= sizeof(quad_list
) / sizeof(*quad_list
);
10350 hr
= IDirect3D3_CreateVertexBuffer(d3d
, &desc
, &vb_list
, 0, NULL
);
10351 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10352 hr
= IDirect3DVertexBuffer_Lock(vb_list
, 0, &data
, NULL
);
10353 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10354 memcpy(data
, quad_list
, sizeof(quad_list
));
10355 hr
= IDirect3DVertexBuffer_Unlock(vb_list
);
10356 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10358 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10359 * the color fixups we have to do for FLAT shading will be dependent on that. */
10361 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
10363 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
10364 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
10366 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
10367 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
10369 hr
= IDirect3DDevice3_BeginScene(device
);
10370 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10371 buffer
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? vb_strip
: vb_list
;
10372 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
10373 hr
= IDirect3DDevice3_DrawPrimitiveVB(device
, tests
[i
].primtype
, buffer
, 0, count
, 0);
10374 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10375 hr
= IDirect3DDevice3_EndScene(device
);
10376 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10378 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
10379 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
10381 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10382 * each triangle. This requires EXT_provoking_vertex or similar
10383 * functionality being available. */
10384 /* PHONG should be the same as GOURAUD, since no hardware implements
10386 ok(compare_color(color0
, tests
[i
].color0
, 1), "Test %u shading has color0 %08x, expected %08x.\n",
10387 i
, color0
, tests
[i
].color0
);
10388 ok(compare_color(color1
, tests
[i
].color1
, 1), "Test %u shading has color1 %08x, expected %08x.\n",
10389 i
, color1
, tests
[i
].color1
);
10392 IDirect3DVertexBuffer_Release(vb_strip
);
10393 IDirect3DVertexBuffer_Release(vb_list
);
10394 destroy_viewport(device
, viewport
);
10395 IDirectDrawSurface4_Release(rt
);
10396 IDirect3D3_Release(d3d
);
10397 refcount
= IDirect3DDevice3_Release(device
);
10398 ok(!refcount
, "Device has %u references left.\n", refcount
);
10399 DestroyWindow(window
);
10402 static void test_lockrect_invalid(void)
10405 IDirectDraw4
*ddraw
;
10406 IDirectDrawSurface4
*surface
;
10409 DDSURFACEDESC2 surface_desc
;
10411 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
10412 static RECT valid
[] =
10417 {120, 60, 128, 68},
10418 {60, 120, 68, 128},
10420 static RECT invalid
[] =
10422 {68, 60, 60, 68}, /* left > right */
10423 {60, 68, 68, 60}, /* top > bottom */
10424 {-8, 60, 0, 68}, /* left < surface */
10425 {60, -8, 68, 0}, /* top < surface */
10426 {-16, 60, -8, 68}, /* right < surface */
10427 {60, -16, 68, -8}, /* bottom < surface */
10428 {60, 60, 136, 68}, /* right > surface */
10429 {60, 60, 68, 136}, /* bottom > surface */
10430 {136, 60, 144, 68}, /* left > surface */
10431 {60, 136, 68, 144}, /* top > surface */
10433 static const struct
10441 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem offscreenplain", DDERR_INVALIDPARAMS
},
10442 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem offscreenplain", DDERR_INVALIDPARAMS
},
10443 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem texture", DDERR_INVALIDPARAMS
},
10444 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem texture", DDERR_INVALIDPARAMS
},
10445 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, "managed texture", DDERR_INVALIDPARAMS
},
10448 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10449 0, 0, 640, 480, 0, 0, 0, 0);
10450 ddraw
= create_ddraw();
10451 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10452 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10453 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10455 memset(&hal_caps
, 0, sizeof(hal_caps
));
10456 hal_caps
.dwSize
= sizeof(hal_caps
);
10457 hr
= IDirectDraw4_GetCaps(ddraw
, &hal_caps
, NULL
);
10458 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
10459 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
10460 || !(hal_caps
.ddsCaps
.dwCaps
& DDSCAPS2_TEXTUREMANAGE
))
10462 skip("Required surface types not supported, skipping test.\n");
10466 for (r
= 0; r
< sizeof(resources
) / sizeof(*resources
); ++r
)
10468 memset(&surface_desc
, 0, sizeof(surface_desc
));
10469 surface_desc
.dwSize
= sizeof(surface_desc
);
10470 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10471 surface_desc
.ddsCaps
.dwCaps
= resources
[r
].caps
;
10472 surface_desc
.ddsCaps
.dwCaps2
= resources
[r
].caps2
;
10473 surface_desc
.dwWidth
= 128;
10474 surface_desc
.dwHeight
= 128;
10475 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
10476 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10477 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10478 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xff0000;
10479 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x00ff00;
10480 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x0000ff;
10482 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10483 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10485 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, NULL
, DDLOCK_WAIT
, NULL
);
10486 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
10488 for (i
= 0; i
< sizeof(valid
) / sizeof(*valid
); ++i
)
10490 RECT
*rect
= &valid
[i
];
10492 memset(&surface_desc
, 0, sizeof(surface_desc
));
10493 surface_desc
.dwSize
= sizeof(surface_desc
);
10495 hr
= IDirectDrawSurface4_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10496 ok(SUCCEEDED(hr
), "Lock failed (%#x) for rect [%d, %d]->[%d, %d], type %s.\n",
10497 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, resources
[r
].name
);
10499 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10500 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10503 for (i
= 0; i
< sizeof(invalid
) / sizeof(*invalid
); ++i
)
10505 RECT
*rect
= &invalid
[i
];
10507 memset(&surface_desc
, 1, sizeof(surface_desc
));
10508 surface_desc
.dwSize
= sizeof(surface_desc
);
10510 hr
= IDirectDrawSurface4_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10511 ok(hr
== resources
[r
].hr
, "Lock returned %#x for rect [%d, %d]->[%d, %d], type %s.\n",
10512 hr
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, resources
[r
].name
);
10515 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10516 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10519 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
10522 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10523 ok(SUCCEEDED(hr
), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
10524 hr
, resources
[r
].name
);
10525 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
10526 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned %#x, type %s.\n",
10527 hr
, resources
[r
].name
);
10528 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10529 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10531 hr
= IDirectDrawSurface4_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
10532 ok(SUCCEEDED(hr
), "Lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
10533 valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, hr
);
10534 hr
= IDirectDrawSurface4_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
10535 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
10536 valid
[0].left
, valid
[0].top
, valid
[0].right
, valid
[0].bottom
, hr
);
10538 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
10539 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
10541 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
10542 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
10544 IDirectDrawSurface4_Release(surface
);
10548 IDirectDraw4_Release(ddraw
);
10549 DestroyWindow(window
);
10552 static void test_yv12_overlay(void)
10554 IDirectDrawSurface4
*src_surface
, *dst_surface
;
10555 RECT rect
= {13, 17, 14, 18};
10556 unsigned int offset
, y
;
10557 DDSURFACEDESC2 desc
;
10558 unsigned char *base
;
10559 IDirectDraw4
*ddraw
;
10563 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10564 0, 0, 640, 480, 0, 0, 0, 0);
10565 ddraw
= create_ddraw();
10566 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10567 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10568 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10570 if (!(src_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
10572 skip("Failed to create a YV12 overlay, skipping test.\n");
10576 memset(&desc
, 0, sizeof(desc
));
10577 desc
.dwSize
= sizeof(desc
);
10578 hr
= IDirectDrawSurface4_Lock(src_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
10579 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10581 ok(desc
.dwFlags
== (DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_PITCH
),
10582 "Got unexpected flags %#x.\n", desc
.dwFlags
);
10583 ok(desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_HWCODEC
)
10584 || desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
10585 "Got unexpected caps %#x.\n", desc
.ddsCaps
.dwCaps
);
10586 ok(desc
.dwWidth
== 256, "Got unexpected width %u.\n", desc
.dwWidth
);
10587 ok(desc
.dwHeight
== 256, "Got unexpected height %u.\n", desc
.dwHeight
);
10588 /* The overlay pitch seems to have 256 byte alignment. */
10589 ok(!(U1(desc
).lPitch
& 0xff), "Got unexpected pitch %u.\n", U1(desc
).lPitch
);
10591 /* Fill the surface with some data for the blit test. */
10592 base
= desc
.lpSurface
;
10594 for (y
= 0; y
< desc
.dwHeight
; ++y
)
10596 memset(base
+ U1(desc
).lPitch
* y
, 0x10, desc
.dwWidth
);
10599 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 4; ++y
)
10601 memset(base
+ U1(desc
).lPitch
* y
, 0x20, desc
.dwWidth
);
10604 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 2; ++y
)
10606 memset(base
+ U1(desc
).lPitch
* y
, 0x30, desc
.dwWidth
);
10609 hr
= IDirectDrawSurface4_Unlock(src_surface
, NULL
);
10610 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10612 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
10613 * other block-based formats like DXT the entire Y channel is stored in
10614 * one big chunk of memory, followed by the chroma channels. So partial
10615 * locks do not really make sense. Show that they are allowed nevertheless
10616 * and the offset points into the luminance data. */
10617 hr
= IDirectDrawSurface4_Lock(src_surface
, &rect
, &desc
, DDLOCK_WAIT
, NULL
);
10618 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10619 offset
= ((const unsigned char *)desc
.lpSurface
- base
);
10620 ok(offset
== rect
.top
* U1(desc
).lPitch
+ rect
.left
, "Got unexpected offset %u, expected %u.\n",
10621 offset
, rect
.top
* U1(desc
).lPitch
+ rect
.left
);
10622 hr
= IDirectDrawSurface4_Unlock(src_surface
, NULL
);
10623 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10625 if (!(dst_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
10627 /* Windows XP with a Radeon X1600 GPU refuses to create a second
10628 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
10629 skip("Failed to create a second YV12 surface, skipping blit test.\n");
10630 IDirectDrawSurface4_Release(src_surface
);
10634 hr
= IDirectDrawSurface4_Blt(dst_surface
, NULL
, src_surface
, NULL
, DDBLT_WAIT
, NULL
);
10635 /* VMware rejects YV12 blits. This behavior has not been seen on real
10636 * hardware yet, so mark it broken. */
10637 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
), "Failed to blit, hr %#x.\n", hr
);
10641 memset(&desc
, 0, sizeof(desc
));
10642 desc
.dwSize
= sizeof(desc
);
10643 hr
= IDirectDrawSurface4_Lock(dst_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
10644 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10646 base
= desc
.lpSurface
;
10647 ok(base
[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base
[0]);
10648 base
+= desc
.dwHeight
* U1(desc
).lPitch
;
10649 todo_wine
ok(base
[0] == 0x20, "Got unexpected V data 0x%02x.\n", base
[0]);
10650 base
+= desc
.dwHeight
/ 4 * U1(desc
).lPitch
;
10651 todo_wine
ok(base
[0] == 0x30, "Got unexpected U data 0x%02x.\n", base
[0]);
10653 hr
= IDirectDrawSurface4_Unlock(dst_surface
, NULL
);
10654 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10657 IDirectDrawSurface4_Release(dst_surface
);
10658 IDirectDrawSurface4_Release(src_surface
);
10660 IDirectDraw4_Release(ddraw
);
10661 DestroyWindow(window
);
10664 static void test_offscreen_overlay(void)
10666 IDirectDrawSurface4
*overlay
, *offscreen
, *primary
;
10667 DDSURFACEDESC2 surface_desc
;
10668 IDirectDraw4
*ddraw
;
10673 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10674 0, 0, 640, 480, 0, 0, 0, 0);
10675 ddraw
= create_ddraw();
10676 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10677 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10678 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10680 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
10682 skip("Failed to create a UYVY overlay, skipping test.\n");
10686 memset(&surface_desc
, 0, sizeof(surface_desc
));
10687 surface_desc
.dwSize
= sizeof(surface_desc
);
10688 surface_desc
.dwFlags
= DDSD_CAPS
;
10689 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
10690 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
10691 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
10693 /* On Windows 7, and probably Vista, UpdateOverlay() will return
10694 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
10695 * surface prevents this by disabling the dwm. */
10696 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
10697 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
10698 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
10699 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
10701 /* Try to overlay a NULL surface. */
10702 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_SHOW
, NULL
);
10703 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10704 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_HIDE
, NULL
);
10705 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10707 /* Try to overlay an offscreen surface. */
10708 memset(&surface_desc
, 0, sizeof(surface_desc
));
10709 surface_desc
.dwSize
= sizeof(surface_desc
);
10710 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
10711 surface_desc
.dwWidth
= 64;
10712 surface_desc
.dwHeight
= 64;
10713 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10714 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
10715 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10716 U4(surface_desc
).ddpfPixelFormat
.dwFourCC
= 0;
10717 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
10718 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
10719 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
10720 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
10721 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
10722 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
10724 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, offscreen
, NULL
, DDOVER_SHOW
, NULL
);
10725 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10727 /* Try to overlay the primary with a non-overlay surface. */
10728 hr
= IDirectDrawSurface4_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
10729 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
10730 hr
= IDirectDrawSurface4_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
10731 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
10733 IDirectDrawSurface4_Release(offscreen
);
10734 IDirectDrawSurface4_Release(primary
);
10735 IDirectDrawSurface4_Release(overlay
);
10737 IDirectDraw4_Release(ddraw
);
10738 DestroyWindow(window
);
10741 static void test_overlay_rect(void)
10743 IDirectDrawSurface4
*overlay
, *primary
;
10744 DDSURFACEDESC2 surface_desc
;
10745 RECT rect
= {0, 0, 64, 64};
10746 IDirectDraw4
*ddraw
;
10752 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10753 0, 0, 640, 480, 0, 0, 0, 0);
10754 ddraw
= create_ddraw();
10755 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10756 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10757 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10759 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
10761 skip("Failed to create a UYVY overlay, skipping test.\n");
10765 memset(&surface_desc
, 0, sizeof(surface_desc
));
10766 surface_desc
.dwSize
= sizeof(surface_desc
);
10767 surface_desc
.dwFlags
= DDSD_CAPS
;
10768 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
10769 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
10770 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
10772 /* On Windows 7, and probably Vista, UpdateOverlay() will return
10773 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
10774 * surface prevents this by disabling the dwm. */
10775 hr
= IDirectDrawSurface4_GetDC(primary
, &dc
);
10776 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
10777 hr
= IDirectDrawSurface4_ReleaseDC(primary
, dc
);
10778 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
10780 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
10781 * used. This is not true in Windows Vista and earlier, but changed in
10783 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
10784 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10785 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
10786 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10787 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
10788 ok(hr
== DD_OK
|| hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
10790 /* Show that the overlay position is the (top, left) coordinate of the
10791 * destination rectangle. */
10792 OffsetRect(&rect
, 32, 16);
10793 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
10794 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10795 pos_x
= -1; pos_y
= -1;
10796 hr
= IDirectDrawSurface4_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
10797 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
10798 ok(pos_x
== rect
.left
, "Got unexpected pos_x %d, expected %d.\n", pos_x
, rect
.left
);
10799 ok(pos_y
== rect
.top
, "Got unexpected pos_y %d, expected %d.\n", pos_y
, rect
.top
);
10801 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
10802 * seen that the overlay overlays the whole primary(==screen). */
10803 hr2
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, NULL
, 0, NULL
);
10804 ok(hr2
== DD_OK
|| hr2
== DDERR_INVALIDPARAMS
|| hr2
== DDERR_OUTOFCAPS
, "Got unexpected hr %#x.\n", hr2
);
10805 hr
= IDirectDrawSurface4_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
10806 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
10807 if (SUCCEEDED(hr2
))
10809 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
10810 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
10814 ok(pos_x
== 32, "Got unexpected pos_x %d.\n", pos_x
);
10815 ok(pos_y
== 16, "Got unexpected pos_y %d.\n", pos_y
);
10818 /* The position cannot be retrieved when the overlay is not shown. */
10819 hr
= IDirectDrawSurface4_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_HIDE
, NULL
);
10820 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
10821 pos_x
= -1; pos_y
= -1;
10822 hr
= IDirectDrawSurface4_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
10823 ok(hr
== DDERR_OVERLAYNOTVISIBLE
, "Got unexpected hr %#x.\n", hr
);
10824 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
10825 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
10827 IDirectDrawSurface4_Release(primary
);
10828 IDirectDrawSurface4_Release(overlay
);
10830 IDirectDraw4_Release(ddraw
);
10831 DestroyWindow(window
);
10834 static void test_blt(void)
10836 IDirectDrawSurface4
*surface
, *rt
;
10837 DDSURFACEDESC2 surface_desc
;
10838 IDirect3DDevice3
*device
;
10839 IDirectDraw4
*ddraw
;
10854 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit. */
10855 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, flipped source. */
10856 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, mirrored source. */
10857 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched x. */
10858 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched y. */
10859 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK
}, /* Full surface blit. */
10860 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT
}, /* Full surface, flipped destination. */
10861 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored destination. */
10862 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, flipped source. */
10863 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored source. */
10866 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10867 0, 0, 640, 480, 0, 0, 0, 0);
10868 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10870 skip("Failed to create a 3D device, skipping test.\n");
10871 DestroyWindow(window
);
10875 hr
= IDirect3DDevice3_GetDirect3D(device
, &d3d
);
10876 ok(SUCCEEDED(hr
), "Failed to get Direct3D3 interface, hr %#x.\n", hr
);
10877 hr
= IDirect3D3_QueryInterface(d3d
, &IID_IDirectDraw4
, (void **)&ddraw
);
10878 ok(SUCCEEDED(hr
), "Failed to get DirectDraw4 interface, hr %#x.\n", hr
);
10879 IDirect3D3_Release(d3d
);
10880 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
10881 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10883 memset(&surface_desc
, 0, sizeof(surface_desc
));
10884 surface_desc
.dwSize
= sizeof(surface_desc
);
10885 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
10886 surface_desc
.dwWidth
= 640;
10887 surface_desc
.dwHeight
= 480;
10888 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10889 hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10890 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10892 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface
, NULL
, 0, NULL
);
10893 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10895 hr
= IDirectDrawSurface_Blt(surface
, NULL
, rt
, NULL
, 0, NULL
);
10896 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10898 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
10900 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
10901 surface
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
10902 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
10904 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
10905 rt
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
10906 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
10909 IDirectDrawSurface4_Release(surface
);
10910 IDirectDrawSurface4_Release(rt
);
10911 IDirectDraw4_Release(ddraw
);
10912 refcount
= IDirect3DDevice3_Release(device
);
10913 ok(!refcount
, "Device has %u references left.\n", refcount
);
10914 DestroyWindow(window
);
10917 static void test_color_clamping(void)
10919 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10920 static D3DMATRIX mat
=
10922 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10923 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10924 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10925 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10927 static struct vec3 quad
[] =
10929 {-1.0f
, -1.0f
, 0.1f
},
10930 {-1.0f
, 1.0f
, 0.1f
},
10931 { 1.0f
, -1.0f
, 0.1f
},
10932 { 1.0f
, 1.0f
, 0.1f
},
10934 IDirect3DViewport3
*viewport
;
10935 IDirect3DDevice3
*device
;
10936 IDirectDrawSurface4
*rt
;
10942 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10943 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
10945 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10947 skip("Failed to create a 3D device, skipping test.\n");
10948 DestroyWindow(window
);
10952 hr
= IDirect3DDevice3_GetRenderTarget(device
, &rt
);
10953 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10955 viewport
= create_viewport(device
, 0, 0, 640, 480);
10956 hr
= IDirect3DDevice3_SetCurrentViewport(device
, viewport
);
10957 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10959 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
10960 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
10961 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
10962 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
10963 hr
= IDirect3DDevice3_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
10964 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
10965 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
10966 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
10967 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
10968 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
10969 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10970 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10971 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
10972 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
10973 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
10974 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
10975 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10976 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
10978 hr
= IDirect3DDevice3_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0xff404040);
10979 ok(SUCCEEDED(hr
), "Failed to set texture factor, hr %#x.\n", hr
);
10980 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_ADD
);
10981 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
10982 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_DIFFUSE
);
10983 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10984 hr
= IDirect3DDevice3_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_SPECULAR
);
10985 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10986 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
10987 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
10988 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
10989 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10990 hr
= IDirect3DDevice3_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
10991 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10993 hr
= IDirect3DViewport3_Clear2(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
10994 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
10996 hr
= IDirect3DDevice3_BeginScene(device
);
10997 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10999 hr
= IDirect3DDevice3_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, 0);
11000 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11002 hr
= IDirect3DDevice3_EndScene(device
);
11003 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11005 color
= get_surface_color(rt
, 320, 240);
11006 ok(compare_color(color
, 0x00404040, 1), "Got unexpected color 0x%08x.\n", color
);
11008 destroy_viewport(device
, viewport
);
11009 IDirectDrawSurface4_Release(rt
);
11010 refcount
= IDirect3DDevice3_Release(device
);
11011 ok(!refcount
, "Device has %u references left.\n", refcount
);
11012 DestroyWindow(window
);
11015 static void test_getdc(void)
11017 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
11018 IDirectDrawSurface4
*surface
, *surface2
, *tmp
;
11019 DDSURFACEDESC2 surface_desc
, map_desc
;
11020 IDirectDraw4
*ddraw
;
11026 static const struct
11029 DDPIXELFORMAT format
;
11030 BOOL getdc_supported
;
11031 HRESULT alt_result
;
11035 {"D3DFMT_A8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
11036 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE
},
11037 {"D3DFMT_X8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
11038 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE
},
11039 {"D3DFMT_R5G6B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
11040 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE
},
11041 {"D3DFMT_X1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
11042 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE
},
11043 {"D3DFMT_A1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
11044 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE
},
11045 {"D3DFMT_A4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
11046 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11047 {"D3DFMT_X4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
11048 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11049 {"D3DFMT_A2R10G10B10", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
11050 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE
},
11051 {"D3DFMT_A8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
11052 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11053 {"D3DFMT_X8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
11054 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
11055 {"D3DFMT_R3G3B2", {sizeof(test_data
->format
), DDPF_RGB
, 0, {8},
11056 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE
},
11057 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
11058 * This is not implemented in wine yet, so disable the test for now.
11059 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
11060 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
11061 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
11063 {"D3DFMT_L8", {sizeof(test_data
->format
), DDPF_LUMINANCE
, 0, {8},
11064 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11065 {"D3DFMT_A8L8", {sizeof(test_data
->format
), DDPF_ALPHAPIXELS
| DDPF_LUMINANCE
, 0, {16},
11066 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE
},
11067 {"D3DFMT_DXT1", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','1'), {0},
11068 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11069 {"D3DFMT_DXT2", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','2'), {0},
11070 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11071 {"D3DFMT_DXT3", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','3'), {0},
11072 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11073 {"D3DFMT_DXT4", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','4'), {0},
11074 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11075 {"D3DFMT_DXT5", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','5'), {0},
11076 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
11079 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11080 0, 0, 640, 480, 0, 0, 0, 0);
11081 ddraw
= create_ddraw();
11082 ok(!!ddraw
, "Failed to create a ddraw object.\n");
11083 hr
= IDirectDraw4_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
11084 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11086 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
11088 memset(&surface_desc
, 0, sizeof(surface_desc
));
11089 surface_desc
.dwSize
= sizeof(surface_desc
);
11090 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
11091 surface_desc
.dwWidth
= 64;
11092 surface_desc
.dwHeight
= 64;
11093 U4(surface_desc
).ddpfPixelFormat
= test_data
[i
].format
;
11094 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11096 if (FAILED(IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11098 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
11099 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
11100 if (FAILED(hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11102 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data
[i
].name
, hr
);
11107 dc
= (void *)0x1234;
11108 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11109 if (test_data
[i
].getdc_supported
)
11110 ok(SUCCEEDED(hr
) || (test_data
[i
].alt_result
&& hr
== test_data
[i
].alt_result
),
11111 "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11113 ok(FAILED(hr
), "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11117 unsigned int width_bytes
;
11123 type
= GetObjectType(dc
);
11124 ok(type
== OBJ_MEMDC
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
11125 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
11126 type
= GetObjectType(bitmap
);
11127 ok(type
== OBJ_BITMAP
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
11129 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
11130 ok(size
== sizeof(dib
), "Got unexpected size %d for format %s.\n", size
, test_data
[i
].name
);
11131 ok(!dib
.dsBm
.bmType
, "Got unexpected type %#x for format %s.\n",
11132 dib
.dsBm
.bmType
, test_data
[i
].name
);
11133 ok(dib
.dsBm
.bmWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
11134 dib
.dsBm
.bmWidth
, test_data
[i
].name
);
11135 ok(dib
.dsBm
.bmHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
11136 dib
.dsBm
.bmHeight
, test_data
[i
].name
);
11137 width_bytes
= ((dib
.dsBm
.bmWidth
* U1(test_data
[i
].format
).dwRGBBitCount
+ 31) >> 3) & ~3;
11138 ok(dib
.dsBm
.bmWidthBytes
== width_bytes
, "Got unexpected width bytes %d for format %s.\n",
11139 dib
.dsBm
.bmWidthBytes
, test_data
[i
].name
);
11140 ok(dib
.dsBm
.bmPlanes
== 1, "Got unexpected plane count %d for format %s.\n",
11141 dib
.dsBm
.bmPlanes
, test_data
[i
].name
);
11142 ok(dib
.dsBm
.bmBitsPixel
== U1(test_data
[i
].format
).dwRGBBitCount
,
11143 "Got unexpected bit count %d for format %s.\n",
11144 dib
.dsBm
.bmBitsPixel
, test_data
[i
].name
);
11145 ok(!!dib
.dsBm
.bmBits
, "Got unexpected bits %p for format %s.\n",
11146 dib
.dsBm
.bmBits
, test_data
[i
].name
);
11148 ok(dib
.dsBmih
.biSize
== sizeof(dib
.dsBmih
), "Got unexpected size %u for format %s.\n",
11149 dib
.dsBmih
.biSize
, test_data
[i
].name
);
11150 ok(dib
.dsBmih
.biWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
11151 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
11152 ok(dib
.dsBmih
.biHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
11153 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
11154 ok(dib
.dsBmih
.biPlanes
== 1, "Got unexpected plane count %u for format %s.\n",
11155 dib
.dsBmih
.biPlanes
, test_data
[i
].name
);
11156 ok(dib
.dsBmih
.biBitCount
== U1(test_data
[i
].format
).dwRGBBitCount
,
11157 "Got unexpected bit count %u for format %s.\n",
11158 dib
.dsBmih
.biBitCount
, test_data
[i
].name
);
11159 ok(dib
.dsBmih
.biCompression
== (U1(test_data
[i
].format
).dwRGBBitCount
== 16 ? BI_BITFIELDS
: BI_RGB
)
11160 || broken(U2(test_data
[i
].format
).dwRGBBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_BITFIELDS
),
11161 "Got unexpected compression %#x for format %s.\n",
11162 dib
.dsBmih
.biCompression
, test_data
[i
].name
);
11163 ok(!dib
.dsBmih
.biSizeImage
, "Got unexpected image size %u for format %s.\n",
11164 dib
.dsBmih
.biSizeImage
, test_data
[i
].name
);
11165 ok(!dib
.dsBmih
.biXPelsPerMeter
, "Got unexpected horizontal resolution %d for format %s.\n",
11166 dib
.dsBmih
.biXPelsPerMeter
, test_data
[i
].name
);
11167 ok(!dib
.dsBmih
.biYPelsPerMeter
, "Got unexpected vertical resolution %d for format %s.\n",
11168 dib
.dsBmih
.biYPelsPerMeter
, test_data
[i
].name
);
11169 ok(!dib
.dsBmih
.biClrUsed
, "Got unexpected used colour count %u for format %s.\n",
11170 dib
.dsBmih
.biClrUsed
, test_data
[i
].name
);
11171 ok(!dib
.dsBmih
.biClrImportant
, "Got unexpected important colour count %u for format %s.\n",
11172 dib
.dsBmih
.biClrImportant
, test_data
[i
].name
);
11174 if (dib
.dsBmih
.biCompression
== BI_BITFIELDS
)
11176 ok((dib
.dsBitfields
[0] == U2(test_data
[i
].format
).dwRBitMask
11177 && dib
.dsBitfields
[1] == U3(test_data
[i
].format
).dwGBitMask
11178 && dib
.dsBitfields
[2] == U4(test_data
[i
].format
).dwBBitMask
)
11179 || broken(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2]),
11180 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11181 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
11185 ok(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2],
11186 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
11187 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
11189 ok(!dib
.dshSection
, "Got unexpected section %p for format %s.\n", dib
.dshSection
, test_data
[i
].name
);
11190 ok(!dib
.dsOffset
, "Got unexpected offset %u for format %s.\n", dib
.dsOffset
, test_data
[i
].name
);
11192 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11193 ok(hr
== DD_OK
, "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11197 ok(!dc
, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
11200 IDirectDrawSurface4_Release(surface
);
11205 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
11206 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
11207 if (FAILED(hr
= IDirectDraw4_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11209 skip("Failed to create mip-mapped texture for format %s (hr %#x), skipping tests.\n",
11210 test_data
[i
].name
, hr
);
11214 hr
= IDirectDrawSurface4_GetAttachedSurface(surface
, &caps
, &tmp
);
11215 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11216 hr
= IDirectDrawSurface4_GetAttachedSurface(tmp
, &caps
, &surface2
);
11217 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11218 IDirectDrawSurface4_Release(tmp
);
11220 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11221 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11222 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11223 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11224 hr
= IDirectDrawSurface4_GetDC(surface2
, &dc
);
11225 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11226 hr
= IDirectDrawSurface4_ReleaseDC(surface2
, dc
);
11227 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11229 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11230 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11231 dc2
= (void *)0x1234;
11232 hr
= IDirectDrawSurface4_GetDC(surface
, &dc2
);
11233 ok(hr
== DDERR_DCALREADYCREATED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11234 ok(dc2
== (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
11235 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11236 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11237 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11238 ok(hr
== DDERR_NODC
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11240 map_desc
.dwSize
= sizeof(map_desc
);
11241 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11242 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11243 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11244 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11245 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11246 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11247 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11248 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11250 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11251 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11252 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11253 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11254 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11255 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11257 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11258 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11259 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11260 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11261 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11262 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11263 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11264 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11266 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11267 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11268 hr
= IDirectDrawSurface4_GetDC(surface2
, &dc2
);
11269 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11270 hr
= IDirectDrawSurface4_ReleaseDC(surface2
, dc2
);
11271 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11272 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11273 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11275 hr
= IDirectDrawSurface4_GetDC(surface2
, &dc
);
11276 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11277 hr
= IDirectDrawSurface4_GetDC(surface
, &dc2
);
11278 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11279 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc2
);
11280 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11281 hr
= IDirectDrawSurface4_ReleaseDC(surface2
, dc
);
11282 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11284 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11285 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11286 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11287 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11288 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11289 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11290 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11291 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11293 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11294 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11295 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11296 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11297 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11298 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11299 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11300 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11302 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11303 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11304 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11305 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11306 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11307 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11308 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11309 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11311 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11312 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11313 hr
= IDirectDrawSurface4_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11314 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11315 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11316 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11317 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11318 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11320 hr
= IDirectDrawSurface4_GetDC(surface2
, &dc
);
11321 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11322 hr
= IDirectDrawSurface4_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
11323 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11324 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11325 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11326 hr
= IDirectDrawSurface4_ReleaseDC(surface2
, dc
);
11327 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11329 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11330 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11331 hr
= IDirectDrawSurface4_GetDC(surface2
, &dc
);
11332 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11333 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11334 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11335 hr
= IDirectDrawSurface4_ReleaseDC(surface2
, dc
);
11336 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11337 hr
= IDirectDrawSurface4_Unlock(surface
, NULL
);
11338 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11340 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11341 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11342 hr
= IDirectDrawSurface4_GetDC(surface
, &dc
);
11343 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11344 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11345 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11346 hr
= IDirectDrawSurface4_ReleaseDC(surface
, dc
);
11347 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
11348 hr
= IDirectDrawSurface4_Unlock(surface2
, NULL
);
11349 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
11351 IDirectDrawSurface4_Release(surface2
);
11352 IDirectDrawSurface4_Release(surface
);
11355 IDirectDraw4_Release(ddraw
);
11356 DestroyWindow(window
);
11361 IDirectDraw4
*ddraw
;
11362 DEVMODEW current_mode
;
11364 if (!(ddraw
= create_ddraw()))
11366 skip("Failed to create a ddraw object, skipping tests.\n");
11369 IDirectDraw4_Release(ddraw
);
11371 memset(¤t_mode
, 0, sizeof(current_mode
));
11372 current_mode
.dmSize
= sizeof(current_mode
);
11373 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
11374 registry_mode
.dmSize
= sizeof(registry_mode
);
11375 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
11376 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
11377 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
11379 skip("Current mode does not match registry mode, skipping test.\n");
11383 test_process_vertices();
11384 test_coop_level_create_device_window();
11385 test_clipper_blt();
11386 test_coop_level_d3d_state();
11387 test_surface_interface_mismatch();
11388 test_coop_level_threaded();
11390 test_texture_load_ckey();
11399 test_window_style();
11400 test_redundant_mode_set();
11401 test_coop_level_mode_set();
11402 test_coop_level_mode_set_multi();
11404 test_coop_level_surf_create();
11406 test_coop_level_multi_window();
11407 test_draw_strided();
11409 test_specular_lighting();
11410 test_clear_rect_count();
11411 test_coop_level_versions();
11412 test_lighting_interface_versions();
11413 test_coop_level_activateapp();
11414 test_texturemanage();
11415 test_block_formats_creation();
11416 test_unsupported_formats();
11418 test_primary_caps();
11419 test_surface_lock();
11420 test_surface_discard();
11422 test_set_surface_desc();
11423 test_user_memory_getdc();
11424 test_sysmem_overlay();
11425 test_primary_palette();
11426 test_surface_attachment();
11427 test_private_data();
11428 test_pixel_format();
11429 test_create_surface_pitch();
11431 test_palette_complex();
11432 test_p8_rgb_blit();
11434 test_palette_gdi();
11435 test_palette_alpha();
11436 test_vb_writeonly();
11437 test_lost_device();
11438 test_surface_desc_lock();
11439 test_signed_formats();
11441 test_texcoordindex();
11442 test_colorkey_precision();
11443 test_range_colorkey();
11445 test_lockrect_invalid();
11446 test_yv12_overlay();
11447 test_offscreen_overlay();
11448 test_overlay_rect();
11450 test_color_clamping();