2 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
3 * Copyright 2012-2014 Stefan Dösinger for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
26 static DEVMODEW registry_mode
;
28 struct create_window_thread_param
31 HANDLE window_created
;
32 HANDLE destroy_window
;
36 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
38 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
40 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
42 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
44 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
48 static DWORD WINAPI
create_window_thread_proc(void *param
)
50 struct create_window_thread_param
*p
= param
;
54 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
55 0, 0, 640, 480, 0, 0, 0, 0);
56 ret
= SetEvent(p
->window_created
);
57 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
63 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
64 DispatchMessageA(&msg
);
65 res
= WaitForSingleObject(p
->destroy_window
, 100);
66 if (res
== WAIT_OBJECT_0
)
68 if (res
!= WAIT_TIMEOUT
)
70 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
75 DestroyWindow(p
->window
);
80 static void create_window_thread(struct create_window_thread_param
*p
)
84 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
85 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
86 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
87 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
88 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
89 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
90 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
91 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
94 static void destroy_window_thread(struct create_window_thread_param
*p
)
96 SetEvent(p
->destroy_window
);
97 WaitForSingleObject(p
->thread
, INFINITE
);
98 CloseHandle(p
->destroy_window
);
99 CloseHandle(p
->window_created
);
100 CloseHandle(p
->thread
);
103 static IDirectDrawSurface
*get_depth_stencil(IDirect3DDevice2
*device
)
105 IDirectDrawSurface
*rt
, *ret
;
106 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
109 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
110 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
111 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ret
);
112 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
113 IDirectDrawSurface_Release(rt
);
117 static HRESULT
set_display_mode(IDirectDraw2
*ddraw
, DWORD width
, DWORD height
)
119 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
121 return IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
124 static D3DCOLOR
get_surface_color(IDirectDrawSurface
*surface
, UINT x
, UINT y
)
126 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
127 DDSURFACEDESC surface_desc
;
131 memset(&surface_desc
, 0, sizeof(surface_desc
));
132 surface_desc
.dwSize
= sizeof(surface_desc
);
134 hr
= IDirectDrawSurface_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
135 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
139 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
141 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
142 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
147 static DWORD
get_device_z_depth(IDirect3DDevice2
*device
)
149 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
150 IDirectDrawSurface
*ds
, *rt
;
154 if (FAILED(IDirect3DDevice2_GetRenderTarget(device
, &rt
)))
157 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ds
);
158 IDirectDrawSurface_Release(rt
);
162 desc
.dwSize
= sizeof(desc
);
163 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
164 IDirectDrawSurface_Release(ds
);
168 return U2(desc
).dwZBufferBitDepth
;
171 static IDirectDraw2
*create_ddraw(void)
173 IDirectDraw2
*ddraw2
;
177 if (FAILED(DirectDrawCreate(NULL
, &ddraw1
, NULL
)))
180 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw2
, (void **)&ddraw2
);
181 IDirectDraw_Release(ddraw1
);
188 static IDirect3DDevice2
*create_device(IDirectDraw2
*ddraw
, HWND window
, DWORD coop_level
)
190 static const DWORD z_depths
[] = {32, 24, 16};
191 IDirectDrawSurface
*surface
, *ds
;
192 IDirect3DDevice2
*device
= NULL
;
193 DDSURFACEDESC surface_desc
;
198 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, coop_level
);
199 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
201 memset(&surface_desc
, 0, sizeof(surface_desc
));
202 surface_desc
.dwSize
= sizeof(surface_desc
);
203 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
204 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
205 surface_desc
.dwWidth
= 640;
206 surface_desc
.dwHeight
= 480;
208 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
209 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
211 if (coop_level
& DDSCL_NORMAL
)
213 IDirectDrawClipper
*clipper
;
215 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
216 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
217 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
218 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
219 hr
= IDirectDrawSurface_SetClipper(surface
, clipper
);
220 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
221 IDirectDrawClipper_Release(clipper
);
224 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
227 IDirectDrawSurface_Release(surface
);
231 /* We used to use EnumDevices() for this, but it seems
232 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
233 * relationship with reality. */
234 for (i
= 0; i
< sizeof(z_depths
) / sizeof(*z_depths
); ++i
)
236 memset(&surface_desc
, 0, sizeof(surface_desc
));
237 surface_desc
.dwSize
= sizeof(surface_desc
);
238 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
239 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
240 U2(surface_desc
).dwZBufferBitDepth
= z_depths
[i
];
241 surface_desc
.dwWidth
= 640;
242 surface_desc
.dwHeight
= 480;
243 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
)))
246 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
247 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
248 IDirectDrawSurface_Release(ds
);
252 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
)))
255 IDirectDrawSurface_DeleteAttachedSurface(surface
, 0, ds
);
258 IDirect3D2_Release(d3d
);
259 IDirectDrawSurface_Release(surface
);
263 static IDirect3DViewport2
*create_viewport(IDirect3DDevice2
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
265 IDirect3DViewport2
*viewport
;
270 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
271 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
272 hr
= IDirect3D2_CreateViewport(d3d
, &viewport
, NULL
);
273 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
274 hr
= IDirect3DDevice2_AddViewport(device
, viewport
);
275 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
276 memset(&vp
, 0, sizeof(vp
));
277 vp
.dwSize
= sizeof(vp
);
284 vp
.dvClipWidth
= 2.0f
;
285 vp
.dvClipHeight
= 2.0f
;
288 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp
);
289 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
290 IDirect3D2_Release(d3d
);
295 static void viewport_set_background(IDirect3DDevice2
*device
, IDirect3DViewport2
*viewport
,
296 IDirect3DMaterial2
*material
)
298 D3DMATERIALHANDLE material_handle
;
301 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &material_handle
);
302 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
303 hr
= IDirect3DViewport2_SetBackground(viewport
, material_handle
);
304 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
307 static void destroy_viewport(IDirect3DDevice2
*device
, IDirect3DViewport2
*viewport
)
311 hr
= IDirect3DDevice2_DeleteViewport(device
, viewport
);
312 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
313 IDirect3DViewport2_Release(viewport
);
316 static IDirect3DMaterial2
*create_material(IDirect3DDevice2
*device
, D3DMATERIAL
*mat
)
318 IDirect3DMaterial2
*material
;
322 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
323 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
324 hr
= IDirect3D2_CreateMaterial(d3d
, &material
, NULL
);
325 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
326 hr
= IDirect3DMaterial2_SetMaterial(material
, mat
);
327 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
328 IDirect3D2_Release(d3d
);
333 static IDirect3DMaterial2
*create_diffuse_material(IDirect3DDevice2
*device
, float r
, float g
, float b
, float a
)
337 memset(&mat
, 0, sizeof(mat
));
338 mat
.dwSize
= sizeof(mat
);
339 U1(U(mat
).diffuse
).r
= r
;
340 U2(U(mat
).diffuse
).g
= g
;
341 U3(U(mat
).diffuse
).b
= b
;
342 U4(U(mat
).diffuse
).a
= a
;
344 return create_material(device
, &mat
);
347 static IDirect3DMaterial2
*create_specular_material(IDirect3DDevice2
*device
,
348 float r
, float g
, float b
, float a
, float power
)
352 memset(&mat
, 0, sizeof(mat
));
353 mat
.dwSize
= sizeof(mat
);
354 U1(U2(mat
).specular
).r
= r
;
355 U2(U2(mat
).specular
).g
= g
;
356 U3(U2(mat
).specular
).b
= b
;
357 U4(U2(mat
).specular
).a
= a
;
358 U4(mat
).power
= power
;
360 return create_material(device
, &mat
);
363 static IDirect3DMaterial2
*create_emissive_material(IDirect3DDevice2
*device
, float r
, float g
, float b
, float a
)
367 memset(&mat
, 0, sizeof(mat
));
368 mat
.dwSize
= sizeof(mat
);
369 U1(U3(mat
).emissive
).r
= r
;
370 U2(U3(mat
).emissive
).g
= g
;
371 U3(U3(mat
).emissive
).b
= b
;
372 U4(U3(mat
).emissive
).a
= a
;
374 return create_material(device
, &mat
);
377 static void destroy_material(IDirect3DMaterial2
*material
)
379 IDirect3DMaterial2_Release(material
);
386 WPARAM expect_wparam
;
389 static const struct message
*expect_messages
;
391 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
393 if (expect_messages
&& message
== expect_messages
->message
)
395 if (expect_messages
->check_wparam
)
396 ok (wparam
== expect_messages
->expect_wparam
,
397 "Got unexpected wparam %lx for message %x, expected %lx.\n",
398 wparam
, message
, expect_messages
->expect_wparam
);
403 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
406 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
407 * interface. This prevents subsequent SetCooperativeLevel() calls on a
408 * different window from failing with DDERR_HWNDALREADYSET. */
409 static void fix_wndproc(HWND window
, LONG_PTR proc
)
414 if (!(ddraw
= create_ddraw()))
417 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
418 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
419 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
420 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
421 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
423 IDirectDraw2_Release(ddraw
);
426 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
428 HRESULT hr
= IDirectDrawSurface_Restore(surface
);
429 ok(SUCCEEDED(hr
) || hr
== DDERR_IMPLICITLYCREATED
, "Failed to restore surface, hr %#x.\n", hr
);
430 IDirectDrawSurface_Release(surface
);
435 static HRESULT
restore_surfaces(IDirectDraw2
*ddraw
)
437 return IDirectDraw2_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
438 NULL
, NULL
, restore_callback
);
441 static void test_coop_level_create_device_window(void)
443 HWND focus_window
, device_window
;
447 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
448 0, 0, 640, 480, 0, 0, 0, 0);
449 ddraw
= create_ddraw();
450 ok(!!ddraw
, "Failed to create a ddraw object.\n");
452 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
453 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
454 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
455 ok(!device_window
, "Unexpected device window found.\n");
456 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
457 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
458 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
459 ok(!device_window
, "Unexpected device window found.\n");
460 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
461 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
462 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
463 ok(!device_window
, "Unexpected device window found.\n");
464 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
465 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
466 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
467 ok(!device_window
, "Unexpected device window found.\n");
468 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
469 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
470 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
471 ok(!device_window
, "Unexpected device window found.\n");
473 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
474 if (broken(hr
== DDERR_INVALIDPARAMS
))
476 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
477 IDirectDraw2_Release(ddraw
);
478 DestroyWindow(focus_window
);
482 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
483 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
484 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
485 ok(!device_window
, "Unexpected device window found.\n");
486 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
487 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
488 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
489 ok(!device_window
, "Unexpected device window found.\n");
491 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
492 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
493 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
494 ok(!device_window
, "Unexpected device window found.\n");
495 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
496 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
497 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
498 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
499 ok(!!device_window
, "Device window not found.\n");
501 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
502 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
503 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
504 ok(!device_window
, "Unexpected device window found.\n");
505 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
506 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
507 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
508 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
509 ok(!!device_window
, "Device window not found.\n");
511 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
512 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
513 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
514 ok(!device_window
, "Unexpected device window found.\n");
515 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
516 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
517 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
518 ok(!device_window
, "Unexpected device window found.\n");
519 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
520 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
521 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
522 ok(!device_window
, "Unexpected device window found.\n");
523 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
524 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
525 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
526 ok(!!device_window
, "Device window not found.\n");
528 IDirectDraw2_Release(ddraw
);
529 DestroyWindow(focus_window
);
532 static void test_clipper_blt(void)
534 IDirectDrawSurface
*src_surface
, *dst_surface
;
535 RECT client_rect
, src_rect
;
536 IDirectDrawClipper
*clipper
;
537 DDSURFACEDESC surface_desc
;
538 unsigned int i
, j
, x
, y
;
550 static const DWORD src_data
[] =
552 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
553 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
554 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
556 static const D3DCOLOR expected1
[] =
558 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
559 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
560 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
561 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
563 /* Nvidia on Windows seems to have an off-by-one error
564 * when processing source rectangles. Our left = 1 and
565 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
566 * read as well, but only for the edge pixels on the
567 * output image. The bug happens on the y axis as well,
568 * but we only read one row there, and all source rows
569 * contain the same data. This bug is not dependent on
570 * the presence of a clipper. */
571 static const D3DCOLOR expected1_broken
[] =
573 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
574 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
575 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
576 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
578 static const D3DCOLOR expected2
[] =
580 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
581 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
582 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
583 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
586 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
587 10, 10, 640, 480, 0, 0, 0, 0);
588 ShowWindow(window
, SW_SHOW
);
589 ddraw
= create_ddraw();
590 ok(!!ddraw
, "Failed to create a ddraw object.\n");
592 ret
= GetClientRect(window
, &client_rect
);
593 ok(ret
, "Failed to get client rect.\n");
594 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
595 ok(ret
, "Failed to map client rect.\n");
597 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
598 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
600 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
601 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
602 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
603 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
604 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
605 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
606 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
607 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
608 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
609 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
610 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
611 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
612 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
613 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
614 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
615 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
616 rgn_data
->rdh
.rcBound
.left
, rgn_data
->rdh
.rcBound
.top
,
617 rgn_data
->rdh
.rcBound
.right
, rgn_data
->rdh
.rcBound
.bottom
,
618 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
619 HeapFree(GetProcessHeap(), 0, rgn_data
);
621 r1
= CreateRectRgn(0, 0, 320, 240);
622 ok(!!r1
, "Failed to create region.\n");
623 r2
= CreateRectRgn(320, 240, 640, 480);
624 ok(!!r2
, "Failed to create region.\n");
625 CombineRgn(r1
, r1
, r2
, RGN_OR
);
626 ret
= GetRegionData(r1
, 0, NULL
);
627 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
628 ret
= GetRegionData(r1
, ret
, rgn_data
);
629 ok(!!ret
, "Failed to get region data.\n");
634 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
635 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
636 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
637 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
638 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
639 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
641 HeapFree(GetProcessHeap(), 0, rgn_data
);
643 memset(&surface_desc
, 0, sizeof(surface_desc
));
644 surface_desc
.dwSize
= sizeof(surface_desc
);
645 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
646 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
647 surface_desc
.dwWidth
= 640;
648 surface_desc
.dwHeight
= 480;
649 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
650 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
651 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
652 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
653 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
654 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
656 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
657 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
658 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
659 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
661 memset(&fx
, 0, sizeof(fx
));
662 fx
.dwSize
= sizeof(fx
);
663 hr
= IDirectDrawSurface_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
664 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
665 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
666 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
668 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
669 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
670 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
671 ptr
= surface_desc
.lpSurface
;
672 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
673 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
674 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
675 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
676 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
678 hr
= IDirectDrawSurface_SetClipper(dst_surface
, clipper
);
679 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
681 SetRect(&src_rect
, 1, 1, 5, 2);
682 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
683 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
684 for (i
= 0; i
< 4; ++i
)
686 for (j
= 0; j
< 4; ++j
)
688 x
= 80 * ((2 * j
) + 1);
689 y
= 60 * ((2 * i
) + 1);
690 color
= get_surface_color(dst_surface
, x
, y
);
691 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
692 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
693 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
697 U5(fx
).dwFillColor
= 0xff0000ff;
698 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
699 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
700 for (i
= 0; i
< 4; ++i
)
702 for (j
= 0; j
< 4; ++j
)
704 x
= 80 * ((2 * j
) + 1);
705 y
= 60 * ((2 * i
) + 1);
706 color
= get_surface_color(dst_surface
, x
, y
);
707 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
708 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
712 hr
= IDirectDrawSurface_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
713 ok(hr
== DDERR_BLTFASTCANTCLIP
|| broken(hr
== E_NOTIMPL
/* NT4 */), "Got unexpected hr %#x.\n", hr
);
715 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
716 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
717 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
718 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
719 DestroyWindow(window
);
720 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
721 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
722 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
723 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
724 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
725 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
726 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
727 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
728 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
729 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
730 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
731 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
733 IDirectDrawSurface_Release(dst_surface
);
734 IDirectDrawSurface_Release(src_surface
);
735 refcount
= IDirectDrawClipper_Release(clipper
);
736 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
737 IDirectDraw2_Release(ddraw
);
740 static void test_coop_level_d3d_state(void)
742 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
743 IDirectDrawSurface
*rt
, *surface
;
744 IDirect3DMaterial2
*background
;
745 IDirect3DViewport2
*viewport
;
746 IDirect3DDevice2
*device
;
747 D3DMATERIAL material
;
754 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
755 0, 0, 640, 480, 0, 0, 0, 0);
756 ddraw
= create_ddraw();
757 ok(!!ddraw
, "Failed to create a ddraw object.\n");
758 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
760 skip("Failed to create a 3D device, skipping test.\n");
761 IDirectDraw2_Release(ddraw
);
762 DestroyWindow(window
);
766 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
767 viewport
= create_viewport(device
, 0, 0, 640, 480);
768 viewport_set_background(device
, viewport
, background
);
770 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
771 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
772 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
773 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
774 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
775 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
776 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
777 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
778 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
779 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
780 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
781 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
782 color
= get_surface_color(rt
, 320, 240);
783 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
785 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
786 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
787 hr
= IDirectDrawSurface_IsLost(rt
);
788 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
789 hr
= restore_surfaces(ddraw
);
790 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
792 memset(&material
, 0, sizeof(material
));
793 material
.dwSize
= sizeof(material
);
794 U1(U(material
).diffuse
).r
= 0.0f
;
795 U2(U(material
).diffuse
).g
= 1.0f
;
796 U3(U(material
).diffuse
).b
= 0.0f
;
797 U4(U(material
).diffuse
).a
= 1.0f
;
798 hr
= IDirect3DMaterial2_SetMaterial(background
, &material
);
799 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
801 hr
= IDirect3DDevice2_GetRenderTarget(device
, &surface
);
802 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
803 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
804 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
805 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
806 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
807 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
808 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
809 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
810 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
811 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
812 color
= get_surface_color(rt
, 320, 240);
813 ok(compare_color(color
, 0x0000ff00, 1) || broken(compare_color(color
, 0x00000000, 1)),
814 "Got unexpected color 0x%08x.\n", color
);
816 destroy_viewport(device
, viewport
);
817 destroy_material(background
);
818 IDirectDrawSurface_Release(surface
);
819 IDirectDrawSurface_Release(rt
);
820 IDirect3DDevice2_Release(device
);
821 IDirectDraw2_Release(ddraw
);
822 DestroyWindow(window
);
825 static void test_surface_interface_mismatch(void)
827 IDirectDraw2
*ddraw
= NULL
;
828 IDirect3D2
*d3d
= NULL
;
829 IDirectDrawSurface
*surface
= NULL
, *ds
;
830 IDirectDrawSurface3
*surface3
= NULL
;
831 IDirect3DDevice2
*device
= NULL
;
832 IDirect3DViewport2
*viewport
= NULL
;
833 IDirect3DMaterial2
*background
= NULL
;
834 DDSURFACEDESC surface_desc
;
840 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
842 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
843 0, 0, 640, 480, 0, 0, 0, 0);
844 ddraw
= create_ddraw();
845 ok(!!ddraw
, "Failed to create a ddraw object.\n");
846 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
848 skip("Failed to create a 3D device, skipping test.\n");
849 IDirectDraw2_Release(ddraw
);
850 DestroyWindow(window
);
853 z_depth
= get_device_z_depth(device
);
854 ok(!!z_depth
, "Failed to get device z depth.\n");
855 IDirect3DDevice2_Release(device
);
858 memset(&surface_desc
, 0, sizeof(surface_desc
));
859 surface_desc
.dwSize
= sizeof(surface_desc
);
860 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
861 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
862 surface_desc
.dwWidth
= 640;
863 surface_desc
.dwHeight
= 480;
865 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
866 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
868 hr
= IDirectDrawSurface2_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
871 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
875 if (FAILED(IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
)))
877 skip("D3D interface is not available, skipping test.\n");
881 memset(&surface_desc
, 0, sizeof(surface_desc
));
882 surface_desc
.dwSize
= sizeof(surface_desc
);
883 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
884 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
885 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
886 surface_desc
.dwWidth
= 640;
887 surface_desc
.dwHeight
= 480;
888 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
889 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
893 /* Using a different surface interface version still works */
894 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
895 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
896 refcount
= IDirectDrawSurface_Release(ds
);
897 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
902 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface
*)surface3
, &device
);
903 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
907 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
908 viewport
= create_viewport(device
, 0, 0, 640, 480);
909 viewport_set_background(device
, viewport
, background
);
911 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
912 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
913 color
= get_surface_color(surface
, 320, 240);
914 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
918 destroy_viewport(device
, viewport
);
920 destroy_material(background
);
921 if (surface3
) IDirectDrawSurface3_Release(surface3
);
922 if (surface
) IDirectDrawSurface_Release(surface
);
923 if (device
) IDirect3DDevice2_Release(device
);
924 if (d3d
) IDirect3D2_Release(d3d
);
925 if (ddraw
) IDirectDraw2_Release(ddraw
);
926 DestroyWindow(window
);
929 static void test_coop_level_threaded(void)
931 struct create_window_thread_param p
;
935 ddraw
= create_ddraw();
936 ok(!!ddraw
, "Failed to create a ddraw object.\n");
937 create_window_thread(&p
);
939 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
940 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
942 IDirectDraw2_Release(ddraw
);
943 destroy_window_thread(&p
);
946 static void test_depth_blit(void)
948 static D3DLVERTEX quad1
[] =
950 {{-1.0}, { 1.0}, {0.50f
}, 0, {0xff00ff00}},
951 {{ 1.0}, { 1.0}, {0.50f
}, 0, {0xff00ff00}},
952 {{-1.0}, {-1.0}, {0.50f
}, 0, {0xff00ff00}},
953 {{ 1.0}, {-1.0}, {0.50f
}, 0, {0xff00ff00}},
955 static const D3DCOLOR expected_colors
[4][4] =
957 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
958 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
959 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
960 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
962 DDSURFACEDESC ddsd_new
, ddsd_existing
;
964 IDirect3DDevice2
*device
;
965 IDirectDrawSurface
*ds1
, *ds2
, *ds3
, *rt
;
966 IDirect3DViewport2
*viewport
;
967 RECT src_rect
, dst_rect
;
975 IDirect3DMaterial2
*background
;
977 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
978 0, 0, 640, 480, 0, 0, 0, 0);
979 ddraw
= create_ddraw();
980 ok(!!ddraw
, "Failed to create a ddraw object.\n");
981 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
983 skip("Failed to create a 3D device, skipping test.\n");
984 IDirectDraw2_Release(ddraw
);
985 DestroyWindow(window
);
989 ds1
= get_depth_stencil(device
);
991 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
992 ddsd_new
.dwSize
= sizeof(ddsd_new
);
993 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
994 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
995 hr
= IDirectDrawSurface_GetSurfaceDesc(ds1
, &ddsd_existing
);
996 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
997 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
998 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
999 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1000 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1001 ddsd_new
.ddpfPixelFormat
= ddsd_existing
.ddpfPixelFormat
;
1002 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1003 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1004 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1005 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1007 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1008 viewport
= create_viewport(device
, 0, 0, ddsd_existing
.dwWidth
, ddsd_existing
.dwHeight
);
1009 viewport_set_background(device
, viewport
, background
);
1010 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1011 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
1013 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1014 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1015 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1016 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1018 U1(d3drect
).x1
= U2(d3drect
).y1
= 0;
1019 U3(d3drect
).x2
= ddsd_existing
.dwWidth
; U4(d3drect
).y2
= ddsd_existing
.dwHeight
;
1020 hr
= IDirect3DViewport2_Clear(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
);
1021 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1024 SetRect(&src_rect
, 0, 0, 320, 240);
1025 SetRect(&dst_rect
, 0, 0, 320, 240);
1026 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1027 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1028 /* Different locations. */
1029 SetRect(&src_rect
, 0, 0, 320, 240);
1030 SetRect(&dst_rect
, 320, 240, 640, 480);
1031 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1032 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1034 SetRect(&src_rect
, 0, 0, 320, 240);
1035 SetRect(&dst_rect
, 0, 0, 640, 480);
1036 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1037 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1039 SetRect(&src_rect
, 0, 480, 640, 0);
1040 SetRect(&dst_rect
, 0, 0, 640, 480);
1041 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1042 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1043 SetRect(&src_rect
, 0, 0, 640, 480);
1044 SetRect(&dst_rect
, 0, 480, 640, 0);
1045 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1046 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1047 /* Full, explicit. */
1048 SetRect(&src_rect
, 0, 0, 640, 480);
1049 SetRect(&dst_rect
, 0, 0, 640, 480);
1050 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1051 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1052 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1054 /* Depth blit inside a BeginScene / EndScene pair */
1055 hr
= IDirect3DDevice2_BeginScene(device
);
1056 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1057 /* From the current depth stencil */
1058 hr
= IDirectDrawSurface_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1059 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1060 /* To the current depth stencil */
1061 hr
= IDirectDrawSurface_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1062 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1063 /* Between unbound surfaces */
1064 hr
= IDirectDrawSurface_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1065 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1066 hr
= IDirect3DDevice2_EndScene(device
);
1067 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1069 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1070 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1071 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1072 * a reliable result(z = 0.0) */
1073 memset(&fx
, 0, sizeof(fx
));
1074 fx
.dwSize
= sizeof(fx
);
1075 U5(fx
).dwFillDepth
= 0;
1076 hr
= IDirectDrawSurface_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1077 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1079 /* This clears the Z buffer with 1.0 */
1080 hr
= IDirect3DViewport2_Clear(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
);
1081 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1083 SetRect(&dst_rect
, 0, 0, 320, 240);
1084 hr
= IDirectDrawSurface_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1085 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1086 IDirectDrawSurface_Release(ds3
);
1087 IDirectDrawSurface_Release(ds2
);
1088 IDirectDrawSurface_Release(ds1
);
1090 hr
= IDirect3DDevice2_BeginScene(device
);
1091 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1092 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad1
, 4, 0);
1093 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1094 hr
= IDirect3DDevice2_EndScene(device
);
1095 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1097 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1098 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1099 for (i
= 0; i
< 4; ++i
)
1101 for (j
= 0; j
< 4; ++j
)
1103 unsigned int x
= 80 * ((2 * j
) + 1);
1104 unsigned int y
= 60 * ((2 * i
) + 1);
1105 color
= get_surface_color(rt
, x
, y
);
1106 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1107 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1110 IDirectDrawSurface_Release(rt
);
1112 destroy_viewport(device
, viewport
);
1113 destroy_material(background
);
1114 IDirect3DDevice2_Release(device
);
1115 IDirectDraw2_Release(ddraw
);
1116 DestroyWindow(window
);
1119 static void test_texture_load_ckey(void)
1121 IDirectDraw2
*ddraw
= NULL
;
1122 IDirectDrawSurface
*src
= NULL
;
1123 IDirectDrawSurface
*dst
= NULL
;
1124 IDirect3DTexture
*src_tex
= NULL
;
1125 IDirect3DTexture
*dst_tex
= NULL
;
1130 ddraw
= create_ddraw();
1131 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1132 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
1133 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1135 memset(&ddsd
, 0, sizeof(ddsd
));
1136 ddsd
.dwSize
= sizeof(ddsd
);
1137 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1138 ddsd
.dwHeight
= 128;
1140 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1141 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1142 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1143 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1144 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1145 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1147 hr
= IDirectDrawSurface_QueryInterface(src
, &IID_IDirect3DTexture
, (void **)&src_tex
);
1148 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get Direct3DTexture interface, hr %#x.\n", hr
);
1151 /* 64 bit ddraw does not support d3d */
1152 skip("Could not get Direct3DTexture interface, skipping texture::Load color keying tests.\n");
1155 hr
= IDirectDrawSurface_QueryInterface(dst
, &IID_IDirect3DTexture
, (void **)&dst_tex
);
1156 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture interface, hr %#x.\n", hr
);
1158 /* No surface has a color key */
1159 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1160 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDCAPS
), "Got unexpected hr %#x.\n", hr
);
1163 /* Testbot Windows NT VMs */
1164 skip("IDirect3DTexture::Load does not work, skipping color keying tests.\n");
1168 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1169 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1170 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1171 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1172 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1174 /* Source surface has a color key */
1175 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1176 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1177 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1178 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1179 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1180 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1181 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1182 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1183 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1185 /* Both surfaces have a color key: Dest ckey is overwritten */
1186 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1187 hr
= IDirectDrawSurface_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1188 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1189 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1190 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1191 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1192 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1193 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1194 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1196 /* Only the destination has a color key: It is not deleted */
1197 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1198 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1199 hr
= IDirectDrawSurface_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1200 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1201 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1202 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1203 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1204 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1205 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1206 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1209 if (dst_tex
) IDirect3DTexture_Release(dst_tex
);
1210 if (src_tex
) IDirect3DTexture_Release(src_tex
);
1211 if (dst
) IDirectDrawSurface_Release(dst
);
1212 if (src
) IDirectDrawSurface_Release(src
);
1213 if (ddraw
) IDirectDraw2_Release(ddraw
);
1216 static ULONG
get_refcount(IUnknown
*test_iface
)
1218 IUnknown_AddRef(test_iface
);
1219 return IUnknown_Release(test_iface
);
1222 static void test_viewport(void)
1224 IDirectDraw2
*ddraw
;
1227 ULONG ref
, old_d3d_ref
;
1228 IDirect3DViewport
*viewport
;
1229 IDirect3DViewport2
*viewport2
, *another_vp
, *test_vp
;
1230 IDirect3DViewport3
*viewport3
;
1231 IDirectDrawGammaControl
*gamma
;
1233 IDirect3DDevice2
*device
;
1236 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1237 0, 0, 640, 480, 0, 0, 0, 0);
1238 ddraw
= create_ddraw();
1239 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1240 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1242 skip("Failed to create a 3D device, skipping test.\n");
1243 IDirectDraw_Release(ddraw
);
1244 DestroyWindow(window
);
1248 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
1249 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get d3d interface, hr %#x.\n", hr
);
1252 skip("D3D interface is not available, skipping test.\n");
1253 IDirectDraw2_Release(ddraw
);
1256 old_d3d_ref
= get_refcount((IUnknown
*)d3d
);
1258 hr
= IDirect3D2_CreateViewport(d3d
, &viewport2
, NULL
);
1259 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1260 ref
= get_refcount((IUnknown
*)viewport2
);
1261 ok(ref
== 1, "Initial IDirect3DViewport2 refcount is %u\n", ref
);
1262 ref
= get_refcount((IUnknown
*)d3d
);
1263 ok(ref
== old_d3d_ref
, "IDirect3D2 refcount is %u\n", ref
);
1265 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1266 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1267 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
1268 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1269 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1270 /* NULL iid: Segfaults */
1272 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirect3DViewport
, (void **)&viewport
);
1273 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport, hr %#x.\n", hr
);
1276 ref
= get_refcount((IUnknown
*)viewport
);
1277 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1278 ref
= get_refcount((IUnknown
*)viewport2
);
1279 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1280 IDirect3DViewport_Release(viewport
);
1284 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirect3DViewport3
, (void **)&viewport3
);
1285 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1288 ref
= get_refcount((IUnknown
*)viewport2
);
1289 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1290 ref
= get_refcount((IUnknown
*)viewport3
);
1291 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1292 IDirect3DViewport3_Release(viewport3
);
1295 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IUnknown
, (void **)&unknown
);
1296 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1299 ref
= get_refcount((IUnknown
*)viewport2
);
1300 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1301 ref
= get_refcount(unknown
);
1302 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1303 IUnknown_Release(unknown
);
1306 /* AddViewport(NULL): Segfault */
1307 hr
= IDirect3DDevice2_DeleteViewport(device
, NULL
);
1308 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1309 hr
= IDirect3DDevice2_GetCurrentViewport(device
, NULL
);
1310 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1312 hr
= IDirect3D2_CreateViewport(d3d
, &another_vp
, NULL
);
1313 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1315 /* Setting a viewport not in the viewport list fails */
1316 hr
= IDirect3DDevice2_SetCurrentViewport(device
, another_vp
);
1317 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1319 hr
= IDirect3DDevice2_AddViewport(device
, viewport2
);
1320 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1321 ref
= get_refcount((IUnknown
*) viewport2
);
1322 ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1323 hr
= IDirect3DDevice2_AddViewport(device
, another_vp
);
1324 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1325 ref
= get_refcount((IUnknown
*) another_vp
);
1326 ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1328 test_vp
= (IDirect3DViewport2
*) 0xbaadc0de;
1329 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1330 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1331 ok(test_vp
== (IDirect3DViewport2
*) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp
);
1333 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
1334 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1335 ref
= get_refcount((IUnknown
*) viewport2
);
1336 ok(ref
== 3, "viewport2 refcount is %d\n", ref
);
1337 ref
= get_refcount((IUnknown
*) device
);
1338 ok(ref
== 1, "device refcount is %d\n", ref
);
1341 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1342 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1343 ok(test_vp
== viewport2
, "Got unexpected viewport %p\n", test_vp
);
1344 ref
= get_refcount((IUnknown
*) viewport2
);
1345 ok(ref
== 4, "viewport2 refcount is %d\n", ref
);
1346 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1348 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1350 /* Cannot set the viewport to NULL */
1351 hr
= IDirect3DDevice2_SetCurrentViewport(device
, NULL
);
1352 ok(hr
== DDERR_INVALIDPARAMS
, "Failed to set viewport to NULL, hr %#x.\n", hr
);
1354 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1355 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1356 ok(test_vp
== viewport2
, "Got unexpected viewport %p\n", test_vp
);
1357 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1359 /* SetCurrentViewport properly releases the old viewport's reference */
1360 hr
= IDirect3DDevice2_SetCurrentViewport(device
, another_vp
);
1361 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1362 ref
= get_refcount((IUnknown
*) viewport2
);
1363 ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1364 ref
= get_refcount((IUnknown
*) another_vp
);
1365 ok(ref
== 3, "another_vp refcount is %d\n", ref
);
1367 /* Deleting the viewport removes the reference added by AddViewport, but not
1368 * the one added by SetCurrentViewport. */
1369 hr
= IDirect3DDevice2_DeleteViewport(device
, another_vp
);
1370 ok(SUCCEEDED(hr
), "Failed to delete viewport from device, hr %#x.\n", hr
);
1371 ref
= get_refcount((IUnknown
*) another_vp
);
1372 todo_wine
ok(ref
== 2, "IDirect3DViewport2 refcount is %d\n", ref
);
1374 /* GetCurrentViewport fails though */
1376 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1377 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1378 ok(test_vp
== NULL
, "Got unexpected viewport %p\n", test_vp
);
1379 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1381 /* Setting a different viewport does not free the leaked reference. How
1382 * do I get rid of it? Leak the viewport for now. */
1383 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
1384 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1385 ref
= get_refcount((IUnknown
*) viewport2
);
1386 ok(ref
== 3, "viewport2 refcount is %d\n", ref
);
1387 ref
= get_refcount((IUnknown
*) another_vp
);
1388 todo_wine
ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1390 /* Destroying the device removes the viewport, but does not free the reference
1391 * added by SetCurrentViewport. */
1392 IDirect3DDevice2_Release(device
);
1393 ref
= get_refcount((IUnknown
*) viewport2
);
1394 todo_wine
ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1396 IDirect3DViewport2_Release(another_vp
);
1397 IDirect3DViewport2_Release(viewport2
);
1398 IDirect3D2_Release(d3d
);
1399 DestroyWindow(window
);
1400 IDirectDraw2_Release(ddraw
);
1403 static void test_zenable(void)
1405 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1406 static D3DTLVERTEX tquad
[] =
1408 {{ 0.0f
}, {480.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1409 {{ 0.0f
}, { 0.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1410 {{640.0f
}, {480.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1411 {{640.0f
}, { 0.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1413 IDirect3DMaterial2
*background
;
1414 IDirect3DViewport2
*viewport
;
1415 IDirect3DDevice2
*device
;
1416 IDirectDrawSurface
*rt
;
1417 IDirectDraw2
*ddraw
;
1424 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1425 0, 0, 640, 480, 0, 0, 0, 0);
1426 ddraw
= create_ddraw();
1427 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1428 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1430 skip("Failed to create a 3D device, skipping test.\n");
1431 IDirectDraw2_Release(ddraw
);
1432 DestroyWindow(window
);
1436 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1437 viewport
= create_viewport(device
, 0, 0, 640, 480);
1438 viewport_set_background(device
, viewport
, background
);
1439 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1440 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1442 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1443 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1445 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1446 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1447 hr
= IDirect3DDevice2_BeginScene(device
);
1448 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1449 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, tquad
, 4, 0);
1450 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1451 hr
= IDirect3DDevice2_EndScene(device
);
1452 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1454 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1455 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1456 for (i
= 0; i
< 4; ++i
)
1458 for (j
= 0; j
< 4; ++j
)
1460 x
= 80 * ((2 * j
) + 1);
1461 y
= 60 * ((2 * i
) + 1);
1462 color
= get_surface_color(rt
, x
, y
);
1463 ok(compare_color(color
, 0x0000ff00, 1),
1464 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1467 IDirectDrawSurface_Release(rt
);
1469 destroy_viewport(device
, viewport
);
1470 destroy_material(background
);
1471 IDirect3DDevice2_Release(device
);
1472 IDirectDraw2_Release(ddraw
);
1473 DestroyWindow(window
);
1476 static void test_ck_rgba(void)
1478 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1479 static D3DTLVERTEX tquad
[] =
1481 {{ 0.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1482 {{ 0.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1483 {{640.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1484 {{640.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1485 {{ 0.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1486 {{ 0.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1487 {{640.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1488 {{640.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1492 D3DCOLOR fill_color
;
1495 D3DCOLOR result1
, result1_broken
;
1496 D3DCOLOR result2
, result2_broken
;
1500 /* r200 on Windows doesn't check the alpha component when applying the color
1501 * key, so the key matches on every texel. */
1502 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1503 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1504 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1505 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1506 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1507 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1508 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1509 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1512 D3DTEXTUREHANDLE texture_handle
;
1513 IDirect3DMaterial2
*background
;
1514 IDirectDrawSurface
*surface
;
1515 IDirect3DViewport2
*viewport
;
1516 IDirect3DTexture2
*texture
;
1517 DDSURFACEDESC surface_desc
;
1518 IDirect3DDevice2
*device
;
1519 IDirectDrawSurface
*rt
;
1520 IDirectDraw2
*ddraw
;
1527 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1528 0, 0, 640, 480, 0, 0, 0, 0);
1529 ddraw
= create_ddraw();
1530 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1531 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1533 skip("Failed to create a 3D device, skipping test.\n");
1534 IDirectDraw2_Release(ddraw
);
1535 DestroyWindow(window
);
1539 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1540 viewport
= create_viewport(device
, 0, 0, 640, 480);
1541 viewport_set_background(device
, viewport
, background
);
1542 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1543 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1545 memset(&surface_desc
, 0, sizeof(surface_desc
));
1546 surface_desc
.dwSize
= sizeof(surface_desc
);
1547 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1548 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1549 surface_desc
.dwWidth
= 256;
1550 surface_desc
.dwHeight
= 256;
1551 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1552 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1553 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1554 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1555 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1556 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1557 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1558 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1559 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1560 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1561 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1562 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1563 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1564 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
1565 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1566 IDirect3DTexture2_Release(texture
);
1568 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1569 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1570 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1571 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1572 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1573 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1575 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1576 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1578 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1580 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1581 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1582 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1583 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1585 memset(&fx
, 0, sizeof(fx
));
1586 fx
.dwSize
= sizeof(fx
);
1587 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1588 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1589 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1591 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
1592 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1593 hr
= IDirect3DDevice2_BeginScene(device
);
1594 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1595 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1596 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1597 hr
= IDirect3DDevice2_EndScene(device
);
1598 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1600 color
= get_surface_color(rt
, 320, 240);
1601 ok(compare_color(color
, tests
[i
].result1
, 1) || compare_color(color
, tests
[i
].result1_broken
, 1),
1602 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1603 tests
[i
].result1
, i
, color
);
1605 U5(fx
).dwFillColor
= 0xff0000ff;
1606 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1607 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1609 hr
= IDirect3DDevice2_BeginScene(device
);
1610 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1611 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[4], 4, 0);
1612 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1613 hr
= IDirect3DDevice2_EndScene(device
);
1614 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1616 /* This tests that fragments that are masked out by the color key are
1617 * discarded, instead of just fully transparent. */
1618 color
= get_surface_color(rt
, 320, 240);
1619 ok(compare_color(color
, tests
[i
].result2
, 1) || compare_color(color
, tests
[i
].result2_broken
, 1),
1620 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1621 tests
[i
].result2
, i
, color
);
1624 IDirectDrawSurface_Release(rt
);
1625 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1626 ok(SUCCEEDED(hr
), "Failed to unset texture, hr %#x.\n", hr
);
1627 IDirectDrawSurface_Release(surface
);
1628 destroy_viewport(device
, viewport
);
1629 destroy_material(background
);
1630 IDirect3DDevice2_Release(device
);
1631 IDirectDraw2_Release(ddraw
);
1632 DestroyWindow(window
);
1635 static void test_ck_default(void)
1637 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1638 static D3DTLVERTEX tquad
[] =
1640 {{ 0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1641 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1642 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1643 {{640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1645 IDirectDrawSurface
*surface
, *rt
;
1646 D3DTEXTUREHANDLE texture_handle
;
1647 IDirect3DMaterial2
*background
;
1648 IDirect3DViewport2
*viewport
;
1649 DDSURFACEDESC surface_desc
;
1650 IDirect3DTexture2
*texture
;
1651 IDirect3DDevice2
*device
;
1652 IDirectDraw2
*ddraw
;
1659 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1660 0, 0, 640, 480, 0, 0, 0, 0);
1661 ddraw
= create_ddraw();
1662 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1663 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1665 skip("Failed to create a 3D device, skipping test.\n");
1666 IDirectDraw2_Release(ddraw
);
1667 DestroyWindow(window
);
1671 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1672 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1674 background
= create_diffuse_material(device
, 0.0, 1.0f
, 0.0f
, 1.0f
);
1675 viewport
= create_viewport(device
, 0, 0, 640, 480);
1676 viewport_set_background(device
, viewport
, background
);
1677 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1678 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1680 memset(&surface_desc
, 0, sizeof(surface_desc
));
1681 surface_desc
.dwSize
= sizeof(surface_desc
);
1682 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1683 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1684 surface_desc
.dwWidth
= 256;
1685 surface_desc
.dwHeight
= 256;
1686 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1687 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1688 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1689 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1690 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1691 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1692 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1693 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1694 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1695 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1696 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1697 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1698 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
1699 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1700 IDirect3DTexture_Release(texture
);
1702 memset(&fx
, 0, sizeof(fx
));
1703 fx
.dwSize
= sizeof(fx
);
1704 U5(fx
).dwFillColor
= 0x000000ff;
1705 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1706 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1708 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1709 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1710 hr
= IDirect3DDevice2_BeginScene(device
);
1711 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1712 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1713 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
1714 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1715 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1716 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1717 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1718 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1719 hr
= IDirect3DDevice2_EndScene(device
);
1720 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1721 color
= get_surface_color(rt
, 320, 240);
1722 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1724 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1725 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1726 hr
= IDirect3DDevice2_BeginScene(device
);
1727 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1728 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1729 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1730 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1731 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1732 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1733 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1734 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1735 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1736 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
1737 hr
= IDirect3DDevice2_EndScene(device
);
1738 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1739 color
= get_surface_color(rt
, 320, 240);
1740 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1742 IDirectDrawSurface_Release(surface
);
1743 destroy_viewport(device
, viewport
);
1744 destroy_material(background
);
1745 IDirectDrawSurface_Release(rt
);
1746 IDirect3DDevice2_Release(device
);
1747 IDirectDraw2_Release(ddraw
);
1748 DestroyWindow(window
);
1751 static void test_ck_complex(void)
1753 IDirectDrawSurface
*surface
, *mipmap
, *tmp
;
1754 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
1755 DDSURFACEDESC surface_desc
;
1756 IDirect3DDevice2
*device
;
1757 DDCOLORKEY color_key
;
1758 IDirectDraw2
*ddraw
;
1764 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1765 0, 0, 640, 480, 0, 0, 0, 0);
1766 ddraw
= create_ddraw();
1767 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1768 if (!(device
= create_device(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1770 skip("Failed to create a 3D device, skipping test.\n");
1771 DestroyWindow(window
);
1772 IDirectDraw2_Release(ddraw
);
1775 IDirect3DDevice2_Release(device
);
1777 memset(&surface_desc
, 0, sizeof(surface_desc
));
1778 surface_desc
.dwSize
= sizeof(surface_desc
);
1779 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1780 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1781 surface_desc
.dwWidth
= 128;
1782 surface_desc
.dwHeight
= 128;
1783 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1784 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1786 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1787 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1788 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1789 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1790 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1791 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1792 memset(&color_key
, 0, sizeof(color_key
));
1793 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1794 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1795 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1796 color_key
.dwColorSpaceLowValue
);
1797 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1798 color_key
.dwColorSpaceHighValue
);
1801 IDirectDrawSurface_AddRef(mipmap
);
1802 for (i
= 0; i
< 7; ++i
)
1804 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1805 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1807 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1808 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1809 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1810 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1811 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1812 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x, i %u.\n", hr
, i
);
1813 memset(&color_key
, 0, sizeof(color_key
));
1814 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1815 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x, i %u.\n", hr
, i
);
1816 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1817 color_key
.dwColorSpaceLowValue
, i
);
1818 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1819 color_key
.dwColorSpaceHighValue
, i
);
1821 IDirectDrawSurface_Release(mipmap
);
1825 memset(&color_key
, 0, sizeof(color_key
));
1826 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1827 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1828 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1829 color_key
.dwColorSpaceLowValue
);
1830 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1831 color_key
.dwColorSpaceHighValue
);
1833 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1834 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1835 IDirectDrawSurface_Release(mipmap
);
1836 refcount
= IDirectDrawSurface_Release(surface
);
1837 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1839 memset(&surface_desc
, 0, sizeof(surface_desc
));
1840 surface_desc
.dwSize
= sizeof(surface_desc
);
1841 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1842 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1843 surface_desc
.dwBackBufferCount
= 1;
1844 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1845 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1847 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1848 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1849 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1850 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1851 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1852 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1853 memset(&color_key
, 0, sizeof(color_key
));
1854 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1855 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1856 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1857 color_key
.dwColorSpaceLowValue
);
1858 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1859 color_key
.dwColorSpaceHighValue
);
1861 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
1862 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
1864 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1865 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1866 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1867 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1868 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1869 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1870 memset(&color_key
, 0, sizeof(color_key
));
1871 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1872 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1873 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1874 color_key
.dwColorSpaceLowValue
);
1875 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1876 color_key
.dwColorSpaceHighValue
);
1878 IDirectDrawSurface_Release(tmp
);
1880 refcount
= IDirectDrawSurface_Release(surface
);
1881 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1882 refcount
= IDirectDraw2_Release(ddraw
);
1883 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1884 DestroyWindow(window
);
1890 REFIID refcount_iid
;
1894 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
1895 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
1897 ULONG refcount
, expected_refcount
;
1898 IUnknown
*iface1
, *iface2
;
1902 for (i
= 0; i
< entry_count
; ++i
)
1904 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
1905 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
1908 for (j
= 0; j
< entry_count
; ++j
)
1910 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
1911 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
1914 expected_refcount
= 0;
1915 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
1916 ++expected_refcount
;
1917 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
1918 ++expected_refcount
;
1919 refcount
= IUnknown_Release(iface2
);
1920 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1921 refcount
, test_name
, i
, j
, expected_refcount
);
1925 expected_refcount
= 0;
1926 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
1927 ++expected_refcount
;
1928 refcount
= IUnknown_Release(iface1
);
1929 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1930 refcount
, test_name
, i
, expected_refcount
);
1935 static void test_surface_qi(void)
1937 static const struct qi_test tests
[] =
1939 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface
, S_OK
},
1940 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface
, S_OK
},
1941 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1942 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1943 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1944 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1945 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1946 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1947 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1948 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
1949 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
1950 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
1951 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
1952 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
1953 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
1954 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
1955 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
1956 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
1957 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
1958 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
1959 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
1960 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
1961 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
1962 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
1963 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
1964 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
1965 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
1966 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
1967 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
1968 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
1969 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
1970 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
1971 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
1972 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
1973 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1976 IDirectDrawSurface
*surface
;
1977 DDSURFACEDESC surface_desc
;
1978 IDirect3DDevice2
*device
;
1979 IDirectDraw2
*ddraw
;
1983 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1985 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1989 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1990 0, 0, 640, 480, 0, 0, 0, 0);
1991 ddraw
= create_ddraw();
1992 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1993 /* Try to create a D3D device to see if the ddraw implementation supports
1994 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1995 * doesn't support e.g. the IDirect3DTexture interfaces. */
1996 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1998 skip("Failed to create a 3D device, skipping test.\n");
1999 IDirectDraw2_Release(ddraw
);
2000 DestroyWindow(window
);
2003 IDirect3DDevice_Release(device
);
2005 memset(&surface_desc
, 0, sizeof(surface_desc
));
2006 surface_desc
.dwSize
= sizeof(surface_desc
);
2007 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2008 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2009 surface_desc
.dwWidth
= 512;
2010 surface_desc
.dwHeight
= 512;
2011 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2012 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2014 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface
, tests
, sizeof(tests
) / sizeof(*tests
));
2016 IDirectDrawSurface_Release(surface
);
2017 IDirectDraw2_Release(ddraw
);
2018 DestroyWindow(window
);
2021 static void test_device_qi(void)
2023 static const struct qi_test tests
[] =
2025 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
2026 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
2027 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
2028 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2029 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
2030 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
2031 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
2032 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
2033 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
2034 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
2035 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
2036 {&IID_IDirect3DDevice2
, &IID_IDirect3DDevice2
, S_OK
},
2037 {&IID_IDirect3DDevice
, &IID_IDirect3DDevice2
, S_OK
},
2038 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
2039 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
2040 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
2041 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
2042 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
2043 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
2044 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
2045 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
2046 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
2047 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
2048 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
2049 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
2050 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
2051 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
2052 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
2053 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
2054 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
2055 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
2056 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
2057 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
2058 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
2059 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
2060 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
2061 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
2062 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
2063 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
2064 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
2065 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
2066 {&IID_IUnknown
, &IID_IDirect3DDevice2
, S_OK
},
2069 IDirect3DDevice2
*device
;
2070 IDirectDraw2
*ddraw
;
2073 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2074 0, 0, 640, 480, 0, 0, 0, 0);
2075 ddraw
= create_ddraw();
2076 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2077 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
2079 skip("Failed to create a 3D device, skipping test.\n");
2080 IDirectDraw2_Release(ddraw
);
2081 DestroyWindow(window
);
2085 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice2
, tests
, sizeof(tests
) / sizeof(*tests
));
2087 IDirect3DDevice2_Release(device
);
2088 IDirectDraw2_Release(ddraw
);
2089 DestroyWindow(window
);
2092 static void test_wndproc(void)
2094 LONG_PTR proc
, ddraw_proc
;
2095 IDirectDraw2
*ddraw
;
2101 static struct message messages
[] =
2103 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2104 {WM_MOVE
, FALSE
, 0},
2105 {WM_SIZE
, FALSE
, 0},
2106 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2107 {WM_ACTIVATE
, FALSE
, 0},
2108 {WM_SETFOCUS
, FALSE
, 0},
2112 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2113 ddraw
= create_ddraw();
2114 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2116 wc
.lpfnWndProc
= test_proc
;
2117 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2118 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2120 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2121 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2123 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2124 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2125 (LONG_PTR
)test_proc
, proc
);
2126 expect_messages
= messages
;
2127 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2128 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2129 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2130 expect_messages
= NULL
;
2131 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2132 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2133 (LONG_PTR
)test_proc
, proc
);
2134 ref
= IDirectDraw2_Release(ddraw
);
2135 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2136 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2137 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2138 (LONG_PTR
)test_proc
, proc
);
2140 /* DDSCL_NORMAL doesn't. */
2141 ddraw
= create_ddraw();
2142 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2143 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2144 (LONG_PTR
)test_proc
, proc
);
2145 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2146 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2147 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2148 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2149 (LONG_PTR
)test_proc
, proc
);
2150 ref
= IDirectDraw2_Release(ddraw
);
2151 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2152 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2153 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2154 (LONG_PTR
)test_proc
, proc
);
2156 /* The original window proc is only restored by ddraw if the current
2157 * window proc matches the one ddraw set. This also affects switching
2158 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2159 ddraw
= create_ddraw();
2160 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2161 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2162 (LONG_PTR
)test_proc
, proc
);
2163 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2164 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2165 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2166 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2167 (LONG_PTR
)test_proc
, proc
);
2169 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2170 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2171 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2172 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2173 (LONG_PTR
)test_proc
, proc
);
2174 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2175 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2176 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2177 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2178 (LONG_PTR
)test_proc
, proc
);
2179 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2180 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2181 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2182 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2183 (LONG_PTR
)DefWindowProcA
, proc
);
2184 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2185 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2186 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2187 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2188 (LONG_PTR
)DefWindowProcA
, proc
);
2189 ref
= IDirectDraw2_Release(ddraw
);
2190 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2191 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2192 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2193 (LONG_PTR
)test_proc
, proc
);
2195 ddraw
= create_ddraw();
2196 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2197 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2198 (LONG_PTR
)test_proc
, proc
);
2199 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2200 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2201 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2202 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2203 (LONG_PTR
)test_proc
, proc
);
2204 ref
= IDirectDraw2_Release(ddraw
);
2205 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2206 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2207 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2208 (LONG_PTR
)DefWindowProcA
, proc
);
2210 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2211 expect_messages
= NULL
;
2212 DestroyWindow(window
);
2213 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2216 static void test_window_style(void)
2218 LONG style
, exstyle
, tmp
, expected_style
;
2219 RECT fullscreen_rect
, r
;
2220 IDirectDraw2
*ddraw
;
2226 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2227 0, 0, 100, 100, 0, 0, 0, 0);
2228 ddraw
= create_ddraw();
2229 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2231 style
= GetWindowLongA(window
, GWL_STYLE
);
2232 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2233 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2235 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2236 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2238 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2239 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2240 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2241 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2243 GetWindowRect(window
, &r
);
2244 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2245 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2246 r
.left
, r
.top
, r
.right
, r
.bottom
);
2247 GetClientRect(window
, &r
);
2248 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2250 ret
= SetForegroundWindow(GetDesktopWindow());
2251 ok(ret
, "Failed to set foreground window.\n");
2253 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2254 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2255 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2256 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2258 ret
= SetForegroundWindow(window
);
2259 ok(ret
, "Failed to set foreground window.\n");
2260 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2261 * the next tests expect this. */
2262 ShowWindow(window
, SW_HIDE
);
2264 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2265 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2267 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2268 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2269 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2270 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2272 ShowWindow(window
, SW_SHOW
);
2273 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2274 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2276 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2277 expected_style
= style
| WS_VISIBLE
;
2278 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2279 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2280 expected_style
= exstyle
| WS_EX_TOPMOST
;
2281 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2283 ret
= SetForegroundWindow(GetDesktopWindow());
2284 ok(ret
, "Failed to set foreground window.\n");
2285 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2286 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2287 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2288 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2289 expected_style
= exstyle
| WS_EX_TOPMOST
;
2290 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2292 ref
= IDirectDraw2_Release(ddraw
);
2293 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2295 DestroyWindow(window
);
2298 static void test_redundant_mode_set(void)
2300 DDSURFACEDESC surface_desc
= {0};
2301 IDirectDraw2
*ddraw
;
2307 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2308 0, 0, 100, 100, 0, 0, 0, 0);
2309 ddraw
= create_ddraw();
2310 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2312 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2313 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2315 surface_desc
.dwSize
= sizeof(surface_desc
);
2316 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
2317 ok(SUCCEEDED(hr
), "GetDipslayMode failed, hr %#x.\n", hr
);
2319 hr
= IDirectDraw2_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2320 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2321 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2323 GetWindowRect(window
, &r
);
2326 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2327 GetWindowRect(window
, &s
);
2328 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2329 r
.left
, r
.top
, r
.right
, r
.bottom
,
2330 s
.left
, s
.top
, s
.right
, s
.bottom
);
2332 hr
= IDirectDraw2_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2333 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2334 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2336 GetWindowRect(window
, &s
);
2337 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2338 r
.left
, r
.top
, r
.right
, r
.bottom
,
2339 s
.left
, s
.top
, s
.right
, s
.bottom
);
2341 ref
= IDirectDraw2_Release(ddraw
);
2342 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2344 DestroyWindow(window
);
2347 static SIZE screen_size
, screen_size2
;
2349 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2351 if (message
== WM_SIZE
)
2353 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2354 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2357 return test_proc(hwnd
, message
, wparam
, lparam
);
2360 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2362 if (message
== WM_SIZE
)
2364 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2365 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2368 return test_proc(hwnd
, message
, wparam
, lparam
);
2371 struct test_coop_level_mode_set_enum_param
2373 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2376 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC
*surface_desc
, void *context
)
2378 struct test_coop_level_mode_set_enum_param
*param
= context
;
2380 if (U1(surface_desc
->ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2381 return DDENUMRET_OK
;
2382 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2383 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2384 return DDENUMRET_OK
;
2386 if (!param
->ddraw_width
)
2388 param
->ddraw_width
= surface_desc
->dwWidth
;
2389 param
->ddraw_height
= surface_desc
->dwHeight
;
2390 return DDENUMRET_OK
;
2392 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2393 return DDENUMRET_OK
;
2395 param
->user32_width
= surface_desc
->dwWidth
;
2396 param
->user32_height
= surface_desc
->dwHeight
;
2397 return DDENUMRET_CANCEL
;
2400 static void test_coop_level_mode_set(void)
2402 IDirectDrawSurface
*primary
;
2403 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2404 IDirectDraw2
*ddraw
;
2407 HWND window
, window2
;
2411 struct test_coop_level_mode_set_enum_param param
;
2416 static const struct message exclusive_messages
[] =
2418 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2419 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2420 {WM_SIZE
, FALSE
, 0},
2421 {WM_DISPLAYCHANGE
, FALSE
, 0},
2424 static const struct message exclusive_focus_loss_messages
[] =
2426 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2427 {WM_DISPLAYCHANGE
, FALSE
, 0},
2428 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2429 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2430 * SW_MINIMIZED, causing a recursive window activation that does not
2431 * produce the same result in Wine yet. Ignore the difference for now.
2432 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2433 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2434 {WM_MOVE
, FALSE
, 0},
2435 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2436 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2439 static const struct message exclusive_focus_restore_messages
[] =
2441 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2442 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2443 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2444 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2445 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2446 /* Native redundantly sets the window size here. */
2447 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2448 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2449 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2450 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2453 static const struct message sc_restore_messages
[] =
2455 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2456 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2457 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2458 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2461 static const struct message sc_minimize_messages
[] =
2463 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2464 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2465 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2466 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2469 static const struct message sc_maximize_messages
[] =
2471 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2472 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2473 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2474 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2478 static const struct message normal_messages
[] =
2480 {WM_DISPLAYCHANGE
, FALSE
, 0},
2484 ddraw
= create_ddraw();
2485 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2487 memset(¶m
, 0, sizeof(param
));
2488 hr
= IDirectDraw2_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2489 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2490 ref
= IDirectDraw2_Release(ddraw
);
2491 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2493 if (!param
.user32_height
)
2495 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2499 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2500 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2501 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2503 memset(&devmode
, 0, sizeof(devmode
));
2504 devmode
.dmSize
= sizeof(devmode
);
2505 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2506 devmode
.dmPelsWidth
= param
.user32_width
;
2507 devmode
.dmPelsHeight
= param
.user32_height
;
2508 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2509 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2511 ddraw
= create_ddraw();
2512 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2514 wc
.lpfnWndProc
= mode_set_proc
;
2515 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2516 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2517 wc
.lpfnWndProc
= mode_set_proc2
;
2518 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2519 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2521 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2522 0, 0, 100, 100, 0, 0, 0, 0);
2523 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2524 0, 0, 100, 100, 0, 0, 0, 0);
2526 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2527 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2529 GetWindowRect(window
, &r
);
2530 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2531 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2532 r
.left
, r
.top
, r
.right
, r
.bottom
);
2534 memset(&ddsd
, 0, sizeof(ddsd
));
2535 ddsd
.dwSize
= sizeof(ddsd
);
2536 ddsd
.dwFlags
= DDSD_CAPS
;
2537 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2539 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2540 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2541 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2542 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2543 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2544 param
.user32_width
, ddsd
.dwWidth
);
2545 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2546 param
.user32_height
, ddsd
.dwHeight
);
2548 GetWindowRect(window
, &r
);
2549 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2550 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2551 r
.left
, r
.top
, r
.right
, r
.bottom
);
2553 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2554 expect_messages
= exclusive_messages
;
2558 hr
= IDirectDrawSurface_IsLost(primary
);
2559 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2560 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2561 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2562 hr
= IDirectDrawSurface_IsLost(primary
);
2563 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2565 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2566 expect_messages
= NULL
;
2567 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2568 "Expected screen size %ux%u, got %ux%u.\n",
2569 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2571 GetWindowRect(window
, &r
);
2572 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2573 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2574 r
.left
, r
.top
, r
.right
, r
.bottom
);
2576 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2577 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2578 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2579 param
.user32_width
, ddsd
.dwWidth
);
2580 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2581 param
.user32_height
, ddsd
.dwHeight
);
2582 IDirectDrawSurface_Release(primary
);
2584 memset(&ddsd
, 0, sizeof(ddsd
));
2585 ddsd
.dwSize
= sizeof(ddsd
);
2586 ddsd
.dwFlags
= DDSD_CAPS
;
2587 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2589 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2590 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2591 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2592 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2593 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2594 param
.ddraw_width
, ddsd
.dwWidth
);
2595 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2596 param
.ddraw_height
, ddsd
.dwHeight
);
2598 GetWindowRect(window
, &r
);
2599 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2600 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2601 r
.left
, r
.top
, r
.right
, r
.bottom
);
2603 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2604 expect_messages
= exclusive_messages
;
2608 hr
= IDirectDrawSurface_IsLost(primary
);
2609 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2610 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2611 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2612 hr
= IDirectDrawSurface_IsLost(primary
);
2613 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2615 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2616 expect_messages
= NULL
;
2617 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2618 "Expected screen size %ux%u, got %ux%u.\n",
2619 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2621 GetWindowRect(window
, &r
);
2622 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2623 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2624 r
.left
, r
.top
, r
.right
, r
.bottom
);
2626 expect_messages
= exclusive_focus_loss_messages
;
2627 ret
= SetForegroundWindow(GetDesktopWindow());
2628 ok(ret
, "Failed to set foreground window.\n");
2629 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2630 memset(&devmode
, 0, sizeof(devmode
));
2631 devmode
.dmSize
= sizeof(devmode
);
2632 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2633 ok(ret
, "Failed to get display mode.\n");
2634 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2635 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2636 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2638 expect_messages
= exclusive_focus_restore_messages
;
2639 ShowWindow(window
, SW_RESTORE
);
2640 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2642 GetWindowRect(window
, &r
);
2643 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2644 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2645 r
.left
, r
.top
, r
.right
, r
.bottom
);
2646 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2647 ok(ret
, "Failed to get display mode.\n");
2648 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2649 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2650 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2652 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2653 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2654 /* Normally the primary should be restored here. Unfortunately this causes the
2655 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2656 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2657 * the point of the GetSurfaceDesc call. */
2659 expect_messages
= sc_minimize_messages
;
2660 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2661 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2662 expect_messages
= NULL
;
2664 expect_messages
= sc_restore_messages
;
2665 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2666 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2667 expect_messages
= NULL
;
2669 expect_messages
= sc_maximize_messages
;
2670 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2671 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2672 expect_messages
= NULL
;
2674 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2675 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2677 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2678 expect_messages
= exclusive_messages
;
2682 hr
= IDirectDrawSurface_IsLost(primary
);
2683 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2684 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
2685 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2686 hr
= IDirectDrawSurface_IsLost(primary
);
2687 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2689 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2690 expect_messages
= NULL
;
2691 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2692 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2693 "Expected screen size %ux%u, got %ux%u.\n",
2694 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2696 GetWindowRect(window
, &r
);
2697 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2698 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2699 r
.left
, r
.top
, r
.right
, r
.bottom
);
2701 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2702 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2703 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2704 param
.ddraw_width
, ddsd
.dwWidth
);
2705 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2706 param
.ddraw_height
, ddsd
.dwHeight
);
2707 IDirectDrawSurface_Release(primary
);
2710 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2711 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2713 memset(&ddsd
, 0, sizeof(ddsd
));
2714 ddsd
.dwSize
= sizeof(ddsd
);
2715 ddsd
.dwFlags
= DDSD_CAPS
;
2716 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2718 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2719 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2720 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2721 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2722 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2723 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2724 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2725 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2727 GetWindowRect(window
, &r
);
2728 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2729 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2730 r
.left
, r
.top
, r
.right
, r
.bottom
);
2732 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2733 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2735 GetWindowRect(window
, &r
);
2736 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2737 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2738 r
.left
, r
.top
, r
.right
, r
.bottom
);
2740 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2741 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2742 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2743 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2744 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2745 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2746 IDirectDrawSurface_Release(primary
);
2748 memset(&ddsd
, 0, sizeof(ddsd
));
2749 ddsd
.dwSize
= sizeof(ddsd
);
2750 ddsd
.dwFlags
= DDSD_CAPS
;
2751 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2753 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2754 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2755 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2756 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2757 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2758 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2759 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2760 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2762 GetWindowRect(window
, &r
);
2763 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2764 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2765 r
.left
, r
.top
, r
.right
, r
.bottom
);
2767 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2768 expect_messages
= normal_messages
;
2772 hr
= IDirectDrawSurface_IsLost(primary
);
2773 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2774 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2775 devmode
.dmPelsWidth
= param
.user32_width
;
2776 devmode
.dmPelsHeight
= param
.user32_height
;
2777 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2778 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2779 hr
= IDirectDrawSurface_IsLost(primary
);
2780 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2782 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2783 expect_messages
= NULL
;
2784 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2786 GetWindowRect(window
, &r
);
2787 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2788 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2789 r
.left
, r
.top
, r
.right
, r
.bottom
);
2791 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2792 expect_messages
= normal_messages
;
2796 hr
= IDirectDrawSurface_Restore(primary
);
2797 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2798 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2799 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
2801 win_skip("Broken SetDisplayMode(), skipping remaining tests.\n");
2802 IDirectDrawSurface_Release(primary
);
2803 IDirectDraw2_Release(ddraw
);
2806 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2807 hr
= IDirectDrawSurface_Restore(primary
);
2808 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2809 hr
= IDirectDrawSurface_IsLost(primary
);
2810 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2812 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2813 expect_messages
= NULL
;
2814 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2816 GetWindowRect(window
, &r
);
2817 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2818 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2819 r
.left
, r
.top
, r
.right
, r
.bottom
);
2821 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2822 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2823 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2824 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2825 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2826 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2827 IDirectDrawSurface_Release(primary
);
2829 memset(&ddsd
, 0, sizeof(ddsd
));
2830 ddsd
.dwSize
= sizeof(ddsd
);
2831 ddsd
.dwFlags
= DDSD_CAPS
;
2832 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2834 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2835 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2836 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2837 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2838 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2839 param
.ddraw_width
, ddsd
.dwWidth
);
2840 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2841 param
.ddraw_height
, ddsd
.dwHeight
);
2843 GetWindowRect(window
, &r
);
2844 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2845 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2846 r
.left
, r
.top
, r
.right
, r
.bottom
);
2848 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2849 expect_messages
= normal_messages
;
2853 hr
= IDirectDrawSurface_IsLost(primary
);
2854 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2855 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2856 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2857 hr
= IDirectDrawSurface_IsLost(primary
);
2858 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2860 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2861 expect_messages
= NULL
;
2862 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2864 GetWindowRect(window
, &r
);
2865 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2866 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2867 r
.left
, r
.top
, r
.right
, r
.bottom
);
2869 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2870 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2871 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2872 param
.ddraw_width
, ddsd
.dwWidth
);
2873 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2874 param
.ddraw_height
, ddsd
.dwHeight
);
2875 IDirectDrawSurface_Release(primary
);
2877 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2878 ok(ret
, "Failed to get display mode.\n");
2879 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2880 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2881 "Expected resolution %ux%u, got %ux%u.\n",
2882 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2883 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2884 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2885 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2887 memset(&ddsd
, 0, sizeof(ddsd
));
2888 ddsd
.dwSize
= sizeof(ddsd
);
2889 ddsd
.dwFlags
= DDSD_CAPS
;
2890 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2892 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2893 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2894 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2895 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2896 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2897 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2898 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2899 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2901 GetWindowRect(window
, &r
);
2902 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2903 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2904 r
.left
, r
.top
, r
.right
, r
.bottom
);
2906 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2907 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2908 * not DDSCL_FULLSCREEN. */
2909 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2910 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2912 GetWindowRect(window
, &r
);
2913 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2914 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2915 r
.left
, r
.top
, r
.right
, r
.bottom
);
2917 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2918 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2919 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2920 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2921 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2922 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2923 IDirectDrawSurface_Release(primary
);
2925 memset(&ddsd
, 0, sizeof(ddsd
));
2926 ddsd
.dwSize
= sizeof(ddsd
);
2927 ddsd
.dwFlags
= DDSD_CAPS
;
2928 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2930 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2931 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2932 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2933 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2934 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2935 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2936 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2937 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2939 GetWindowRect(window
, &r
);
2940 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2941 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2942 r
.left
, r
.top
, r
.right
, r
.bottom
);
2944 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2945 expect_messages
= normal_messages
;
2949 hr
= IDirectDrawSurface_IsLost(primary
);
2950 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2951 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2952 devmode
.dmPelsWidth
= param
.user32_width
;
2953 devmode
.dmPelsHeight
= param
.user32_height
;
2954 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2955 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2956 hr
= IDirectDrawSurface_IsLost(primary
);
2957 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2959 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2960 expect_messages
= NULL
;
2961 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2963 GetWindowRect(window
, &r
);
2964 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2965 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2966 r
.left
, r
.top
, r
.right
, r
.bottom
);
2968 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2969 expect_messages
= normal_messages
;
2973 hr
= IDirectDrawSurface_Restore(primary
);
2974 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2975 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2976 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2977 hr
= IDirectDrawSurface_Restore(primary
);
2978 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2979 hr
= IDirectDrawSurface_IsLost(primary
);
2980 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2982 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2983 expect_messages
= NULL
;
2984 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2986 GetWindowRect(window
, &r
);
2987 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2988 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2989 r
.left
, r
.top
, r
.right
, r
.bottom
);
2991 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2992 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2993 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2994 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2995 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2996 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2997 IDirectDrawSurface_Release(primary
);
2999 memset(&ddsd
, 0, sizeof(ddsd
));
3000 ddsd
.dwSize
= sizeof(ddsd
);
3001 ddsd
.dwFlags
= DDSD_CAPS
;
3002 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3004 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3005 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3006 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3007 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3008 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3009 param
.ddraw_width
, ddsd
.dwWidth
);
3010 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3011 param
.ddraw_height
, ddsd
.dwHeight
);
3013 GetWindowRect(window
, &r
);
3014 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3015 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3016 r
.left
, r
.top
, r
.right
, r
.bottom
);
3018 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3019 expect_messages
= normal_messages
;
3023 hr
= IDirectDrawSurface_IsLost(primary
);
3024 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3025 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3026 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3027 hr
= IDirectDrawSurface_IsLost(primary
);
3028 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3030 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3031 expect_messages
= NULL
;
3032 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3034 GetWindowRect(window
, &r
);
3035 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3036 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3037 r
.left
, r
.top
, r
.right
, r
.bottom
);
3039 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3040 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3041 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3042 param
.ddraw_width
, ddsd
.dwWidth
);
3043 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3044 param
.ddraw_height
, ddsd
.dwHeight
);
3045 IDirectDrawSurface_Release(primary
);
3047 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3048 ok(ret
, "Failed to get display mode.\n");
3049 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3050 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3051 "Expected resolution %ux%u, got %ux%u.\n",
3052 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3053 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3054 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3055 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3057 memset(&ddsd
, 0, sizeof(ddsd
));
3058 ddsd
.dwSize
= sizeof(ddsd
);
3059 ddsd
.dwFlags
= DDSD_CAPS
;
3060 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3062 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3063 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3064 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3065 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3066 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3067 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3068 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3069 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3070 IDirectDrawSurface_Release(primary
);
3072 GetWindowRect(window
, &r
);
3073 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3074 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3075 r
.left
, r
.top
, r
.right
, r
.bottom
);
3077 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3078 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3079 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3080 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3081 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3083 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3084 expect_messages
= exclusive_messages
;
3088 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3089 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3091 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3092 expect_messages
= NULL
;
3093 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
3094 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
3095 "Expected screen size %ux%u, got %ux%u.\n",
3096 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3097 screen_size
.cx
, screen_size
.cy
);
3099 GetWindowRect(window
, &r
);
3100 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3101 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3102 r
.left
, r
.top
, r
.right
, r
.bottom
);
3104 memset(&ddsd
, 0, sizeof(ddsd
));
3105 ddsd
.dwSize
= sizeof(ddsd
);
3106 ddsd
.dwFlags
= DDSD_CAPS
;
3107 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3109 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3110 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3111 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3112 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3113 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3114 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3115 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3116 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3117 IDirectDrawSurface_Release(primary
);
3119 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3120 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3121 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3122 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3123 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3125 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3126 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3128 memset(&ddsd
, 0, sizeof(ddsd
));
3129 ddsd
.dwSize
= sizeof(ddsd
);
3130 ddsd
.dwFlags
= DDSD_CAPS
;
3131 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3133 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3134 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3135 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3136 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3137 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3138 param
.ddraw_width
, ddsd
.dwWidth
);
3139 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3140 param
.ddraw_height
, ddsd
.dwHeight
);
3141 IDirectDrawSurface_Release(primary
);
3143 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3144 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3146 /* If the window is changed at the same time, messages are sent to the new window. */
3147 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3148 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3149 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3150 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3152 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3153 expect_messages
= exclusive_messages
;
3156 screen_size2
.cx
= 0;
3157 screen_size2
.cy
= 0;
3159 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3160 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3162 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3163 expect_messages
= NULL
;
3164 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
3165 screen_size
.cx
, screen_size
.cy
);
3166 ok(screen_size2
.cx
== registry_mode
.dmPelsWidth
&& screen_size2
.cy
== registry_mode
.dmPelsHeight
,
3167 "Expected screen size 2 %ux%u, got %ux%u.\n",
3168 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size2
.cx
, screen_size2
.cy
);
3170 GetWindowRect(window
, &r
);
3171 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3172 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
3173 r
.left
, r
.top
, r
.right
, r
.bottom
);
3174 GetWindowRect(window2
, &r
);
3175 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3176 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3177 r
.left
, r
.top
, r
.right
, r
.bottom
);
3179 memset(&ddsd
, 0, sizeof(ddsd
));
3180 ddsd
.dwSize
= sizeof(ddsd
);
3181 ddsd
.dwFlags
= DDSD_CAPS
;
3182 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3184 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3185 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3186 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3187 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3188 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3189 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3190 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3191 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3192 IDirectDrawSurface_Release(primary
);
3194 ref
= IDirectDraw2_Release(ddraw
);
3195 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3197 GetWindowRect(window
, &r
);
3198 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3199 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
3200 r
.left
, r
.top
, r
.right
, r
.bottom
);
3203 expect_messages
= NULL
;
3204 DestroyWindow(window
);
3205 DestroyWindow(window2
);
3206 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3207 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3210 static void test_coop_level_mode_set_multi(void)
3212 IDirectDraw2
*ddraw1
, *ddraw2
;
3218 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3219 0, 0, 100, 100, 0, 0, 0, 0);
3220 ddraw1
= create_ddraw();
3221 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3223 /* With just a single ddraw object, the display mode is restored on
3225 hr
= set_display_mode(ddraw1
, 800, 600);
3226 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
3228 win_skip("Broken SetDisplayMode(), skipping test.\n");
3229 IDirectDraw2_Release(ddraw1
);
3230 DestroyWindow(window
);
3233 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3234 w
= GetSystemMetrics(SM_CXSCREEN
);
3235 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3236 h
= GetSystemMetrics(SM_CYSCREEN
);
3237 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3239 ref
= IDirectDraw2_Release(ddraw1
);
3240 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3241 w
= GetSystemMetrics(SM_CXSCREEN
);
3242 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3243 h
= GetSystemMetrics(SM_CYSCREEN
);
3244 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3246 /* When there are multiple ddraw objects, the display mode is restored to
3247 * the initial mode, before the first SetDisplayMode() call. */
3248 ddraw1
= create_ddraw();
3249 hr
= set_display_mode(ddraw1
, 800, 600);
3250 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3251 w
= GetSystemMetrics(SM_CXSCREEN
);
3252 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3253 h
= GetSystemMetrics(SM_CYSCREEN
);
3254 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3256 ddraw2
= create_ddraw();
3257 hr
= set_display_mode(ddraw2
, 640, 480);
3258 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3259 w
= GetSystemMetrics(SM_CXSCREEN
);
3260 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3261 h
= GetSystemMetrics(SM_CYSCREEN
);
3262 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3264 ref
= IDirectDraw2_Release(ddraw2
);
3265 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3266 w
= GetSystemMetrics(SM_CXSCREEN
);
3267 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3268 h
= GetSystemMetrics(SM_CYSCREEN
);
3269 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3271 ref
= IDirectDraw2_Release(ddraw1
);
3272 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3273 w
= GetSystemMetrics(SM_CXSCREEN
);
3274 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3275 h
= GetSystemMetrics(SM_CYSCREEN
);
3276 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3278 /* Regardless of release ordering. */
3279 ddraw1
= create_ddraw();
3280 hr
= set_display_mode(ddraw1
, 800, 600);
3281 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3282 w
= GetSystemMetrics(SM_CXSCREEN
);
3283 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3284 h
= GetSystemMetrics(SM_CYSCREEN
);
3285 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3287 ddraw2
= create_ddraw();
3288 hr
= set_display_mode(ddraw2
, 640, 480);
3289 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3290 w
= GetSystemMetrics(SM_CXSCREEN
);
3291 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3292 h
= GetSystemMetrics(SM_CYSCREEN
);
3293 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3295 ref
= IDirectDraw2_Release(ddraw1
);
3296 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3297 w
= GetSystemMetrics(SM_CXSCREEN
);
3298 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3299 h
= GetSystemMetrics(SM_CYSCREEN
);
3300 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3302 ref
= IDirectDraw2_Release(ddraw2
);
3303 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3304 w
= GetSystemMetrics(SM_CXSCREEN
);
3305 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3306 h
= GetSystemMetrics(SM_CYSCREEN
);
3307 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3309 /* But only for ddraw objects that called SetDisplayMode(). */
3310 ddraw1
= create_ddraw();
3311 ddraw2
= create_ddraw();
3312 hr
= set_display_mode(ddraw2
, 640, 480);
3313 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3314 w
= GetSystemMetrics(SM_CXSCREEN
);
3315 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3316 h
= GetSystemMetrics(SM_CYSCREEN
);
3317 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3319 ref
= IDirectDraw2_Release(ddraw1
);
3320 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3321 w
= GetSystemMetrics(SM_CXSCREEN
);
3322 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3323 h
= GetSystemMetrics(SM_CYSCREEN
);
3324 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3326 ref
= IDirectDraw2_Release(ddraw2
);
3327 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3328 w
= GetSystemMetrics(SM_CXSCREEN
);
3329 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3330 h
= GetSystemMetrics(SM_CYSCREEN
);
3331 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3333 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3334 * restoring the display mode. */
3335 ddraw1
= create_ddraw();
3336 hr
= set_display_mode(ddraw1
, 800, 600);
3337 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3338 w
= GetSystemMetrics(SM_CXSCREEN
);
3339 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3340 h
= GetSystemMetrics(SM_CYSCREEN
);
3341 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3343 ddraw2
= create_ddraw();
3344 hr
= set_display_mode(ddraw2
, 640, 480);
3345 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3346 w
= GetSystemMetrics(SM_CXSCREEN
);
3347 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3348 h
= GetSystemMetrics(SM_CYSCREEN
);
3349 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3351 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3352 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3354 ref
= IDirectDraw2_Release(ddraw1
);
3355 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3356 w
= GetSystemMetrics(SM_CXSCREEN
);
3357 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3358 h
= GetSystemMetrics(SM_CYSCREEN
);
3359 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3361 ref
= IDirectDraw2_Release(ddraw2
);
3362 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3363 w
= GetSystemMetrics(SM_CXSCREEN
);
3364 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3365 h
= GetSystemMetrics(SM_CYSCREEN
);
3366 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3368 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3369 ddraw1
= create_ddraw();
3370 hr
= set_display_mode(ddraw1
, 800, 600);
3371 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3372 w
= GetSystemMetrics(SM_CXSCREEN
);
3373 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3374 h
= GetSystemMetrics(SM_CYSCREEN
);
3375 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3377 hr
= IDirectDraw2_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3378 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3380 ddraw2
= create_ddraw();
3381 hr
= set_display_mode(ddraw2
, 640, 480);
3382 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3384 ref
= IDirectDraw2_Release(ddraw1
);
3385 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3386 w
= GetSystemMetrics(SM_CXSCREEN
);
3387 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3388 h
= GetSystemMetrics(SM_CYSCREEN
);
3389 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3391 ref
= IDirectDraw2_Release(ddraw2
);
3392 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3393 w
= GetSystemMetrics(SM_CXSCREEN
);
3394 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3395 h
= GetSystemMetrics(SM_CYSCREEN
);
3396 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3398 DestroyWindow(window
);
3401 static void test_initialize(void)
3403 IDirectDraw2
*ddraw
;
3406 ddraw
= create_ddraw();
3407 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3409 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3410 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3411 IDirectDraw2_Release(ddraw
);
3414 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw2
, (void **)&ddraw
);
3415 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw2 instance, hr %#x.\n", hr
);
3416 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3417 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3418 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3419 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3420 IDirectDraw2_Release(ddraw
);
3424 static void test_coop_level_surf_create(void)
3426 IDirectDrawSurface
*surface
;
3427 IDirectDraw2
*ddraw
;
3431 ddraw
= create_ddraw();
3432 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3434 memset(&ddsd
, 0, sizeof(ddsd
));
3435 ddsd
.dwSize
= sizeof(ddsd
);
3436 ddsd
.dwFlags
= DDSD_CAPS
;
3437 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3438 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3439 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3441 IDirectDraw2_Release(ddraw
);
3444 static void test_coop_level_multi_window(void)
3446 HWND window1
, window2
;
3447 IDirectDraw2
*ddraw
;
3450 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3451 0, 0, 640, 480, 0, 0, 0, 0);
3452 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3453 0, 0, 640, 480, 0, 0, 0, 0);
3454 ddraw
= create_ddraw();
3455 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3457 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3458 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3459 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3460 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3461 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3462 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3464 IDirectDraw2_Release(ddraw
);
3465 DestroyWindow(window2
);
3466 DestroyWindow(window1
);
3469 static void test_clear_rect_count(void)
3471 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3472 IDirect3DMaterial2
*white
, *red
, *green
, *blue
;
3473 IDirect3DViewport2
*viewport
;
3474 IDirect3DDevice2
*device
;
3475 IDirectDrawSurface
*rt
;
3476 IDirectDraw2
*ddraw
;
3481 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3482 0, 0, 640, 480, 0, 0, 0, 0);
3483 ddraw
= create_ddraw();
3484 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3485 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3487 skip("Failed to create a 3D device, skipping test.\n");
3488 IDirectDraw2_Release(ddraw
);
3489 DestroyWindow(window
);
3493 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
3494 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3496 white
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
3497 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
3498 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
3499 blue
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
3501 viewport
= create_viewport(device
, 0, 0, 640, 480);
3502 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
3503 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3505 viewport_set_background(device
, viewport
, white
);
3506 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3507 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3508 viewport_set_background(device
, viewport
, red
);
3509 hr
= IDirect3DViewport2_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3510 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3511 viewport_set_background(device
, viewport
, green
);
3512 hr
= IDirect3DViewport2_Clear(viewport
, 0, NULL
, D3DCLEAR_TARGET
);
3513 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3514 viewport_set_background(device
, viewport
, blue
);
3515 hr
= IDirect3DViewport2_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3516 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3518 color
= get_surface_color(rt
, 320, 240);
3519 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x000000ff, 1)),
3520 "Got unexpected color 0x%08x.\n", color
);
3522 IDirectDrawSurface_Release(rt
);
3523 destroy_viewport(device
, viewport
);
3524 destroy_material(white
);
3525 destroy_material(red
);
3526 destroy_material(green
);
3527 destroy_material(blue
);
3528 IDirect3DDevice2_Release(device
);
3529 IDirectDraw2_Release(ddraw
);
3530 DestroyWindow(window
);
3533 static BOOL
test_mode_restored(IDirectDraw2
*ddraw
, HWND window
)
3535 DDSURFACEDESC ddsd1
, ddsd2
;
3538 memset(&ddsd1
, 0, sizeof(ddsd1
));
3539 ddsd1
.dwSize
= sizeof(ddsd1
);
3540 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &ddsd1
);
3541 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3543 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3544 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3545 hr
= set_display_mode(ddraw
, 640, 480);
3546 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3547 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3548 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3550 memset(&ddsd2
, 0, sizeof(ddsd2
));
3551 ddsd2
.dwSize
= sizeof(ddsd2
);
3552 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &ddsd2
);
3553 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3554 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3555 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3557 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
3560 static void test_coop_level_versions(void)
3566 IDirectDrawSurface
*surface
;
3567 IDirectDraw2
*ddraw2
;
3570 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3571 0, 0, 640, 480, 0, 0, 0, 0);
3573 ddraw2
= create_ddraw();
3574 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3575 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3576 restored
= test_mode_restored(ddraw2
, window
);
3577 ok(restored
, "Display mode not restored in new ddraw object\n");
3579 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3580 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3581 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3583 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3584 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3585 restored
= test_mode_restored(ddraw2
, window
);
3586 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3588 /* A successful one does */
3589 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3590 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3591 restored
= test_mode_restored(ddraw2
, window
);
3592 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3594 IDirectDraw_Release(ddraw
);
3595 IDirectDraw2_Release(ddraw2
);
3597 ddraw2
= create_ddraw();
3598 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3599 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3600 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3602 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
3603 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3604 restored
= test_mode_restored(ddraw2
, window
);
3605 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3607 IDirectDraw_Release(ddraw
);
3608 IDirectDraw2_Release(ddraw2
);
3610 /* A failing call does not restore the ddraw2+ behavior */
3611 ddraw2
= create_ddraw();
3612 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3613 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3614 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3616 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3617 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3618 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3619 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3620 restored
= test_mode_restored(ddraw2
, window
);
3621 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3623 IDirectDraw_Release(ddraw
);
3624 IDirectDraw2_Release(ddraw2
);
3626 /* Neither does a sequence of successful calls with the new interface */
3627 ddraw2
= create_ddraw();
3628 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3629 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3630 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3632 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3633 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3634 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3635 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3636 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_NORMAL
);
3637 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3639 restored
= test_mode_restored(ddraw2
, window
);
3640 ok(!restored
, "Display mode restored after ddraw1-ddraw2 SetCooperativeLevel() call sequence\n");
3641 IDirectDraw_Release(ddraw
);
3642 IDirectDraw2_Release(ddraw2
);
3644 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3645 ddraw2
= create_ddraw();
3646 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3647 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3648 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3650 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_NORMAL
);
3651 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3653 memset(&ddsd
, 0, sizeof(ddsd
));
3654 ddsd
.dwSize
= sizeof(ddsd
);
3655 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
3656 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
3657 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
3658 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3659 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
3660 IDirectDrawSurface_Release(surface
);
3661 restored
= test_mode_restored(ddraw2
, window
);
3662 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
3664 IDirectDraw_Release(ddraw
);
3665 IDirectDraw2_Release(ddraw2
);
3666 DestroyWindow(window
);
3669 static void test_lighting_interface_versions(void)
3671 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3672 IDirect3DMaterial2
*emissive
, *background
;
3673 IDirect3DViewport2
*viewport
;
3674 IDirect3DDevice2
*device
;
3675 IDirectDrawSurface
*rt
;
3676 IDirectDraw2
*ddraw
;
3680 D3DMATERIALHANDLE mat_handle
;
3684 static D3DVERTEX quad
[] =
3686 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3687 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3688 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3689 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3691 static D3DLVERTEX lquad
[] =
3693 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3694 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3695 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3696 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3698 static D3DTLVERTEX tlquad
[] =
3700 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3701 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3702 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3703 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3707 D3DVERTEXTYPE vertextype
;
3709 DWORD d3drs_lighting
, d3drs_specular
;
3715 /* Lighting is enabled when D3DVT_VERTEX is used and D3DDP_DONOTLIGHT is not
3716 * set. D3DVT_VERTEX has diffuse = 0xffffffff and specular = 0x00000000, as
3717 * in later d3d versions */
3718 { D3DVT_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x0000ff00},
3719 { D3DVT_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
3720 { D3DVT_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3721 { D3DVT_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3722 { D3DVT_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x0000ff00},
3723 { D3DVT_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
3724 { D3DVT_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3725 { D3DVT_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3727 { D3DVT_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
3728 { D3DVT_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x00ff0000},
3729 { D3DVT_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3730 { D3DVT_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3731 { D3DVT_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
3732 { D3DVT_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x00ff8080},
3733 { D3DVT_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3734 { D3DVT_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3736 { D3DVT_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
3737 { D3DVT_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
3738 { D3DVT_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3739 { D3DVT_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3740 { D3DVT_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
3741 { D3DVT_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
3742 { D3DVT_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3743 { D3DVT_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3746 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3747 0, 0, 640, 480, 0, 0, 0, 0);
3748 ddraw
= create_ddraw();
3749 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3750 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3752 skip("Failed to create a 3D device, skipping test.\n");
3753 IDirectDraw2_Release(ddraw
);
3754 DestroyWindow(window
);
3758 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
3759 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3761 viewport
= create_viewport(device
, 0, 0, 640, 480);
3762 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
3763 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3765 emissive
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
3766 hr
= IDirect3DMaterial2_GetHandle(emissive
, device
, &mat_handle
);
3767 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
3768 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
3769 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
3770 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
3771 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
3773 background
= create_diffuse_material(device
, 0.1f
, 0.1f
, 0.1f
, 0.1f
);
3774 viewport_set_background(device
, viewport
, background
);
3776 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
3777 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
3778 ok(rs
== TRUE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected TRUE.\n", rs
);
3780 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
3782 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3783 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3785 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
3786 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
3787 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
3788 tests
[i
].d3drs_specular
);
3789 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
3791 hr
= IDirect3DDevice2_BeginScene(device
);
3792 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3793 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
3794 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
3795 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3796 hr
= IDirect3DDevice2_EndScene(device
);
3797 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3799 color
= get_surface_color(rt
, 320, 240);
3800 ok(compare_color(color
, tests
[i
].color
, 1),
3801 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3802 color
, tests
[i
].color
, i
);
3805 destroy_material(background
);
3806 destroy_material(emissive
);
3807 IDirectDrawSurface_Release(rt
);
3808 IDirect3DDevice2_Release(device
);
3809 ref
= IDirectDraw2_Release(ddraw
);
3810 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
3811 DestroyWindow(window
);
3817 IDirectDraw2
*ddraw
;
3820 } activateapp_testdata
;
3822 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
3824 if (message
== WM_ACTIVATEAPP
)
3826 if (activateapp_testdata
.ddraw
)
3829 activateapp_testdata
.received
= FALSE
;
3830 hr
= IDirectDraw2_SetCooperativeLevel(activateapp_testdata
.ddraw
,
3831 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
3832 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
3833 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3835 activateapp_testdata
.received
= TRUE
;
3838 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
3841 static void test_coop_level_activateapp(void)
3843 IDirectDraw2
*ddraw
;
3848 IDirectDrawSurface
*surface
;
3850 ddraw
= create_ddraw();
3851 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3853 wc
.lpfnWndProc
= activateapp_test_proc
;
3854 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
3855 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3857 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3858 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3860 /* Exclusive with window already active. */
3861 SetForegroundWindow(window
);
3862 activateapp_testdata
.received
= FALSE
;
3863 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3864 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3865 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
3866 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3867 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3869 /* Exclusive with window not active. */
3870 SetForegroundWindow(GetDesktopWindow());
3871 activateapp_testdata
.received
= FALSE
;
3872 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3873 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3874 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3875 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3876 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3878 /* Normal with window not active, then exclusive with the same window. */
3879 SetForegroundWindow(GetDesktopWindow());
3880 activateapp_testdata
.received
= FALSE
;
3881 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3882 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3883 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3884 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3885 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3886 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3887 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3888 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3890 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3891 SetForegroundWindow(GetDesktopWindow());
3892 activateapp_testdata
.received
= FALSE
;
3893 activateapp_testdata
.ddraw
= ddraw
;
3894 activateapp_testdata
.window
= window
;
3895 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
3896 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3897 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3898 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3899 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3900 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3902 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3903 * succeeding. Another switch to exclusive and back to normal is needed to release the
3904 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3905 * WM_ACTIVATEAPP messages. */
3906 activateapp_testdata
.ddraw
= NULL
;
3907 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3908 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3909 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3910 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3912 /* Setting DDSCL_NORMAL with recursive invocation. */
3913 SetForegroundWindow(GetDesktopWindow());
3914 activateapp_testdata
.received
= FALSE
;
3915 activateapp_testdata
.ddraw
= ddraw
;
3916 activateapp_testdata
.window
= window
;
3917 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
3918 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3919 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3920 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3922 /* DDraw is in exlusive mode now. */
3923 memset(&ddsd
, 0, sizeof(ddsd
));
3924 ddsd
.dwSize
= sizeof(ddsd
);
3925 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
3926 ddsd
.dwBackBufferCount
= 1;
3927 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
3928 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3929 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3930 IDirectDrawSurface_Release(surface
);
3932 /* Recover again, just to be sure. */
3933 activateapp_testdata
.ddraw
= NULL
;
3934 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3935 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3936 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3937 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3939 DestroyWindow(window
);
3940 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3941 IDirectDraw2_Release(ddraw
);
3944 struct format_support_check
3946 const DDPIXELFORMAT
*format
;
3950 static HRESULT WINAPI
test_unsupported_formats_cb(DDSURFACEDESC
*desc
, void *ctx
)
3952 struct format_support_check
*format
= ctx
;
3954 if (!memcmp(format
->format
, &desc
->ddpfPixelFormat
, sizeof(*format
->format
)))
3956 format
->supported
= TRUE
;
3957 return DDENUMRET_CANCEL
;
3960 return DDENUMRET_OK
;
3963 static void test_unsupported_formats(void)
3966 BOOL expect_success
;
3968 IDirectDraw2
*ddraw
;
3969 IDirect3DDevice2
*device
;
3970 IDirectDrawSurface
*surface
;
3973 DWORD expected_caps
;
3984 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
3985 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
3991 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
3992 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3996 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
3998 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3999 0, 0, 640, 480, 0, 0, 0, 0);
4000 ddraw
= create_ddraw();
4001 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4002 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4004 skip("Failed to create a 3D device, skipping test.\n");
4005 IDirectDraw2_Release(ddraw
);
4006 DestroyWindow(window
);
4010 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
4012 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
4013 hr
= IDirect3DDevice2_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
4014 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4016 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
4018 memset(&ddsd
, 0, sizeof(ddsd
));
4019 ddsd
.dwSize
= sizeof(ddsd
);
4020 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
4021 ddsd
.ddpfPixelFormat
= formats
[i
].fmt
;
4024 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
4026 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
4027 expect_success
= FALSE
;
4029 expect_success
= TRUE
;
4031 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4032 ok(SUCCEEDED(hr
) == expect_success
,
4033 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4034 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
4038 memset(&ddsd
, 0, sizeof(ddsd
));
4039 ddsd
.dwSize
= sizeof(ddsd
);
4040 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &ddsd
);
4041 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4043 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
4044 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4045 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
4046 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4047 else if (check
.supported
)
4048 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4050 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4052 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
4053 "Expected capability %#x, format %s, input cap %#x.\n",
4054 expected_caps
, formats
[i
].name
, caps
[j
]);
4056 IDirectDrawSurface_Release(surface
);
4060 IDirect3DDevice2_Release(device
);
4061 IDirectDraw2_Release(ddraw
);
4062 DestroyWindow(window
);
4065 static void test_rt_caps(void)
4067 PALETTEENTRY palette_entries
[256];
4068 IDirectDrawPalette
*palette
;
4069 IDirect3DDevice2
*device
;
4070 IDirectDraw2
*ddraw
;
4078 static const DDPIXELFORMAT p8_fmt
=
4080 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4081 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4086 const DDPIXELFORMAT
*pf
;
4089 HRESULT create_device_hr
;
4091 HRESULT alternative_set_rt_hr
;
4092 BOOL create_may_fail
;
4098 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4099 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4107 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4108 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4116 DDSCAPS_OFFSCREENPLAIN
,
4117 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4125 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4126 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4127 D3DERR_SURFACENOTINVIDMEM
,
4134 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4135 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4143 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4144 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4153 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4162 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4170 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4171 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4172 D3DERR_SURFACENOTINVIDMEM
,
4179 DDSCAPS_SYSTEMMEMORY
,
4180 DDSCAPS_SYSTEMMEMORY
,
4189 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4197 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4199 DDERR_NOPALETTEATTACHED
,
4206 DDSCAPS_OFFSCREENPLAIN
,
4207 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4215 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4216 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4217 DDERR_NOPALETTEATTACHED
,
4224 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4225 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4233 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
4234 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4236 DDERR_INVALIDPIXELFORMAT
,
4238 TRUE
/* AMD Evergreen */,
4242 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4243 ~0U /* AMD Evergreen */,
4245 DDERR_INVALIDPIXELFORMAT
,
4252 ~0U /* AMD Evergreen */,
4260 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4261 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4263 DDERR_INVALIDPIXELFORMAT
,
4264 DDERR_INVALIDPIXELFORMAT
,
4265 TRUE
/* Nvidia Kepler */,
4269 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4270 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4274 TRUE
/* Nvidia Kepler */,
4278 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4279 0, 0, 640, 480, 0, 0, 0, 0);
4280 ddraw
= create_ddraw();
4281 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4282 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4284 skip("Failed to create a 3D device, skipping test.\n");
4285 IDirectDraw2_Release(ddraw
);
4286 DestroyWindow(window
);
4289 z_depth
= get_device_z_depth(device
);
4290 ok(!!z_depth
, "Failed to get device z depth.\n");
4291 IDirect3DDevice2_Release(device
);
4293 if (FAILED(IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
)))
4295 skip("D3D interface is not available, skipping test.\n");
4299 memset(palette_entries
, 0, sizeof(palette_entries
));
4300 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
4301 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
4303 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4305 IDirectDrawSurface
*surface
, *rt
, *expected_rt
, *tmp
;
4306 DDSURFACEDESC surface_desc
;
4307 IDirect3DDevice2
*device
;
4309 memset(&surface_desc
, 0, sizeof(surface_desc
));
4310 surface_desc
.dwSize
= sizeof(surface_desc
);
4311 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4312 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4313 if (test_data
[i
].pf
)
4315 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4316 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
4318 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
4320 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4321 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
4323 surface_desc
.dwWidth
= 640;
4324 surface_desc
.dwHeight
= 480;
4325 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4326 ok(SUCCEEDED(hr
) || broken(test_data
[i
].create_may_fail
),
4327 "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4328 i
, test_data
[i
].caps_in
, hr
);
4332 memset(&surface_desc
, 0, sizeof(surface_desc
));
4333 surface_desc
.dwSize
= sizeof(surface_desc
);
4334 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4335 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4336 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
4337 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4338 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4340 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4341 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4342 i
, hr
, test_data
[i
].create_device_hr
);
4345 if (hr
== DDERR_NOPALETTEATTACHED
)
4347 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
4348 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
4349 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4350 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
4351 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4353 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4355 IDirectDrawSurface_Release(surface
);
4357 memset(&surface_desc
, 0, sizeof(surface_desc
));
4358 surface_desc
.dwSize
= sizeof(surface_desc
);
4359 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4360 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
4361 surface_desc
.dwWidth
= 640;
4362 surface_desc
.dwHeight
= 480;
4363 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4364 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
4366 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4367 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
4370 memset(&surface_desc
, 0, sizeof(surface_desc
));
4371 surface_desc
.dwSize
= sizeof(surface_desc
);
4372 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4373 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4374 if (test_data
[i
].pf
)
4376 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4377 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
4379 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
4381 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4382 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
4384 surface_desc
.dwWidth
= 640;
4385 surface_desc
.dwHeight
= 480;
4386 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
4387 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4388 i
, test_data
[i
].caps_in
, hr
);
4390 hr
= IDirect3DDevice2_SetRenderTarget(device
, rt
, 0);
4391 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
4392 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4393 i
, hr
, test_data
[i
].set_rt_hr
);
4394 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
4397 expected_rt
= surface
;
4399 /* It appears the surface is set as render target in this case, but no
4400 * reference is taken. */
4401 if (hr
== DDERR_INVALIDPIXELFORMAT
)
4403 refcount
= IDirectDrawSurface_AddRef(rt
);
4404 ok(refcount
== 2, "Test %u: Got unexpected refcount %u.\n", i
, refcount
);
4407 hr
= IDirect3DDevice2_GetRenderTarget(device
, &tmp
);
4408 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
4409 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
4411 IDirectDrawSurface_Release(tmp
);
4412 IDirectDrawSurface_Release(rt
);
4413 refcount
= IDirect3DDevice2_Release(device
);
4414 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
4415 refcount
= IDirectDrawSurface_Release(surface
);
4416 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
4419 IDirectDrawPalette_Release(palette
);
4420 IDirect3D2_Release(d3d
);
4423 refcount
= IDirectDraw2_Release(ddraw
);
4424 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4425 DestroyWindow(window
);
4428 static void test_primary_caps(void)
4430 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4431 IDirectDrawSurface
*surface
;
4432 DDSURFACEDESC surface_desc
;
4433 IDirectDraw2
*ddraw
;
4443 DWORD back_buffer_count
;
4451 DDSCAPS_PRIMARYSURFACE
,
4454 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
4458 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
4465 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
4472 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
4479 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
4486 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
4493 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4500 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4507 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4509 DDERR_NOEXCLUSIVEMODE
,
4513 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4514 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4520 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4521 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4524 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
4527 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4528 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
4534 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4535 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
4542 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4543 0, 0, 640, 480, 0, 0, 0, 0);
4544 ddraw
= create_ddraw();
4545 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4547 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4549 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
4550 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4552 memset(&surface_desc
, 0, sizeof(surface_desc
));
4553 surface_desc
.dwSize
= sizeof(surface_desc
);
4554 surface_desc
.dwFlags
= DDSD_CAPS
;
4555 if (test_data
[i
].back_buffer_count
!= ~0u)
4556 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4557 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4558 surface_desc
.dwBackBufferCount
= test_data
[i
].back_buffer_count
;
4559 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4560 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
4564 memset(&surface_desc
, 0, sizeof(surface_desc
));
4565 surface_desc
.dwSize
= sizeof(surface_desc
);
4566 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4567 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4568 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
4569 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4570 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4572 IDirectDrawSurface_Release(surface
);
4575 refcount
= IDirectDraw2_Release(ddraw
);
4576 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4577 DestroyWindow(window
);
4580 static void test_surface_lock(void)
4582 IDirectDraw2
*ddraw
;
4583 IDirectDrawSurface
*surface
;
4584 IDirect3DDevice2
*device
;
4599 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
4600 "videomemory offscreenplain"
4603 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4604 "systemmemory offscreenplain"
4607 DDSCAPS_PRIMARYSURFACE
,
4611 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
4612 "videomemory texture"
4615 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
4616 "systemmemory texture"
4619 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4628 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4629 0, 0, 640, 480, 0, 0, 0, 0);
4630 ddraw
= create_ddraw();
4631 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4632 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4634 skip("Failed to create a 3D device, skipping test.\n");
4635 IDirectDraw2_Release(ddraw
);
4636 DestroyWindow(window
);
4639 z_depth
= get_device_z_depth(device
);
4640 ok(!!z_depth
, "Failed to get device z depth.\n");
4641 IDirect3DDevice2_Release(device
);
4643 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4645 memset(&ddsd
, 0, sizeof(ddsd
));
4646 ddsd
.dwSize
= sizeof(ddsd
);
4647 ddsd
.dwFlags
= DDSD_CAPS
;
4648 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4650 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4654 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
4656 ddsd
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4657 U2(ddsd
).dwZBufferBitDepth
= z_depth
;
4659 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4661 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4662 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4664 memset(&ddsd
, 0, sizeof(ddsd
));
4665 ddsd
.dwSize
= sizeof(ddsd
);
4666 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4667 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4670 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4671 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4674 IDirectDrawSurface_Release(surface
);
4677 refcount
= IDirectDraw2_Release(ddraw
);
4678 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4679 DestroyWindow(window
);
4682 static void test_surface_discard(void)
4684 IDirectDraw2
*ddraw
;
4685 IDirect3DDevice2
*device
;
4689 IDirectDrawSurface
*surface
, *target
;
4698 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4699 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4700 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4701 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4705 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4706 0, 0, 640, 480, 0, 0, 0, 0);
4707 ddraw
= create_ddraw();
4708 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4709 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4711 skip("Failed to create a 3D device, skipping test.\n");
4712 DestroyWindow(window
);
4713 IDirectDraw2_Release(ddraw
);
4717 hr
= IDirect3DDevice2_GetRenderTarget(device
, &target
);
4718 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4720 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4724 memset(&ddsd
, 0, sizeof(ddsd
));
4725 ddsd
.dwSize
= sizeof(ddsd
);
4726 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4727 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4730 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4733 skip("Failed to create surface, skipping.\n");
4737 memset(&ddsd
, 0, sizeof(ddsd
));
4738 ddsd
.dwSize
= sizeof(ddsd
);
4739 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4740 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4741 addr
= ddsd
.lpSurface
;
4742 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4743 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4745 memset(&ddsd
, 0, sizeof(ddsd
));
4746 ddsd
.dwSize
= sizeof(ddsd
);
4747 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4748 ok(SUCCEEDED(hr
) , "Failed to lock surface, hr %#x.\n", hr
);
4749 discarded
= ddsd
.lpSurface
!= addr
;
4750 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4751 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4753 hr
= IDirectDrawSurface_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
4754 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
4756 memset(&ddsd
, 0, sizeof(ddsd
));
4757 ddsd
.dwSize
= sizeof(ddsd
);
4758 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4759 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4760 discarded
|= ddsd
.lpSurface
!= addr
;
4761 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4762 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4764 IDirectDrawSurface_Release(surface
);
4766 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4767 * AMD r500, evergreen). Windows XP, at least on AMD r200, never changes the pointer. */
4768 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
4771 IDirectDrawSurface_Release(target
);
4772 IDirect3DDevice2_Release(device
);
4773 IDirectDraw2_Release(ddraw
);
4774 DestroyWindow(window
);
4777 static void test_flip(void)
4779 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4780 IDirectDrawSurface
*primary
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
4781 DDSCAPS caps
= {DDSCAPS_FLIP
};
4782 DDSURFACEDESC surface_desc
;
4783 BOOL sysmem_primary
;
4784 IDirectDraw2
*ddraw
;
4791 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4792 0, 0, 640, 480, 0, 0, 0, 0);
4793 ddraw
= create_ddraw();
4794 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4796 hr
= set_display_mode(ddraw
, 640, 480);
4797 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
4798 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4799 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4801 memset(&surface_desc
, 0, sizeof(surface_desc
));
4802 surface_desc
.dwSize
= sizeof(surface_desc
);
4803 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4804 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4805 surface_desc
.dwBackBufferCount
= 3;
4806 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
4807 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4809 memset(&surface_desc
, 0, sizeof(surface_desc
));
4810 surface_desc
.dwSize
= sizeof(surface_desc
);
4811 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
4812 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4813 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
)
4814 == (DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
4815 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
4816 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
4818 hr
= IDirectDrawSurface_GetAttachedSurface(primary
, &caps
, &backbuffer1
);
4819 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4820 memset(&surface_desc
, 0, sizeof(surface_desc
));
4821 surface_desc
.dwSize
= sizeof(surface_desc
);
4822 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer1
, &surface_desc
);
4823 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4824 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
4825 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
| DDSCAPS_BACKBUFFER
),
4826 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
4828 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
4829 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4830 memset(&surface_desc
, 0, sizeof(surface_desc
));
4831 surface_desc
.dwSize
= sizeof(surface_desc
);
4832 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer2
, &surface_desc
);
4833 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4834 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
4835 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
4836 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
4838 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
4839 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4840 memset(&surface_desc
, 0, sizeof(surface_desc
));
4841 surface_desc
.dwSize
= sizeof(surface_desc
);
4842 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer3
, &surface_desc
);
4843 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4844 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
4845 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
4846 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
4848 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
4849 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4850 ok(surface
== primary
, "Got unexpected surface %p, expected %p.\n", surface
, primary
);
4851 IDirectDrawSurface_Release(surface
);
4853 memset(&surface_desc
, 0, sizeof(surface_desc
));
4854 surface_desc
.dwSize
= sizeof(surface_desc
);
4855 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4856 surface_desc
.ddsCaps
.dwCaps
= 0;
4857 surface_desc
.dwWidth
= 640;
4858 surface_desc
.dwHeight
= 480;
4859 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4860 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4861 hr
= IDirectDrawSurface_Flip(primary
, surface
, DDFLIP_WAIT
);
4862 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
4863 IDirectDrawSurface_Release(surface
);
4865 hr
= IDirectDrawSurface_Flip(primary
, primary
, DDFLIP_WAIT
);
4866 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
4867 hr
= IDirectDrawSurface_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
4868 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
4869 hr
= IDirectDrawSurface_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
4870 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
4871 hr
= IDirectDrawSurface_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
4872 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
4874 memset(&fx
, 0, sizeof(fx
));
4875 fx
.dwSize
= sizeof(fx
);
4876 U5(fx
).dwFillColor
= 0xffff0000;
4877 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4878 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4879 U5(fx
).dwFillColor
= 0xff00ff00;
4880 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4881 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4882 U5(fx
).dwFillColor
= 0xff0000ff;
4883 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4884 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4886 hr
= IDirectDrawSurface_Flip(primary
, NULL
, DDFLIP_WAIT
);
4887 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4888 color
= get_surface_color(backbuffer1
, 320, 240);
4889 /* The testbot seems to just copy the contents of one surface to all the
4890 * others, instead of properly flipping. */
4891 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
4892 "Got unexpected color 0x%08x.\n", color
);
4893 color
= get_surface_color(backbuffer2
, 320, 240);
4894 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
4895 U5(fx
).dwFillColor
= 0xffff0000;
4896 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4897 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4899 hr
= IDirectDrawSurface_Flip(primary
, NULL
, DDFLIP_WAIT
);
4900 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4901 color
= get_surface_color(backbuffer1
, 320, 240);
4902 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
4903 "Got unexpected color 0x%08x.\n", color
);
4904 color
= get_surface_color(backbuffer2
, 320, 240);
4905 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
4906 U5(fx
).dwFillColor
= 0xff00ff00;
4907 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4908 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4910 hr
= IDirectDrawSurface_Flip(primary
, NULL
, DDFLIP_WAIT
);
4911 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4912 color
= get_surface_color(backbuffer1
, 320, 240);
4913 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
4914 "Got unexpected color 0x%08x.\n", color
);
4915 color
= get_surface_color(backbuffer2
, 320, 240);
4916 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
4917 U5(fx
).dwFillColor
= 0xff0000ff;
4918 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4919 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4921 hr
= IDirectDrawSurface_Flip(primary
, backbuffer1
, DDFLIP_WAIT
);
4922 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4923 color
= get_surface_color(backbuffer2
, 320, 240);
4924 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
4925 "Got unexpected color 0x%08x.\n", color
);
4926 color
= get_surface_color(backbuffer3
, 320, 240);
4927 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
4928 U5(fx
).dwFillColor
= 0xffff0000;
4929 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4930 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4932 hr
= IDirectDrawSurface_Flip(primary
, backbuffer2
, DDFLIP_WAIT
);
4933 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4934 color
= get_surface_color(backbuffer1
, 320, 240);
4935 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
4936 color
= get_surface_color(backbuffer3
, 320, 240);
4937 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
4938 "Got unexpected color 0x%08x.\n", color
);
4939 U5(fx
).dwFillColor
= 0xff00ff00;
4940 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4941 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
4943 hr
= IDirectDrawSurface_Flip(primary
, backbuffer3
, DDFLIP_WAIT
);
4944 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
4945 color
= get_surface_color(backbuffer1
, 320, 240);
4946 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
4947 "Got unexpected color 0x%08x.\n", color
);
4948 color
= get_surface_color(backbuffer2
, 320, 240);
4949 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
4951 IDirectDrawSurface_Release(backbuffer3
);
4952 IDirectDrawSurface_Release(backbuffer2
);
4953 IDirectDrawSurface_Release(backbuffer1
);
4954 IDirectDrawSurface_Release(primary
);
4955 refcount
= IDirectDraw2_Release(ddraw
);
4956 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4957 DestroyWindow(window
);
4960 static void reset_ddsd(DDSURFACEDESC
*ddsd
)
4962 memset(ddsd
, 0, sizeof(*ddsd
));
4963 ddsd
->dwSize
= sizeof(*ddsd
);
4966 static void test_set_surface_desc(void)
4968 IDirectDraw2
*ddraw
;
4972 IDirectDrawSurface
*surface
;
4973 IDirectDrawSurface3
*surface3
;
4983 invalid_caps_tests
[] =
4985 {DDSCAPS_VIDEOMEMORY
, FALSE
, "videomemory plain"},
4986 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, TRUE
, "systemmemory texture"},
4987 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, FALSE
, "systemmemory primary"},
4990 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4991 0, 0, 640, 480, 0, 0, 0, 0);
4992 ddraw
= create_ddraw();
4993 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4994 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4995 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4998 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5001 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5002 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5003 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5004 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5005 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5006 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5007 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5009 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5010 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5012 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5013 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5014 IDirectDrawSurface_Release(surface
);
5017 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5018 ddsd
.lpSurface
= data
;
5019 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5020 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5022 /* Redundantly setting the same lpSurface is not an error. */
5023 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5024 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5025 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5026 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5027 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5028 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
5030 hr
= IDirectDrawSurface3_Lock(surface3
, NULL
, &ddsd
, 0, NULL
);
5031 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5032 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5033 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
5034 hr
= IDirectDrawSurface3_Unlock(surface3
, NULL
);
5035 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5038 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5039 ddsd
.lpSurface
= data
;
5040 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 1);
5041 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
5043 ddsd
.lpSurface
= NULL
;
5044 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5045 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
5047 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, NULL
, 0);
5048 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
5050 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5051 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5052 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5053 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5055 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5056 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5057 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
5059 ddsd
.dwFlags
= DDSD_CAPS
;
5060 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5061 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5063 /* dwCaps = 0 is allowed, but ignored. */
5064 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
5065 ddsd
.lpSurface
= data
;
5066 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5067 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5068 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5069 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5070 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5071 ddsd
.ddsCaps
.dwCaps
= 0;
5072 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5073 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5075 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5076 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5077 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5078 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5080 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5082 ddsd
.dwFlags
= DDSD_HEIGHT
;
5084 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5085 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
5087 ddsd
.lpSurface
= data
;
5088 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
5089 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5090 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5093 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5094 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
5097 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5098 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
5099 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5100 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5102 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
5104 ddsd
.dwFlags
= DDSD_PITCH
;
5105 U1(ddsd
).lPitch
= 8 * 4;
5106 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5107 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
5109 ddsd
.dwFlags
= DDSD_WIDTH
;
5111 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5112 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
5114 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
5115 ddsd
.lpSurface
= data
;
5116 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5117 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
5119 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
5120 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5121 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
5123 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5124 U1(ddsd
).lPitch
= 16 * 4;
5126 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5127 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5130 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5131 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5132 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5133 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5134 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
5136 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5138 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5139 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5140 U1(ddsd
).lPitch
= 4 * 4;
5141 ddsd
.lpSurface
= data
;
5142 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5143 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5145 U1(ddsd
).lPitch
= 4;
5146 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5147 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5149 U1(ddsd
).lPitch
= 16 * 4 + 1;
5150 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5151 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5153 U1(ddsd
).lPitch
= 16 * 4 + 3;
5154 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5155 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5157 U1(ddsd
).lPitch
= -4;
5158 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5159 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
5161 U1(ddsd
).lPitch
= 16 * 4;
5162 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5163 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5166 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5167 U1(ddsd
).lPitch
= 0;
5169 ddsd
.lpSurface
= data
;
5170 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5171 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
5173 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5174 U1(ddsd
).lPitch
= 16 * 4;
5176 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5177 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
5179 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5180 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
5181 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5182 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5183 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5184 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5185 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5186 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5187 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5188 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
5190 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
5191 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5192 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5194 /* Can't set color keys. */
5196 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
5197 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
5198 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
5199 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5200 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5202 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
5203 ddsd
.lpSurface
= data
;
5204 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5205 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5207 IDirectDrawSurface3_Release(surface3
);
5209 /* SetSurfaceDesc needs systemmemory surfaces.
5211 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5212 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
5215 ddsd
.dwFlags
= DDSD_CAPS
;
5216 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
5217 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5219 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5222 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5223 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5224 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5225 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5226 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5227 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5230 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5231 ok(SUCCEEDED(hr
) || hr
== DDERR_NODIRECTDRAWHW
, "Failed to create surface, hr %#x.\n", hr
);
5234 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5235 invalid_caps_tests
[i
].name
);
5238 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5239 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5240 IDirectDrawSurface_Release(surface
);
5243 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5244 ddsd
.lpSurface
= data
;
5245 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5246 if (invalid_caps_tests
[i
].supported
)
5248 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5252 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5253 invalid_caps_tests
[i
].name
, hr
);
5255 /* Check priority of error conditions. */
5256 ddsd
.dwFlags
= DDSD_WIDTH
;
5257 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5258 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5259 invalid_caps_tests
[i
].name
, hr
);
5262 IDirectDrawSurface3_Release(surface3
);
5266 ref
= IDirectDraw2_Release(ddraw
);
5267 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5268 DestroyWindow(window
);
5271 static void test_user_memory_getdc(void)
5273 IDirectDraw2
*ddraw
;
5277 IDirectDrawSurface
*surface
;
5278 IDirectDrawSurface3
*surface3
;
5284 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5285 0, 0, 640, 480, 0, 0, 0, 0);
5286 ddraw
= create_ddraw();
5287 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5289 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5290 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5293 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5296 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5297 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5298 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5299 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5300 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5301 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5302 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5303 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5304 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5306 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5307 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5308 IDirectDrawSurface_Release(surface
);
5310 memset(data
, 0xaa, sizeof(data
));
5312 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5313 ddsd
.lpSurface
= data
;
5314 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5315 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5317 hr
= IDirectDrawSurface3_GetDC(surface3
, &dc
);
5318 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5319 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
5320 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
5321 hr
= IDirectDrawSurface3_ReleaseDC(surface3
, dc
);
5322 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5324 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
5325 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
5327 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
5328 ddsd
.lpSurface
= data
;
5331 U1(ddsd
).lPitch
= sizeof(*data
);
5332 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5333 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5335 memset(data
, 0xaa, sizeof(data
));
5336 hr
= IDirectDrawSurface3_GetDC(surface3
, &dc
);
5337 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5338 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
5339 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
5340 hr
= IDirectDrawSurface3_ReleaseDC(surface3
, dc
);
5341 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5343 for (y
= 0; y
< 4; y
++)
5345 for (x
= 0; x
< 4; x
++)
5347 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
5348 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5351 ok(data
[y
][x
] == 0x00000000, "Expected color 0xaaaaaaaa on position %ux%u, got %#x.\n",
5355 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5357 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5359 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5361 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5364 IDirectDrawSurface3_Release(surface3
);
5365 ref
= IDirectDraw2_Release(ddraw
);
5366 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5367 DestroyWindow(window
);
5370 static void test_sysmem_overlay(void)
5372 IDirectDraw2
*ddraw
;
5376 IDirectDrawSurface
*surface
;
5379 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5380 0, 0, 640, 480, 0, 0, 0, 0);
5381 ddraw
= create_ddraw();
5382 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5384 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5385 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5388 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
5391 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
5392 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5393 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5394 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5395 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5396 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5397 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5398 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5399 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
5401 ref
= IDirectDraw2_Release(ddraw
);
5402 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5403 DestroyWindow(window
);
5406 static void test_primary_palette(void)
5408 DDSCAPS surface_caps
= {DDSCAPS_FLIP
};
5409 IDirectDrawSurface
*primary
, *backbuffer
;
5410 PALETTEENTRY palette_entries
[256];
5411 IDirectDrawPalette
*palette
, *tmp
;
5412 DDSURFACEDESC surface_desc
;
5413 IDirectDraw2
*ddraw
;
5419 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5420 0, 0, 640, 480, 0, 0, 0, 0);
5421 ddraw
= create_ddraw();
5422 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5423 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
5425 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5426 IDirectDraw2_Release(ddraw
);
5427 DestroyWindow(window
);
5430 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5431 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5433 memset(&surface_desc
, 0, sizeof(surface_desc
));
5434 surface_desc
.dwSize
= sizeof(surface_desc
);
5435 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
5436 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
5437 surface_desc
.dwBackBufferCount
= 1;
5438 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
5439 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5440 hr
= IDirectDrawSurface_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
5441 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5443 memset(palette_entries
, 0, sizeof(palette_entries
));
5444 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
5445 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5446 refcount
= get_refcount((IUnknown
*)palette
);
5447 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5449 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5450 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5451 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5453 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5454 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5456 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
5457 * and is generally somewhat broken with respect to 8 bpp / palette
5459 if (SUCCEEDED(IDirectDrawSurface_GetPalette(backbuffer
, &tmp
)))
5461 win_skip("Broken palette handling detected, skipping tests.\n");
5462 IDirectDrawPalette_Release(tmp
);
5463 IDirectDrawPalette_Release(palette
);
5464 /* The Windows 8 testbot keeps extra references to the primary and
5465 * backbuffer while in 8 bpp mode. */
5466 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
5467 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
5471 refcount
= get_refcount((IUnknown
*)palette
);
5472 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5474 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5475 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5476 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
5477 "Got unexpected palette caps %#x.\n", palette_caps
);
5479 hr
= IDirectDrawSurface_SetPalette(primary
, NULL
);
5480 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5481 refcount
= get_refcount((IUnknown
*)palette
);
5482 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5484 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5485 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5486 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5488 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5489 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5490 refcount
= get_refcount((IUnknown
*)palette
);
5491 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5493 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
5494 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
5495 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
5496 IDirectDrawPalette_Release(tmp
);
5497 hr
= IDirectDrawSurface_GetPalette(backbuffer
, &tmp
);
5498 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5500 refcount
= IDirectDrawPalette_Release(palette
);
5501 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5502 refcount
= IDirectDrawPalette_Release(palette
);
5503 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5505 /* Note that this only seems to work when the palette is attached to the
5506 * primary surface. When attached to a regular surface, attempting to get
5507 * the palette here will cause an access violation. */
5508 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
5509 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5512 refcount
= IDirectDrawSurface_Release(backbuffer
);
5513 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5514 refcount
= IDirectDrawSurface_Release(primary
);
5515 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5516 refcount
= IDirectDraw2_Release(ddraw
);
5517 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5518 DestroyWindow(window
);
5521 static HRESULT WINAPI
surface_counter(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
5523 UINT
*surface_count
= context
;
5526 IDirectDrawSurface_Release(surface
);
5528 return DDENUMRET_OK
;
5531 static void test_surface_attachment(void)
5533 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
5534 DDSCAPS caps
= {DDSCAPS_TEXTURE
};
5535 DDSURFACEDESC surface_desc
;
5536 IDirectDraw2
*ddraw
;
5542 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5543 0, 0, 640, 480, 0, 0, 0, 0);
5544 ddraw
= create_ddraw();
5545 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5546 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5547 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5549 memset(&surface_desc
, 0, sizeof(surface_desc
));
5550 surface_desc
.dwSize
= sizeof(surface_desc
);
5551 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
5552 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
5553 U2(surface_desc
).dwMipMapCount
= 3;
5554 surface_desc
.dwWidth
= 128;
5555 surface_desc
.dwHeight
= 128;
5556 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5557 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5559 hr
= IDirectDrawSurface_GetAttachedSurface(surface1
, &caps
, &surface2
);
5560 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5561 hr
= IDirectDrawSurface_GetAttachedSurface(surface2
, &caps
, &surface3
);
5562 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5563 hr
= IDirectDrawSurface_GetAttachedSurface(surface3
, &caps
, &surface4
);
5564 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5567 IDirectDrawSurface_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
5568 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5570 IDirectDrawSurface_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
5571 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5573 IDirectDrawSurface_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
5574 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
5576 memset(&surface_desc
, 0, sizeof(surface_desc
));
5577 surface_desc
.dwSize
= sizeof(surface_desc
);
5578 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5579 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
5580 surface_desc
.dwWidth
= 16;
5581 surface_desc
.dwHeight
= 16;
5582 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5583 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5585 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
5586 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5587 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5588 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5589 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
5590 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5591 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
5592 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5593 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
5594 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5595 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
5596 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5598 IDirectDrawSurface_Release(surface4
);
5600 memset(&surface_desc
, 0, sizeof(surface_desc
));
5601 surface_desc
.dwSize
= sizeof(surface_desc
);
5602 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5603 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5604 surface_desc
.dwWidth
= 16;
5605 surface_desc
.dwHeight
= 16;
5606 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5607 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5609 if (SUCCEEDED(hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
)))
5611 skip("Running on refrast, skipping some tests.\n");
5612 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface4
);
5613 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5617 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5618 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5619 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5620 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
5621 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5622 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
5623 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5624 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
5625 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5626 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
5627 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5630 IDirectDrawSurface_Release(surface4
);
5631 IDirectDrawSurface_Release(surface3
);
5632 IDirectDrawSurface_Release(surface2
);
5633 IDirectDrawSurface_Release(surface1
);
5635 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5636 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5638 /* Try a single primary and two offscreen plain surfaces. */
5639 memset(&surface_desc
, 0, sizeof(surface_desc
));
5640 surface_desc
.dwSize
= sizeof(surface_desc
);
5641 surface_desc
.dwFlags
= DDSD_CAPS
;
5642 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
5643 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5644 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5646 memset(&surface_desc
, 0, sizeof(surface_desc
));
5647 surface_desc
.dwSize
= sizeof(surface_desc
);
5648 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5649 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5650 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
5651 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
5652 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5653 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5655 memset(&surface_desc
, 0, sizeof(surface_desc
));
5656 surface_desc
.dwSize
= sizeof(surface_desc
);
5657 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5658 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5659 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
5660 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
5661 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5662 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5664 /* This one has a different size. */
5665 memset(&surface_desc
, 0, sizeof(surface_desc
));
5666 surface_desc
.dwSize
= sizeof(surface_desc
);
5667 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5668 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5669 surface_desc
.dwWidth
= 128;
5670 surface_desc
.dwHeight
= 128;
5671 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5672 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5674 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5675 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5676 /* Try the reverse without detaching first. */
5677 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
5678 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5679 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5680 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5682 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
5683 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5684 /* Try to detach reversed. */
5685 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5686 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5687 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
5688 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5690 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
);
5691 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5692 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
5693 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5695 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
5696 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5697 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5698 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5700 IDirectDrawSurface_Release(surface4
);
5701 IDirectDrawSurface_Release(surface3
);
5702 IDirectDrawSurface_Release(surface2
);
5703 IDirectDrawSurface_Release(surface1
);
5705 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
5706 memset(&surface_desc
, 0, sizeof(surface_desc
));
5707 surface_desc
.dwSize
= sizeof(surface_desc
);
5708 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5709 surface_desc
.dwWidth
= 64;
5710 surface_desc
.dwHeight
= 64;
5711 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5712 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5713 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
5714 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
5715 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
5716 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
5717 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
5718 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5719 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5720 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5721 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5723 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
5724 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
5725 U1(surface_desc
.ddpfPixelFormat
).dwZBufferBitDepth
= 16;
5726 U3(surface_desc
.ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
5727 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5728 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5730 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5731 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5732 refcount
= get_refcount((IUnknown
*)surface2
);
5733 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5734 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5735 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5737 /* Attaching while already attached to other surface. */
5738 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface2
);
5739 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5740 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface3
, 0, surface2
);
5741 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5742 IDirectDrawSurface_Release(surface3
);
5744 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5745 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5746 refcount
= get_refcount((IUnknown
*)surface2
);
5747 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5749 /* Automatic detachment on release. */
5750 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5751 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5752 refcount
= get_refcount((IUnknown
*)surface2
);
5753 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5754 refcount
= IDirectDrawSurface_Release(surface1
);
5755 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5756 refcount
= IDirectDrawSurface_Release(surface2
);
5757 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5758 refcount
= IDirectDraw2_Release(ddraw
);
5759 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5760 DestroyWindow(window
);
5763 static void test_pixel_format(void)
5765 HWND window
, window2
= NULL
;
5766 HDC hdc
, hdc2
= NULL
;
5768 int format
, test_format
;
5769 PIXELFORMATDESCRIPTOR pfd
;
5770 IDirectDraw2
*ddraw
= NULL
;
5771 IDirectDrawClipper
*clipper
= NULL
;
5773 IDirectDrawSurface
*primary
= NULL
;
5777 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
5778 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
5781 skip("Failed to create window\n");
5785 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
5786 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
5788 hdc
= GetDC(window
);
5791 skip("Failed to get DC\n");
5796 hdc2
= GetDC(window2
);
5798 gl
= LoadLibraryA("opengl32.dll");
5799 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
5801 format
= GetPixelFormat(hdc
);
5802 ok(format
== 0, "new window has pixel format %d\n", format
);
5804 ZeroMemory(&pfd
, sizeof(pfd
));
5805 pfd
.nSize
= sizeof(pfd
);
5807 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
5808 pfd
.iPixelType
= PFD_TYPE_RGBA
;
5809 pfd
.iLayerType
= PFD_MAIN_PLANE
;
5810 format
= ChoosePixelFormat(hdc
, &pfd
);
5813 skip("no pixel format available\n");
5817 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
5819 skip("failed to set pixel format\n");
5823 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
5825 skip("failed to set pixel format on second window\n");
5828 ReleaseDC(window2
, hdc2
);
5833 ddraw
= create_ddraw();
5834 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5836 test_format
= GetPixelFormat(hdc
);
5837 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5839 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5842 skip("Failed to set cooperative level, hr %#x.\n", hr
);
5846 test_format
= GetPixelFormat(hdc
);
5847 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5851 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
5852 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
5853 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
5854 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
5856 test_format
= GetPixelFormat(hdc
);
5857 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5859 test_format
= GetPixelFormat(hdc2
);
5860 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
5863 memset(&ddsd
, 0, sizeof(ddsd
));
5864 ddsd
.dwSize
= sizeof(ddsd
);
5865 ddsd
.dwFlags
= DDSD_CAPS
;
5866 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
5868 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
5869 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
5871 test_format
= GetPixelFormat(hdc
);
5872 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5876 test_format
= GetPixelFormat(hdc2
);
5877 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
5882 hr
= IDirectDrawSurface2_SetClipper(primary
, clipper
);
5883 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
5885 test_format
= GetPixelFormat(hdc
);
5886 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5888 test_format
= GetPixelFormat(hdc2
);
5889 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
5892 memset(&fx
, 0, sizeof(fx
));
5893 fx
.dwSize
= sizeof(fx
);
5894 hr
= IDirectDrawSurface2_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5895 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
5897 test_format
= GetPixelFormat(hdc
);
5898 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5902 test_format
= GetPixelFormat(hdc2
);
5903 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
5907 if (primary
) IDirectDrawSurface2_Release(primary
);
5908 if (clipper
) IDirectDrawClipper_Release(clipper
);
5909 if (ddraw
) IDirectDraw2_Release(ddraw
);
5910 if (gl
) FreeLibrary(gl
);
5911 if (hdc
) ReleaseDC(window
, hdc
);
5912 if (hdc2
) ReleaseDC(window2
, hdc2
);
5913 if (window
) DestroyWindow(window
);
5914 if (window2
) DestroyWindow(window2
);
5917 static void test_create_surface_pitch(void)
5919 IDirectDrawSurface
*surface
;
5920 DDSURFACEDESC surface_desc
;
5921 IDirectDraw2
*ddraw
;
5940 {DDSCAPS_VIDEOMEMORY
, 0, 0, DD_OK
,
5941 DDSD_PITCH
, 0x100, 0x100},
5942 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
5943 DDSD_PITCH
, 0x100, 0x100},
5944 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
5945 DDSD_PITCH
, 0x100, 0x100},
5946 {DDSCAPS_VIDEOMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
5948 {DDSCAPS_SYSTEMMEMORY
, 0, 0, DD_OK
,
5949 DDSD_PITCH
, 0x100, 0x0fc},
5950 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
5951 DDSD_PITCH
, 0x100, 0x0fc},
5952 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
5953 DDSD_PITCH
, 0x100, 0x0fc},
5954 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
5955 DDSD_PITCH
, 0x100, 0x0fc},
5956 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
5958 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
5961 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
5963 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5964 0, 0, 640, 480, 0, 0, 0, 0);
5965 ddraw
= create_ddraw();
5966 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5967 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5968 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5970 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
5972 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5974 memset(&surface_desc
, 0, sizeof(surface_desc
));
5975 surface_desc
.dwSize
= sizeof(surface_desc
);
5976 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
5977 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| test_data
[i
].placement
;
5978 surface_desc
.dwWidth
= 63;
5979 surface_desc
.dwHeight
= 63;
5980 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
5981 surface_desc
.lpSurface
= mem
;
5982 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5983 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5984 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5985 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5986 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5987 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5988 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5989 ok(hr
== test_data
[i
].hr
|| (test_data
[i
].placement
== DDSCAPS_VIDEOMEMORY
&& hr
== DDERR_NODIRECTDRAWHW
),
5990 "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
5994 memset(&surface_desc
, 0, sizeof(surface_desc
));
5995 surface_desc
.dwSize
= sizeof(surface_desc
);
5996 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
5997 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5998 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
5999 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6000 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
6001 if (sizeof(void *) != sizeof(DWORD
) && test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
6002 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
6003 "Test %u: Got unexpected pitch %u, expected %u.\n",
6004 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
6006 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
6007 "Test %u: Got unexpected pitch %u, expected %u.\n",
6008 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
6009 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
6011 IDirectDrawSurface_Release(surface
);
6014 HeapFree(GetProcessHeap(), 0, mem
);
6015 refcount
= IDirectDraw2_Release(ddraw
);
6016 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6017 DestroyWindow(window
);
6020 static void test_mipmap_lock(void)
6022 IDirectDrawSurface
*surface1
;
6023 IDirectDrawSurface2
*surface
, *surface2
;
6024 DDSURFACEDESC surface_desc
;
6025 IDirectDraw2
*ddraw
;
6029 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
6032 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6033 0, 0, 640, 480, 0, 0, 0, 0);
6034 ddraw
= create_ddraw();
6035 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6036 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6037 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6039 memset(&hal_caps
, 0, sizeof(hal_caps
));
6040 hal_caps
.dwSize
= sizeof(hal_caps
);
6041 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
6042 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6043 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6045 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
6046 IDirectDraw2_Release(ddraw
);
6047 DestroyWindow(window
);
6051 memset(&surface_desc
, 0, sizeof(surface_desc
));
6052 surface_desc
.dwSize
= sizeof(surface_desc
);
6053 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
6054 surface_desc
.dwWidth
= 4;
6055 surface_desc
.dwHeight
= 4;
6056 U2(surface_desc
).dwMipMapCount
= 2;
6057 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
6058 | DDSCAPS_SYSTEMMEMORY
;
6059 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6060 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6062 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
6063 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
6064 IDirectDrawSurface_Release(surface1
);
6065 hr
= IDirectDrawSurface2_GetAttachedSurface(surface
, &caps
, &surface2
);
6066 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6068 memset(&surface_desc
, 0, sizeof(surface_desc
));
6069 surface_desc
.dwSize
= sizeof(surface_desc
);
6070 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
6071 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6072 memset(&surface_desc
, 0, sizeof(surface_desc
));
6073 surface_desc
.dwSize
= sizeof(surface_desc
);
6074 hr
= IDirectDrawSurface2_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
6075 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6076 IDirectDrawSurface2_Unlock(surface2
, NULL
);
6077 IDirectDrawSurface2_Unlock(surface
, NULL
);
6079 IDirectDrawSurface2_Release(surface2
);
6080 IDirectDrawSurface2_Release(surface
);
6081 refcount
= IDirectDraw2_Release(ddraw
);
6082 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6083 DestroyWindow(window
);
6086 static void test_palette_complex(void)
6088 IDirectDrawSurface
*surface1
;
6089 IDirectDrawSurface2
*surface
, *mipmap
, *tmp
;
6090 DDSURFACEDESC surface_desc
;
6091 IDirectDraw2
*ddraw
;
6092 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
6096 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
6098 PALETTEENTRY palette_entries
[256];
6104 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6105 0, 0, 640, 480, 0, 0, 0, 0);
6106 ddraw
= create_ddraw();
6107 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6108 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6109 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6111 memset(&hal_caps
, 0, sizeof(hal_caps
));
6112 hal_caps
.dwSize
= sizeof(hal_caps
);
6113 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
6114 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6115 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6117 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
6118 IDirectDraw2_Release(ddraw
);
6119 DestroyWindow(window
);
6123 memset(&surface_desc
, 0, sizeof(surface_desc
));
6124 surface_desc
.dwSize
= sizeof(surface_desc
);
6125 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6126 surface_desc
.dwWidth
= 128;
6127 surface_desc
.dwHeight
= 128;
6128 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6129 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6130 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6131 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6132 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6133 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6134 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
6135 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
6136 IDirectDrawSurface_Release(surface1
);
6138 memset(palette_entries
, 0, sizeof(palette_entries
));
6139 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6140 palette_entries
, &palette
, NULL
);
6141 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6143 memset(palette_entries
, 0, sizeof(palette_entries
));
6144 palette_entries
[1].peRed
= 0xff;
6145 palette_entries
[1].peGreen
= 0x80;
6146 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6147 palette_entries
, &palette_mipmap
, NULL
);
6148 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6150 palette2
= (void *)0xdeadbeef;
6151 hr
= IDirectDrawSurface2_GetPalette(surface
, &palette2
);
6152 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6153 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
6154 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
6155 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6156 hr
= IDirectDrawSurface2_GetPalette(surface
, &palette2
);
6157 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6158 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
6159 IDirectDrawPalette_Release(palette2
);
6162 IDirectDrawSurface2_AddRef(mipmap
);
6163 for (i
= 0; i
< 7; ++i
)
6165 hr
= IDirectDrawSurface2_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6166 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
6167 palette2
= (void *)0xdeadbeef;
6168 hr
= IDirectDrawSurface2_GetPalette(tmp
, &palette2
);
6169 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
6170 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
6172 hr
= IDirectDrawSurface2_SetPalette(tmp
, palette_mipmap
);
6173 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
6175 hr
= IDirectDrawSurface2_GetPalette(tmp
, &palette2
);
6176 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
6177 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
6178 IDirectDrawPalette_Release(palette2
);
6180 hr
= IDirectDrawSurface2_GetDC(tmp
, &dc
);
6181 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
6182 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
6183 ok(count
== 1, "Expected count 1, got %u.\n", count
);
6184 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
6185 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
6186 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
6187 hr
= IDirectDrawSurface2_ReleaseDC(tmp
, dc
);
6188 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
6190 IDirectDrawSurface2_Release(mipmap
);
6194 hr
= IDirectDrawSurface2_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6195 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6196 IDirectDrawSurface2_Release(mipmap
);
6197 refcount
= IDirectDrawSurface2_Release(surface
);
6198 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6199 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
6200 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6201 refcount
= IDirectDrawPalette_Release(palette
);
6202 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6204 refcount
= IDirectDraw2_Release(ddraw
);
6205 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6206 DestroyWindow(window
);
6209 static void test_p8_rgb_blit(void)
6211 IDirectDrawSurface
*src
, *dst
;
6212 DDSURFACEDESC surface_desc
;
6213 IDirectDraw2
*ddraw
;
6214 IDirectDrawPalette
*palette
;
6218 PALETTEENTRY palette_entries
[256];
6220 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
6221 static const D3DCOLOR expected
[] =
6223 0x00101010, 0x00010101, 0x00020202, 0x00030303,
6224 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
6228 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6229 0, 0, 640, 480, 0, 0, 0, 0);
6230 ddraw
= create_ddraw();
6231 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6232 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6233 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6235 memset(palette_entries
, 0, sizeof(palette_entries
));
6236 palette_entries
[1].peGreen
= 0xff;
6237 palette_entries
[2].peBlue
= 0xff;
6238 palette_entries
[3].peFlags
= 0xff;
6239 palette_entries
[4].peRed
= 0xff;
6240 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6241 palette_entries
, &palette
, NULL
);
6242 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6244 memset(&surface_desc
, 0, sizeof(surface_desc
));
6245 surface_desc
.dwSize
= sizeof(surface_desc
);
6246 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6247 surface_desc
.dwWidth
= 8;
6248 surface_desc
.dwHeight
= 1;
6249 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6250 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6251 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6252 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6253 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
6254 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6256 memset(&surface_desc
, 0, sizeof(surface_desc
));
6257 surface_desc
.dwSize
= sizeof(surface_desc
);
6258 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6259 surface_desc
.dwWidth
= 8;
6260 surface_desc
.dwHeight
= 1;
6261 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6262 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6263 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6264 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6265 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6266 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6267 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6268 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6269 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
6270 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6272 memset(&surface_desc
, 0, sizeof(surface_desc
));
6273 surface_desc
.dwSize
= sizeof(surface_desc
);
6274 hr
= IDirectDrawSurface_Lock(src
, NULL
, &surface_desc
, 0, NULL
);
6275 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
6276 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
6277 hr
= IDirectDrawSurface_Unlock(src
, NULL
);
6278 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
6280 hr
= IDirectDrawSurface_SetPalette(src
, palette
);
6281 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6282 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
6283 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
6284 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
6285 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
6286 "Failed to blit, hr %#x.\n", hr
);
6290 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
6292 color
= get_surface_color(dst
, x
, 0);
6293 todo_wine
ok(compare_color(color
, expected
[x
], 0),
6294 "Pixel %u: Got color %#x, expected %#x.\n",
6295 x
, color
, expected
[x
]);
6299 IDirectDrawSurface_Release(src
);
6300 IDirectDrawSurface_Release(dst
);
6301 IDirectDrawPalette_Release(palette
);
6303 refcount
= IDirectDraw2_Release(ddraw
);
6304 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6305 DestroyWindow(window
);
6308 static void test_material(void)
6310 IDirect3DMaterial2
*background
, *material
;
6311 D3DMATERIALHANDLE mat_handle
, tmp
;
6312 IDirect3DViewport2
*viewport
;
6313 IDirect3DDevice2
*device
;
6314 IDirectDrawSurface
*rt
;
6315 IDirectDraw2
*ddraw
;
6323 static D3DVERTEX quad
[] =
6325 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6326 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6327 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6328 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6333 D3DCOLOR expected_color
;
6338 {FALSE
, 0x00ffffff},
6340 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6342 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6343 0, 0, 640, 480, 0, 0, 0, 0);
6344 ddraw
= create_ddraw();
6345 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6346 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6348 skip("Failed to create a 3D device, skipping test.\n");
6349 DestroyWindow(window
);
6353 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6354 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6356 background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
6357 viewport
= create_viewport(device
, 0, 0, 640, 480);
6358 viewport_set_background(device
, viewport
, background
);
6359 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6360 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6362 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
6363 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6364 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6366 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6367 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6368 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6369 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6370 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6371 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6372 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6373 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6374 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, 0);
6375 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6376 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6377 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6378 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6380 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6382 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
6383 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6385 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
6386 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6388 hr
= IDirect3DDevice2_BeginScene(device
);
6389 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6390 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_VERTEX
, quad
, 4, 0);
6391 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6392 hr
= IDirect3DDevice2_EndScene(device
);
6393 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6394 color
= get_surface_color(rt
, 320, 240);
6395 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
6396 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
6399 destroy_material(material
);
6400 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
6401 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6402 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6404 hr
= IDirect3DViewport2_SetBackground(viewport
, mat_handle
);
6405 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
6406 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6407 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6408 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6409 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6410 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6411 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6412 color
= get_surface_color(rt
, 320, 240);
6413 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6415 hr
= IDirect3DViewport2_SetBackground(viewport
, 0);
6416 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6417 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6418 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6419 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6420 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6421 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6422 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6423 color
= get_surface_color(rt
, 320, 240);
6424 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6426 destroy_viewport(device
, viewport
);
6427 viewport
= create_viewport(device
, 0, 0, 640, 480);
6429 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6430 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6431 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6432 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
6433 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6434 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6435 color
= get_surface_color(rt
, 320, 240);
6436 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
6438 destroy_viewport(device
, viewport
);
6439 destroy_material(background
);
6440 destroy_material(material
);
6441 IDirectDrawSurface_Release(rt
);
6442 refcount
= IDirect3DDevice2_Release(device
);
6443 ok(!refcount
, "Device has %u references left.\n", refcount
);
6444 refcount
= IDirectDraw2_Release(ddraw
);
6445 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
6446 DestroyWindow(window
);
6449 static void test_lighting(void)
6451 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6452 static D3DMATRIX mat
=
6454 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6455 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6456 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6457 0.0f
, 0.0f
, 0.0f
, 1.0f
,
6461 1.0f
, 0.0f
, 1.0f
, 0.0f
,
6462 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6463 1.0f
, 0.0f
, 1.0f
, 0.0f
,
6464 0.0f
, 0.0f
, 0.5f
, 1.0f
,
6468 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6469 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6470 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
6471 10.f
, 10.0f
, 10.0f
, 1.0f
,
6475 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6476 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6477 0.0f
, 0.0f
, 1.0f
, -1.0f
,
6478 10.f
, 10.0f
, 10.0f
, 0.0f
,
6480 static D3DLVERTEX unlitquad
[] =
6482 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6483 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6484 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6485 {{ 0.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6489 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6490 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6491 {{ 0.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6492 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6494 static D3DVERTEX unlitnquad
[] =
6496 {{0.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6497 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6498 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6499 {{1.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6503 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6504 {{0.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6505 {{1.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6506 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6510 {{-1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6511 {{-1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6512 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6513 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6517 {{-10.0f
}, {-11.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6518 {{-10.0f
}, { -9.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6519 {{-10.0f
}, { -9.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6520 {{-10.0f
}, {-11.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6524 {{-11.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6525 {{-11.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6526 {{ -9.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6527 {{ -9.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6529 static WORD indices
[] = {0, 1, 2, 2, 3, 0};
6532 D3DMATRIX
*world_matrix
;
6535 const char *message
;
6539 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
6540 {&mat_singular
, nquad
, 0x000000b4, "Lit quad with singular world matrix"},
6541 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
6542 {&mat_nonaffine
, translatedquad
, 0x000000ff, "Lit quad with non-affine matrix"},
6547 IDirect3DDevice2
*device
;
6548 IDirectDraw2
*ddraw
;
6549 IDirectDrawSurface
*rt
;
6550 IDirect3DViewport2
*viewport
;
6551 IDirect3DMaterial2
*material
;
6552 IDirect3DLight
*light
;
6553 D3DMATERIALHANDLE mat_handle
;
6554 D3DLIGHT2 light_desc
;
6560 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6561 0, 0, 640, 480, 0, 0, 0, 0);
6562 ddraw
= create_ddraw();
6563 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6564 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6566 skip("Failed to create a 3D device, skipping test.\n");
6567 DestroyWindow(window
);
6571 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
6572 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
6574 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6575 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6577 viewport
= create_viewport(device
, 0, 0, 640, 480);
6578 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6579 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6581 material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
6582 viewport_set_background(device
, viewport
, material
);
6584 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6585 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6587 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
6588 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
6589 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
6590 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
6591 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
6592 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
6593 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
6594 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
6595 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
6596 ok(SUCCEEDED(hr
), "Failed to disable zbuffer, hr %#x.\n", hr
);
6597 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
6598 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
6599 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
6600 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
6602 hr
= IDirect3DDevice2_BeginScene(device
);
6603 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6605 /* There is no D3DRENDERSTATE_LIGHTING on ddraw < 7. */
6606 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
6607 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6608 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_LVERTEX
, unlitquad
,
6610 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6612 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
6613 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
6614 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_LVERTEX
, litquad
,
6616 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6618 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
6619 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6620 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, unlitnquad
,
6622 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6624 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
6625 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6626 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, litnquad
,
6628 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6630 hr
= IDirect3DDevice2_EndScene(device
);
6631 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6633 color
= get_surface_color(rt
, 160, 360);
6634 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color
);
6635 color
= get_surface_color(rt
, 160, 120);
6636 ok(color
== 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color
);
6637 color
= get_surface_color(rt
, 480, 360);
6638 ok(color
== 0x00ffffff, "Unlit quad with normals has color 0x%08x.\n", color
);
6639 color
= get_surface_color(rt
, 480, 120);
6640 ok(color
== 0x00ffffff, "Lit quad with normals has color 0x%08x.\n", color
);
6642 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6643 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6644 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6645 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6647 hr
= IDirect3D2_CreateLight(d3d
, &light
, NULL
);
6648 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
6649 memset(&light_desc
, 0, sizeof(light_desc
));
6650 light_desc
.dwSize
= sizeof(light_desc
);
6651 light_desc
.dltType
= D3DLIGHT_DIRECTIONAL
;
6652 U1(light_desc
.dcvColor
).r
= 0.0f
;
6653 U2(light_desc
.dcvColor
).g
= 0.0f
;
6654 U3(light_desc
.dcvColor
).b
= 1.0f
;
6655 U4(light_desc
.dcvColor
).a
= 1.0f
;
6656 U3(light_desc
.dvDirection
).z
= 1.0f
;
6657 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
6658 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
6659 hr
= IDirect3DViewport2_AddLight(viewport
, light
);
6660 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
6662 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6663 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6665 hr
= IDirect3DDevice2_BeginScene(device
);
6666 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6668 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, nquad
,
6670 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6672 hr
= IDirect3DDevice2_EndScene(device
);
6673 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6675 color
= get_surface_color(rt
, 320, 240);
6676 ok(color
== 0x00000000, "Lit quad with no light has color 0x%08x.\n", color
);
6678 light_desc
.dwFlags
= D3DLIGHT_ACTIVE
;
6679 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
6680 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
6682 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
6684 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, tests
[i
].world_matrix
);
6685 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
6687 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6688 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6690 hr
= IDirect3DDevice2_BeginScene(device
);
6691 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6693 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
,
6694 tests
[i
].quad
, 4, indices
, 6, 0);
6695 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6697 hr
= IDirect3DDevice2_EndScene(device
);
6698 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6700 color
= get_surface_color(rt
, 320, 240);
6701 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
6704 hr
= IDirect3DViewport2_DeleteLight(viewport
, light
);
6705 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
6706 IDirect3DLight_Release(light
);
6707 destroy_material(material
);
6708 destroy_viewport(device
, viewport
);
6709 IDirectDrawSurface2_Release(rt
);
6710 refcount
= IDirect3DDevice2_Release(device
);
6711 ok(!refcount
, "Device has %u references left.\n", refcount
);
6712 IDirect3D2_Release(d3d
);
6713 refcount
= IDirectDraw2_Release(ddraw
);
6714 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
6715 DestroyWindow(window
);
6718 static void test_specular_lighting(void)
6720 static const unsigned int vertices_side
= 5;
6721 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
6722 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6723 static D3DMATRIX mat
=
6725 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6726 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6727 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6728 0.0f
, 0.0f
, 0.0f
, 1.0f
,
6730 static D3DLIGHT2 directional
=
6733 D3DLIGHT_DIRECTIONAL
,
6734 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
6735 {{0.0f
}, {0.0f
}, {0.0f
}},
6736 {{0.0f
}, {0.0f
}, {1.0f
}},
6742 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
6743 {{0.0f
}, {0.0f
}, {0.0f
}},
6744 {{0.0f
}, {0.0f
}, {0.0f
}},
6753 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
6754 {{0.0f
}, {0.0f
}, {0.0f
}},
6755 {{0.0f
}, {0.0f
}, {1.0f
}},
6759 M_PI
/ 12.0f
, M_PI
/ 3.0f
6764 D3DLIGHT_PARALLELPOINT
,
6765 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
6766 {{0.5f
}, {0.0f
}, {-1.0f
}},
6767 {{0.0f
}, {0.0f
}, {0.0f
}},
6769 static const struct expected_color
6774 expected_directional_local
[] =
6776 {160, 120, 0x003c3c3c},
6777 {320, 120, 0x00717171},
6778 {480, 120, 0x003c3c3c},
6779 {160, 240, 0x00717171},
6780 {320, 240, 0x00ffffff},
6781 {480, 240, 0x00717171},
6782 {160, 360, 0x003c3c3c},
6783 {320, 360, 0x00717171},
6784 {480, 360, 0x003c3c3c},
6786 expected_point_local
[] =
6788 {160, 120, 0x00000000},
6789 {320, 120, 0x00090909},
6790 {480, 120, 0x00000000},
6791 {160, 240, 0x00090909},
6792 {320, 240, 0x00fafafa},
6793 {480, 240, 0x00090909},
6794 {160, 360, 0x00000000},
6795 {320, 360, 0x00090909},
6796 {480, 360, 0x00000000},
6798 expected_spot_local
[] =
6800 {160, 120, 0x00000000},
6801 {320, 120, 0x00020202},
6802 {480, 120, 0x00000000},
6803 {160, 240, 0x00020202},
6804 {320, 240, 0x00fafafa},
6805 {480, 240, 0x00020202},
6806 {160, 360, 0x00000000},
6807 {320, 360, 0x00020202},
6808 {480, 360, 0x00000000},
6810 expected_parallelpoint
[] =
6812 {160, 120, 0x00050505},
6813 {320, 120, 0x002c2c2c},
6814 {480, 120, 0x006e6e6e},
6815 {160, 240, 0x00090909},
6816 {320, 240, 0x00717171},
6817 {480, 240, 0x00ffffff},
6818 {160, 360, 0x00050505},
6819 {320, 360, 0x002c2c2c},
6820 {480, 360, 0x006e6e6e},
6825 const struct expected_color
*expected
;
6826 unsigned int expected_count
;
6830 {&directional
, expected_directional_local
,
6831 sizeof(expected_directional_local
) / sizeof(expected_directional_local
[0])},
6832 {&point
, expected_point_local
,
6833 sizeof(expected_point_local
) / sizeof(expected_point_local
[0])},
6834 {&spot
, expected_spot_local
,
6835 sizeof(expected_spot_local
) / sizeof(expected_spot_local
[0])},
6836 {¶llelpoint
, expected_parallelpoint
,
6837 sizeof(expected_parallelpoint
) / sizeof(expected_parallelpoint
[0])},
6840 IDirect3DDevice2
*device
;
6841 IDirectDraw2
*ddraw
;
6842 IDirectDrawSurface
*rt
;
6843 IDirect3DViewport2
*viewport
;
6844 IDirect3DMaterial2
*material
, *background_material
;
6845 IDirect3DLight
*light
;
6846 D3DMATERIALHANDLE mat_handle
;
6851 unsigned int i
, j
, x
, y
;
6855 quad
= HeapAlloc(GetProcessHeap(), 0, vertices_side
* vertices_side
* sizeof(*quad
));
6856 indices
= HeapAlloc(GetProcessHeap(), 0, indices_count
* sizeof(*indices
));
6857 for (i
= 0, y
= 0; y
< vertices_side
; ++y
)
6859 for (x
= 0; x
< vertices_side
; ++x
)
6861 U1(quad
[i
]).x
= x
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
6862 U2(quad
[i
]).y
= y
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
6863 U3(quad
[i
]).z
= 1.0f
;
6864 U4(quad
[i
]).nx
= 0.0f
;
6865 U5(quad
[i
]).ny
= 0.0f
;
6866 U6(quad
[i
]).nz
= -1.0f
;
6867 U7(quad
[i
]).tu
= 0.0f
;
6868 U8(quad
[i
++]).tv
= 0.0f
;
6871 for (i
= 0, y
= 0; y
< (vertices_side
- 1); ++y
)
6873 for (x
= 0; x
< (vertices_side
- 1); ++x
)
6875 indices
[i
++] = y
* vertices_side
+ x
+ 1;
6876 indices
[i
++] = y
* vertices_side
+ x
;
6877 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
6878 indices
[i
++] = y
* vertices_side
+ x
+ 1;
6879 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
6880 indices
[i
++] = (y
+ 1) * vertices_side
+ x
+ 1;
6884 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6885 0, 0, 640, 480, 0, 0, 0, 0);
6886 ddraw
= create_ddraw();
6887 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6888 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6890 skip("Failed to create a 3D device, skipping test.\n");
6891 DestroyWindow(window
);
6895 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
6896 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
6898 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6899 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6901 viewport
= create_viewport(device
, 0, 0, 640, 480);
6902 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6903 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6905 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
6906 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
6907 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
6908 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
6909 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
6910 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
6911 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
6912 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
6913 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
6914 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
6915 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
6916 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
6918 background_material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
6919 viewport_set_background(device
, viewport
, background_material
);
6921 material
= create_specular_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 30.0f
);
6922 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6923 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6924 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6925 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6927 hr
= IDirect3D2_CreateLight(d3d
, &light
, NULL
);
6928 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
6929 hr
= IDirect3DViewport2_AddLight(viewport
, light
);
6930 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
6932 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, TRUE
);
6933 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
6935 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
6937 tests
[i
].light
->dwFlags
= D3DLIGHT_ACTIVE
;
6938 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)tests
[i
].light
);
6939 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
6941 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6942 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6944 hr
= IDirect3DDevice2_BeginScene(device
);
6945 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6947 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
,
6948 quad
, vertices_side
* vertices_side
, indices
, indices_count
, 0);
6949 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6951 hr
= IDirect3DDevice2_EndScene(device
);
6952 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6954 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
6956 color
= get_surface_color(rt
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
6957 ok(compare_color(color
, tests
[i
].expected
[j
].color
, 1),
6958 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
6959 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
6960 tests
[i
].expected
[j
].y
, color
, i
);
6964 hr
= IDirect3DViewport2_DeleteLight(viewport
, light
);
6965 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
6966 IDirect3DLight_Release(light
);
6967 destroy_material(material
);
6968 destroy_material(background_material
);
6969 destroy_viewport(device
, viewport
);
6970 IDirectDrawSurface2_Release(rt
);
6971 refcount
= IDirect3DDevice2_Release(device
);
6972 ok(!refcount
, "Device has %u references left.\n", refcount
);
6973 IDirect3D2_Release(d3d
);
6974 refcount
= IDirectDraw2_Release(ddraw
);
6975 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
6976 DestroyWindow(window
);
6977 HeapFree(GetProcessHeap(), 0, indices
);
6978 HeapFree(GetProcessHeap(), 0, quad
);
6981 static void test_palette_gdi(void)
6983 IDirectDrawSurface
*surface
, *primary
;
6984 DDSURFACEDESC surface_desc
;
6985 IDirectDraw2
*ddraw
;
6986 IDirectDrawPalette
*palette
, *palette2
;
6990 PALETTEENTRY palette_entries
[256];
6993 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
6994 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
6995 * not the point of this test. */
6996 static const RGBQUAD expected1
[] =
6998 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
6999 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7001 static const RGBQUAD expected2
[] =
7003 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7004 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7006 static const RGBQUAD expected3
[] =
7008 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7009 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7011 HPALETTE ddraw_palette_handle
;
7012 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7013 RGBQUAD rgbquad
[255];
7014 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
7016 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7017 0, 0, 640, 480, 0, 0, 0, 0);
7018 ddraw
= create_ddraw();
7019 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7020 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7021 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7023 memset(&surface_desc
, 0, sizeof(surface_desc
));
7024 surface_desc
.dwSize
= sizeof(surface_desc
);
7025 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7026 surface_desc
.dwWidth
= 16;
7027 surface_desc
.dwHeight
= 16;
7028 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7029 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7030 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7031 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
7032 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7033 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7035 /* Avoid colors from the Windows default palette. */
7036 memset(palette_entries
, 0, sizeof(palette_entries
));
7037 palette_entries
[1].peRed
= 0x01;
7038 palette_entries
[2].peGreen
= 0x02;
7039 palette_entries
[3].peBlue
= 0x03;
7040 palette_entries
[4].peRed
= 0x13;
7041 palette_entries
[4].peGreen
= 0x14;
7042 palette_entries
[4].peBlue
= 0x15;
7043 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7044 palette_entries
, &palette
, NULL
);
7045 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7047 /* If there is no palette assigned and the display mode is not 8 bpp, some
7048 * drivers refuse to create a DC while others allow it. If a DC is created,
7049 * the DIB color table is uninitialized and contains random colors. No error
7050 * is generated when trying to read pixels and random garbage is returned.
7052 * The most likely explanation is that if the driver creates a DC, it (or
7053 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7054 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7055 * contains uninitialized garbage. See comments below for the P8 case. */
7057 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
7058 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7059 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7060 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7061 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7062 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7063 "Got unexpected palette %p, expected %p.\n",
7064 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7066 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7067 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7068 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
7070 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
7071 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7072 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7073 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
7075 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7077 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7078 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7079 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7082 /* Update the palette while the DC is in use. This does not modify the DC. */
7083 palette_entries
[4].peRed
= 0x23;
7084 palette_entries
[4].peGreen
= 0x24;
7085 palette_entries
[4].peBlue
= 0x25;
7086 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
7087 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
7089 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7090 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7091 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7092 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7093 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7094 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7096 /* Neither does re-setting the palette. */
7097 hr
= IDirectDrawSurface_SetPalette(surface
, NULL
);
7098 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7099 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
7100 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7102 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7103 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7104 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7105 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7106 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7107 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7109 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7110 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7112 /* Refresh the DC. This updates the palette. */
7113 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7114 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7115 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7116 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7117 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7119 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7120 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7121 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7122 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7124 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7126 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7127 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7128 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7130 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7131 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7133 refcount
= IDirectDrawSurface_Release(surface
);
7134 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7136 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7138 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7139 IDirectDrawPalette_Release(palette
);
7140 IDirectDraw2_Release(ddraw
);
7141 DestroyWindow(window
);
7144 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
7145 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
7146 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7148 memset(&surface_desc
, 0, sizeof(surface_desc
));
7149 surface_desc
.dwSize
= sizeof(surface_desc
);
7150 surface_desc
.dwFlags
= DDSD_CAPS
;
7151 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7152 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
7153 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7155 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
7156 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7157 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
7158 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7159 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7160 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
7161 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
7162 "Got unexpected palette %p, expected %p.\n",
7163 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7164 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
7166 /* The primary uses the system palette. In exclusive mode, the system palette matches
7167 * the ddraw palette attached to the primary, so the result is what you would expect
7168 * from a regular surface. Tests for the interaction between the ddraw palette and
7169 * the system palette are not included pending an application that depends on this.
7170 * The relation between those causes problems on Windows Vista and newer for games
7171 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
7172 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7173 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7174 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7176 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7177 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7178 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7179 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7181 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7183 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7184 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7185 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7187 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
7188 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7190 memset(&surface_desc
, 0, sizeof(surface_desc
));
7191 surface_desc
.dwSize
= sizeof(surface_desc
);
7192 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7193 surface_desc
.dwWidth
= 16;
7194 surface_desc
.dwHeight
= 16;
7195 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7196 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7197 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7199 /* Here the offscreen surface appears to use the primary's palette,
7200 * but in all likelihood it is actually the system palette. */
7201 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7202 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7203 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7204 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7205 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7207 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7208 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7209 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7210 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7212 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7214 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7215 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7216 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7218 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7219 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7221 /* On real hardware a change to the primary surface's palette applies immediately,
7222 * even on device contexts from offscreen surfaces that do not have their own
7223 * palette. On the testbot VMs this is not the case. Don't test this until we
7224 * know of an application that depends on this. */
7226 memset(palette_entries
, 0, sizeof(palette_entries
));
7227 palette_entries
[1].peBlue
= 0x40;
7228 palette_entries
[2].peRed
= 0x40;
7229 palette_entries
[3].peGreen
= 0x40;
7230 palette_entries
[4].peRed
= 0x12;
7231 palette_entries
[4].peGreen
= 0x34;
7232 palette_entries
[4].peBlue
= 0x56;
7233 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7234 palette_entries
, &palette2
, NULL
);
7235 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7236 hr
= IDirectDrawSurface_SetPalette(surface
, palette2
);
7237 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7239 /* A palette assigned to the offscreen surface overrides the primary / system
7241 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7242 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7243 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7244 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7245 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
7247 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
7248 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7249 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7250 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
7252 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7254 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7255 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7256 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7258 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7259 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7261 refcount
= IDirectDrawSurface_Release(surface
);
7262 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7264 /* The Windows 8 testbot keeps extra references to the primary and
7265 * backbuffer while in 8 bpp mode. */
7266 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
7267 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7269 refcount
= IDirectDrawSurface_Release(primary
);
7270 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7271 refcount
= IDirectDrawPalette_Release(palette2
);
7272 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7273 refcount
= IDirectDrawPalette_Release(palette
);
7274 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7275 refcount
= IDirectDraw2_Release(ddraw
);
7276 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7277 DestroyWindow(window
);
7280 static void test_palette_alpha(void)
7282 IDirectDrawSurface
*surface1
;
7283 IDirectDrawSurface2
*surface
;
7284 DDSURFACEDESC surface_desc
;
7285 IDirectDraw2
*ddraw
;
7286 IDirectDrawPalette
*palette
;
7290 PALETTEENTRY palette_entries
[256];
7295 BOOL attach_allowed
;
7300 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
7301 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
7302 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
7305 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7306 0, 0, 640, 480, 0, 0, 0, 0);
7307 ddraw
= create_ddraw();
7308 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7309 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7311 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7312 IDirectDraw2_Release(ddraw
);
7313 DestroyWindow(window
);
7316 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7317 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7319 memset(palette_entries
, 0, sizeof(palette_entries
));
7320 palette_entries
[1].peFlags
= 0x42;
7321 palette_entries
[2].peFlags
= 0xff;
7322 palette_entries
[3].peFlags
= 0x80;
7323 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
7324 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7326 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7327 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7328 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7329 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7330 palette_entries
[0].peFlags
);
7331 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7332 palette_entries
[1].peFlags
);
7333 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7334 palette_entries
[2].peFlags
);
7335 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7336 palette_entries
[3].peFlags
);
7338 IDirectDrawPalette_Release(palette
);
7340 memset(palette_entries
, 0, sizeof(palette_entries
));
7341 palette_entries
[1].peFlags
= 0x42;
7342 palette_entries
[1].peRed
= 0xff;
7343 palette_entries
[2].peFlags
= 0xff;
7344 palette_entries
[3].peFlags
= 0x80;
7345 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
7346 palette_entries
, &palette
, NULL
);
7347 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7349 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7350 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7351 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7352 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7353 palette_entries
[0].peFlags
);
7354 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7355 palette_entries
[1].peFlags
);
7356 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7357 palette_entries
[2].peFlags
);
7358 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7359 palette_entries
[3].peFlags
);
7361 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
7363 memset(&surface_desc
, 0, sizeof(surface_desc
));
7364 surface_desc
.dwSize
= sizeof(surface_desc
);
7365 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
7366 surface_desc
.dwWidth
= 128;
7367 surface_desc
.dwHeight
= 128;
7368 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
7369 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7370 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7371 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
7372 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
7373 IDirectDrawSurface_Release(surface1
);
7375 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
7376 if (test_data
[i
].attach_allowed
)
7377 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7379 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7387 hr
= IDirectDrawSurface2_GetDC(surface
, &dc
);
7388 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_CANTCREATEDC
) /* Win2k testbot */,
7389 "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7392 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
7393 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
7394 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
7395 rgbquad
.rgbRed
, test_data
[i
].name
);
7396 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
7397 rgbquad
.rgbGreen
, test_data
[i
].name
);
7398 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
7399 rgbquad
.rgbBlue
, test_data
[i
].name
);
7400 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
7401 rgbquad
.rgbReserved
, test_data
[i
].name
);
7402 hr
= IDirectDrawSurface2_ReleaseDC(surface
, dc
);
7403 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7406 IDirectDrawSurface2_Release(surface
);
7409 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
7410 memset(&surface_desc
, 0, sizeof(surface_desc
));
7411 surface_desc
.dwSize
= sizeof(surface_desc
);
7412 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7413 surface_desc
.dwWidth
= 128;
7414 surface_desc
.dwHeight
= 128;
7415 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7416 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7417 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7418 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7419 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7420 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7421 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7422 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7423 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7424 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
7425 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
7426 IDirectDrawSurface_Release(surface1
);
7428 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
7429 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
7430 IDirectDrawSurface2_Release(surface
);
7432 /* The Windows 8 testbot keeps extra references to the primary
7433 * while in 8 bpp mode. */
7434 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
7435 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7437 refcount
= IDirectDrawPalette_Release(palette
);
7438 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7439 refcount
= IDirectDraw2_Release(ddraw
);
7440 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7441 DestroyWindow(window
);
7444 static void test_lost_device(void)
7446 IDirectDrawSurface
*surface
;
7447 DDSURFACEDESC surface_desc
;
7448 HWND window1
, window2
;
7449 IDirectDraw2
*ddraw
;
7454 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7455 0, 0, 640, 480, 0, 0, 0, 0);
7456 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7457 0, 0, 640, 480, 0, 0, 0, 0);
7458 ddraw
= create_ddraw();
7459 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7460 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7461 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7463 memset(&surface_desc
, 0, sizeof(surface_desc
));
7464 surface_desc
.dwSize
= sizeof(surface_desc
);
7465 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
7466 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
7467 surface_desc
.dwBackBufferCount
= 1;
7468 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7469 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7471 hr
= IDirectDrawSurface_IsLost(surface
);
7472 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7473 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7474 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7476 ret
= SetForegroundWindow(GetDesktopWindow());
7477 ok(ret
, "Failed to set foreground window.\n");
7478 hr
= IDirectDrawSurface_IsLost(surface
);
7479 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7480 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7481 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7483 ret
= SetForegroundWindow(window1
);
7484 ok(ret
, "Failed to set foreground window.\n");
7485 hr
= IDirectDrawSurface_IsLost(surface
);
7486 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7487 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7488 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7490 hr
= restore_surfaces(ddraw
);
7491 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7492 hr
= IDirectDrawSurface_IsLost(surface
);
7493 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7494 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7495 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7497 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
7498 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7499 hr
= IDirectDrawSurface_IsLost(surface
);
7500 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7501 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7502 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7504 /* Trying to restore the primary will crash, probably because flippable
7505 * surfaces can't exist in DDSCL_NORMAL. */
7506 IDirectDrawSurface_Release(surface
);
7507 memset(&surface_desc
, 0, sizeof(surface_desc
));
7508 surface_desc
.dwSize
= sizeof(surface_desc
);
7509 surface_desc
.dwFlags
= DDSD_CAPS
;
7510 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7511 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7512 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7514 hr
= IDirectDrawSurface_IsLost(surface
);
7515 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7517 ret
= SetForegroundWindow(GetDesktopWindow());
7518 ok(ret
, "Failed to set foreground window.\n");
7519 hr
= IDirectDrawSurface_IsLost(surface
);
7520 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7522 ret
= SetForegroundWindow(window1
);
7523 ok(ret
, "Failed to set foreground window.\n");
7524 hr
= IDirectDrawSurface_IsLost(surface
);
7525 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7527 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7528 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7529 hr
= IDirectDrawSurface_IsLost(surface
);
7530 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7532 hr
= restore_surfaces(ddraw
);
7533 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7534 hr
= IDirectDrawSurface_IsLost(surface
);
7535 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7537 IDirectDrawSurface_Release(surface
);
7538 memset(&surface_desc
, 0, sizeof(surface_desc
));
7539 surface_desc
.dwSize
= sizeof(surface_desc
);
7540 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
7541 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
7542 U5(surface_desc
).dwBackBufferCount
= 1;
7543 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7544 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7546 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7547 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7548 hr
= IDirectDrawSurface_IsLost(surface
);
7549 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7550 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7551 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7553 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
7554 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7555 hr
= IDirectDrawSurface_IsLost(surface
);
7556 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7557 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7558 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7560 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
7561 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7562 hr
= IDirectDrawSurface_IsLost(surface
);
7563 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7564 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7565 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7567 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
7568 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7569 hr
= IDirectDrawSurface_IsLost(surface
);
7570 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7571 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7572 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7574 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
7575 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7576 hr
= IDirectDrawSurface_IsLost(surface
);
7577 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7578 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7579 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7581 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7582 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7583 hr
= IDirectDrawSurface_IsLost(surface
);
7584 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7585 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7586 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7588 IDirectDrawSurface_Release(surface
);
7589 refcount
= IDirectDraw2_Release(ddraw
);
7590 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7591 DestroyWindow(window2
);
7592 DestroyWindow(window1
);
7595 static void test_surface_desc_lock(void)
7597 IDirectDrawSurface
*surface
;
7598 DDSURFACEDESC surface_desc
;
7599 IDirectDraw2
*ddraw
;
7604 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7605 0, 0, 640, 480, 0, 0, 0, 0);
7606 ddraw
= create_ddraw();
7607 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7608 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7609 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7611 memset(&surface_desc
, 0, sizeof(surface_desc
));
7612 surface_desc
.dwSize
= sizeof(surface_desc
);
7613 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7614 surface_desc
.dwWidth
= 16;
7615 surface_desc
.dwHeight
= 16;
7616 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7617 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7618 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7620 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7621 surface_desc
.dwSize
= sizeof(surface_desc
);
7622 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7623 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7624 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7626 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7627 surface_desc
.dwSize
= sizeof(surface_desc
);
7628 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7629 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7630 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7631 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7632 surface_desc
.dwSize
= sizeof(surface_desc
);
7633 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7634 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7635 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7636 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
7637 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7639 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7640 surface_desc
.dwSize
= sizeof(surface_desc
);
7641 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7642 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7643 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7645 IDirectDrawSurface_Release(surface
);
7646 refcount
= IDirectDraw2_Release(ddraw
);
7647 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7648 DestroyWindow(window
);
7651 static void test_texturemapblend(void)
7656 static RECT rect
= {0, 0, 64, 128};
7657 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7659 IDirectDrawSurface
*surface
, *rt
;
7660 IDirect3DTexture2
*texture
;
7661 D3DTEXTUREHANDLE texture_handle
;
7663 IDirectDraw2
*ddraw
;
7664 IDirect3DDevice2
*device
;
7665 IDirect3DMaterial2
*material
;
7666 IDirect3DViewport2
*viewport
;
7670 static D3DTLVERTEX test1_quads
[] =
7672 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {0.0f
}},
7673 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {1.0f
}},
7674 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {0.0f
}},
7675 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {1.0f
}},
7676 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {0.0f
}},
7677 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {1.0f
}},
7678 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {0.0f
}},
7679 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {1.0f
}},
7683 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {0.0f
}},
7684 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {1.0f
}},
7685 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {0.0f
}},
7686 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {1.0f
}},
7687 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {0.0f
}},
7688 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {1.0f
}},
7689 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {0.0f
}},
7690 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {1.0f
}},
7693 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7694 0, 0, 640, 480, 0, 0, 0, 0);
7695 ddraw
= create_ddraw();
7696 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7697 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
7699 skip("Failed to create a 3D device, skipping test.\n");
7700 DestroyWindow(window
);
7701 IDirectDraw2_Release(ddraw
);
7705 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
7706 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
7708 material
= create_diffuse_material(device
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
7709 viewport
= create_viewport(device
, 0, 0, 640, 480);
7710 viewport_set_background(device
, viewport
, material
);
7711 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
7712 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
7714 /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel.
7716 * The vertex alpha is completely ignored in this case, so case 1 and 2 combined are not
7717 * a D3DTOP_MODULATE with texture alpha = 0xff in case 2 (no alpha in texture). */
7718 memset(&ddsd
, 0, sizeof(ddsd
));
7719 ddsd
.dwSize
= sizeof(ddsd
);
7720 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
7721 ddsd
.dwHeight
= 128;
7723 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
7724 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
7725 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
7726 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7727 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7728 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7729 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7730 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
7731 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
7732 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7734 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
7735 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
7736 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
7737 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
7738 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
7739 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7741 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7742 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
7744 memset(&fx
, 0, sizeof(fx
));
7745 fx
.dwSize
= sizeof(fx
);
7746 U5(fx
).dwFillColor
= 0xff0000ff;
7747 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7748 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7749 U5(fx
).dwFillColor
= 0x800000ff;
7750 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7751 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7753 /* Note that the ddraw1 version of this test runs tests 1-3 with D3DRENDERSTATE_COLORKEYENABLE
7754 * enabled, whereas this version only runs test 4 with color keying on. Because no color key
7755 * is set on the texture this should not result in different behavior. */
7756 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
7757 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7758 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
7759 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7760 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
7761 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7762 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
7763 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7764 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
7765 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7766 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
);
7767 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7769 hr
= IDirect3DDevice2_BeginScene(device
);
7770 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7771 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
7772 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7773 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
7774 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7775 hr
= IDirect3DDevice2_EndScene(device
);
7776 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7778 color
= get_surface_color(rt
, 5, 5);
7779 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
7780 color
= get_surface_color(rt
, 400, 5);
7781 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
7782 color
= get_surface_color(rt
, 5, 245);
7783 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
7784 color
= get_surface_color(rt
, 400, 245);
7785 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
7787 IDirect3DTexture2_Release(texture
);
7788 ref
= IDirectDrawSurface_Release(surface
);
7789 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
7791 /* Test alpha with texture that has no alpha channel - alpha should be taken from diffuse vertex color. */
7792 memset(&ddsd
, 0, sizeof(ddsd
));
7793 ddsd
.dwSize
= sizeof(ddsd
);
7794 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
7795 ddsd
.dwHeight
= 128;
7797 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
7798 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
7799 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7800 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7801 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7802 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7803 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7805 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
7806 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7808 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
7809 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
7810 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
7811 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
7812 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
7813 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7815 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7816 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
7818 U5(fx
).dwFillColor
= 0xff0000ff;
7819 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7820 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7821 U5(fx
).dwFillColor
= 0x800000ff;
7822 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7823 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7825 hr
= IDirect3DDevice2_BeginScene(device
);
7826 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7827 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
7828 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7829 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
7830 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7831 hr
= IDirect3DDevice2_EndScene(device
);
7832 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7834 color
= get_surface_color(rt
, 5, 5);
7835 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
7836 color
= get_surface_color(rt
, 400, 5);
7837 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
7838 color
= get_surface_color(rt
, 5, 245);
7839 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
7840 color
= get_surface_color(rt
, 400, 245);
7841 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
7843 IDirect3DTexture2_Release(texture
);
7844 ref
= IDirectDrawSurface_Release(surface
);
7845 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
7847 /* Test RGB - should multiply color components from diffuse vertex color and texture. */
7848 memset(&ddsd
, 0, sizeof(ddsd
));
7849 ddsd
.dwSize
= sizeof(ddsd
);
7850 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
7851 ddsd
.dwHeight
= 128;
7853 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
7854 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
7855 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
7856 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7857 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7858 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7859 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7860 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
7861 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
7862 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7864 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
7865 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
7866 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
7867 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
7868 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
7869 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7871 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7872 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
7874 U5(fx
).dwFillColor
= 0x00ffffff;
7875 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7876 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7877 U5(fx
).dwFillColor
= 0x00ffff80;
7878 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7879 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7881 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
7882 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7884 hr
= IDirect3DDevice2_BeginScene(device
);
7885 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7886 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test2_quads
[0], 4, 0);
7887 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7888 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test2_quads
[4], 4, 0);
7889 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7890 hr
= IDirect3DDevice2_EndScene(device
);
7891 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7893 color
= get_surface_color(rt
, 5, 5);
7894 ok(compare_color(color
, 0x00ff0040, 2), "Got unexpected color 0x%08x.\n", color
);
7895 color
= get_surface_color(rt
, 400, 5);
7896 ok(compare_color(color
, 0x00ff0080, 2), "Got unexpected color 0x%08x.\n", color
);
7897 color
= get_surface_color(rt
, 5, 245);
7898 ok(compare_color(color
, 0x00800080, 2), "Got unexpected color 0x%08x.\n", color
);
7899 color
= get_surface_color(rt
, 400, 245);
7900 ok(compare_color(color
, 0x008000ff, 2), "Got unexpected color 0x%08x.\n", color
);
7902 IDirect3DTexture2_Release(texture
);
7903 ref
= IDirectDrawSurface_Release(surface
);
7904 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
7906 /* Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere). */
7907 memset(&ddsd
, 0, sizeof(ddsd
));
7908 ddsd
.dwSize
= sizeof(ddsd
);
7909 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
7910 ddsd
.dwHeight
= 128;
7912 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
7913 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
7914 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7915 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 16;
7916 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
7917 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
7918 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
7920 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
7921 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7923 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
7924 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
7925 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
7926 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
7927 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
7928 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7930 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7931 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
7933 U5(fx
).dwFillColor
= 0xf800;
7934 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7935 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7936 U5(fx
).dwFillColor
= 0x001f;
7937 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7938 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7940 ckey
.dwColorSpaceLowValue
= 0x001f;
7941 ckey
.dwColorSpaceHighValue
= 0x001f;
7942 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
7943 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
7945 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
7946 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7947 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
7948 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7950 hr
= IDirect3DDevice2_BeginScene(device
);
7951 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7952 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
7953 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7954 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
7955 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7956 hr
= IDirect3DDevice2_EndScene(device
);
7957 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7959 color
= get_surface_color(rt
, 5, 5);
7960 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
7961 color
= get_surface_color(rt
, 400, 5);
7962 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
7963 color
= get_surface_color(rt
, 5, 245);
7964 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
7965 color
= get_surface_color(rt
, 400, 245);
7966 ok(compare_color(color
, 0x00800000, 2), "Got unexpected color 0x%08x.\n", color
);
7968 IDirect3DTexture2_Release(texture
);
7969 ref
= IDirectDrawSurface_Release(surface
);
7970 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
7972 destroy_viewport(device
, viewport
);
7973 ref
= IDirect3DMaterial2_Release(material
);
7974 ok(ref
== 0, "Material not properly released, refcount %u.\n", ref
);
7975 IDirectDrawSurface_Release(rt
);
7976 IDirect3DDevice2_Release(device
);
7977 ref
= IDirectDraw2_Release(ddraw
);
7978 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
7979 DestroyWindow(window
);
7982 static void test_viewport_clear_rect(void)
7985 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7986 static D3DRECT clear_rect2
= {{90}, {90}, {110}, {110}};
7987 IDirectDrawSurface
*rt
;
7989 IDirectDraw2
*ddraw
;
7990 IDirect3DDevice2
*device
;
7991 IDirect3DMaterial2
*red
, *green
;
7992 IDirect3DViewport2
*viewport
, *viewport2
;
7996 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7997 0, 0, 640, 480, 0, 0, 0, 0);
7998 ddraw
= create_ddraw();
7999 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8000 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8002 skip("Failed to create a 3D device, skipping test.\n");
8003 DestroyWindow(window
);
8004 IDirectDraw2_Release(ddraw
);
8008 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8009 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8011 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
8012 viewport
= create_viewport(device
, 0, 0, 640, 480);
8013 viewport_set_background(device
, viewport
, red
);
8014 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8015 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8017 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
8018 viewport2
= create_viewport(device
, 100, 100, 20, 20);
8019 viewport_set_background(device
, viewport2
, green
);
8020 hr
= IDirect3DViewport2_Clear(viewport2
, 1, &clear_rect2
, D3DCLEAR_TARGET
);
8021 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8023 color
= get_surface_color(rt
, 85, 85); /* Outside both. */
8024 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8025 color
= get_surface_color(rt
, 95, 95); /* Outside vp, inside rect. */
8026 /* AMD GPUs ignore the viewport dimensions and only care about the rectangle. */
8027 ok(compare_color(color
, 0x00ff0000, 1) || broken(compare_color(color
, 0x0000ff00, 1)),
8028 "Got unexpected color 0x%08x.\n", color
);
8029 color
= get_surface_color(rt
, 105, 105); /* Inside both. */
8030 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
8031 color
= get_surface_color(rt
, 115, 115); /* Inside vp, outside rect. */
8032 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8033 color
= get_surface_color(rt
, 125, 125); /* Outside both. */
8034 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8036 destroy_viewport(device
, viewport2
);
8037 destroy_material(green
);
8038 destroy_viewport(device
, viewport
);
8039 destroy_material(red
);
8040 IDirectDrawSurface_Release(rt
);
8041 IDirect3DDevice2_Release(device
);
8042 ref
= IDirectDraw2_Release(ddraw
);
8043 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
8044 DestroyWindow(window
);
8047 static void test_color_fill(void)
8050 IDirect3DDevice2
*device
;
8051 IDirectDraw2
*ddraw
;
8052 IDirectDrawSurface
*surface
, *surface2
;
8053 DDSURFACEDESC surface_desc
;
8058 RECT rect
= {5, 5, 7, 7};
8060 DWORD num_fourcc_codes
, *fourcc_codes
;
8062 BOOL support_uyvy
= FALSE
, support_yuy2
= FALSE
;
8066 HRESULT colorfill_hr
, depthfill_hr
;
8071 DDPIXELFORMAT format
;
8076 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8077 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8079 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8080 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8084 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
8085 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8087 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8088 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8092 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
8093 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
8095 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8096 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8100 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
8101 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
8103 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8104 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8108 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
,
8109 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
8110 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
8113 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
8114 * different afterwards. DX9+ GPUs set one of the two luminance values
8115 * in each block, but AMD and Nvidia GPUs disagree on which luminance
8116 * value they set. r200 (dx8) just sets the entire block to the clear
8118 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8119 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
8121 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8122 {0}, {0}, {0}, {0}, {0}
8126 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8127 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
8129 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8130 {0}, {0}, {0}, {0}, {0}
8134 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
8135 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
8137 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8138 {0}, {0}, {0}, {0}, {0}
8142 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
8143 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
8145 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8146 {0}, {0}, {0}, {0}, {0}
8150 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
8151 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
8153 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8154 {0}, {0}, {0}, {0}, {0}
8158 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
8159 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
8161 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8162 {0}, {0}, {0}, {0}, {0}
8166 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
8167 * surface works, presumably because it is handled by the runtime instead of
8169 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8170 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
8172 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
8173 {8}, {0}, {0}, {0}, {0}
8177 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
8178 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
8180 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
8181 {8}, {0}, {0}, {0}, {0}
8193 {SRCCOPY
, "SRCCOPY", DD_OK
},
8194 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
8195 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
8196 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
8197 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
8198 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
8199 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
8200 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
8201 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
8202 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
8203 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
8204 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
8205 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
8206 {BLACKNESS
, "BLACKNESS", DD_OK
},
8207 {WHITENESS
, "WHITENESS", DD_OK
},
8208 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
8211 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8212 0, 0, 640, 480, 0, 0, 0, 0);
8213 ddraw
= create_ddraw();
8214 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8215 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8217 skip("Failed to create a 3D device, skipping test.\n");
8218 DestroyWindow(window
);
8219 IDirectDraw2_Release(ddraw
);
8223 hr
= IDirectDraw2_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
8224 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
8225 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
8226 num_fourcc_codes
* sizeof(*fourcc_codes
));
8229 hr
= IDirectDraw2_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
8230 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
8231 for (i
= 0; i
< num_fourcc_codes
; i
++)
8233 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
8234 support_yuy2
= TRUE
;
8235 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
8236 support_uyvy
= TRUE
;
8238 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
8240 memset(&hal_caps
, 0, sizeof(hal_caps
));
8241 hal_caps
.dwSize
= sizeof(hal_caps
);
8242 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
8243 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
8245 if ((!support_yuy2
&& !support_uyvy
) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
8246 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
8248 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
8250 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
8251 memset(&fx
, 0, sizeof(fx
));
8252 fx
.dwSize
= sizeof(fx
);
8253 U5(fx
).dwFillColor
= 0xdeadbeef;
8255 memset(&surface_desc
, 0, sizeof(surface_desc
));
8256 surface_desc
.dwSize
= sizeof(surface_desc
);
8257 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8258 surface_desc
.dwWidth
= 64;
8259 surface_desc
.dwHeight
= 64;
8260 surface_desc
.ddpfPixelFormat
= tests
[i
].format
;
8261 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
8263 if (tests
[i
].caps
& DDSCAPS_TEXTURE
)
8265 struct format_support_check check
= {&tests
[i
].format
, FALSE
};
8266 hr
= IDirect3DDevice2_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
8267 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
8268 if (!check
.supported
)
8272 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !support_yuy2
)
8274 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !support_uyvy
)
8276 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
8279 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
8281 surface_desc
.dwFlags
&= ~DDSD_PIXELFORMAT
;
8282 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
8283 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
8286 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8287 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8289 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8290 if (tests
[i
].format
.dwFourCC
)
8291 todo_wine
ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8292 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8294 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8295 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8297 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8298 if (tests
[i
].format
.dwFourCC
)
8299 todo_wine
ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8300 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8302 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8303 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8305 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8307 memset(&surface_desc
, 0, sizeof(surface_desc
));
8308 surface_desc
.dwSize
= sizeof(surface_desc
);
8309 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8310 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8311 color
= surface_desc
.lpSurface
;
8312 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
8313 *color
, tests
[i
].result
, tests
[i
].name
);
8314 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8315 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8318 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8319 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8320 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
8321 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8322 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8323 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
8325 U5(fx
).dwFillColor
= 0xdeadbeef;
8326 fx
.dwROP
= BLACKNESS
;
8327 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8328 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
8329 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
8330 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8331 U5(fx
).dwFillColor
, tests
[i
].name
);
8333 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8335 memset(&surface_desc
, 0, sizeof(surface_desc
));
8336 surface_desc
.dwSize
= sizeof(surface_desc
);
8337 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8338 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8339 color
= surface_desc
.lpSurface
;
8340 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
8341 *color
, tests
[i
].name
);
8342 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8343 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8346 fx
.dwROP
= WHITENESS
;
8347 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8348 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
8349 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
8350 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8351 U5(fx
).dwFillColor
, tests
[i
].name
);
8353 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8355 memset(&surface_desc
, 0, sizeof(surface_desc
));
8356 surface_desc
.dwSize
= sizeof(surface_desc
);
8357 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8358 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8359 color
= surface_desc
.lpSurface
;
8360 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
8361 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
8362 *color
, tests
[i
].name
);
8363 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8364 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8367 IDirectDrawSurface_Release(surface
);
8370 memset(&fx
, 0, sizeof(fx
));
8371 fx
.dwSize
= sizeof(fx
);
8372 U5(fx
).dwFillColor
= 0xdeadbeef;
8373 fx
.dwROP
= WHITENESS
;
8375 memset(&surface_desc
, 0, sizeof(surface_desc
));
8376 surface_desc
.dwSize
= sizeof(surface_desc
);
8377 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8378 surface_desc
.dwWidth
= 64;
8379 surface_desc
.dwHeight
= 64;
8380 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
8381 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8382 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8383 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8384 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8385 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8386 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
8387 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8388 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8389 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
8390 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8393 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
8394 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8395 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
8396 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8398 /* Unused source rectangle. */
8399 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8400 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8401 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8402 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8404 /* Unused source surface. */
8405 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8406 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8407 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8408 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8409 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8410 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8411 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8412 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8414 /* Inverted destination or source rectangle. */
8415 SetRect(&rect
, 5, 7, 7, 5);
8416 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8417 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8418 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8419 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8420 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8421 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8422 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8423 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8424 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8425 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8427 /* Negative rectangle. */
8428 SetRect(&rect
, -1, -1, 5, 5);
8429 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8430 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8431 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8432 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8433 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8434 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8435 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8436 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8437 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8438 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8440 /* Out of bounds rectangle. */
8441 SetRect(&rect
, 0, 0, 65, 65);
8442 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8443 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8444 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8445 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8447 /* Combine multiple flags. */
8448 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8449 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8450 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8451 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8452 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8453 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8455 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
8457 fx
.dwROP
= rops
[i
].rop
;
8458 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8459 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
8462 IDirectDrawSurface_Release(surface2
);
8463 IDirectDrawSurface_Release(surface
);
8465 memset(&surface_desc
, 0, sizeof(surface_desc
));
8466 surface_desc
.dwSize
= sizeof(surface_desc
);
8467 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_ZBUFFERBITDEPTH
;
8468 surface_desc
.dwWidth
= 64;
8469 surface_desc
.dwHeight
= 64;
8470 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
8471 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
8472 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8473 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8474 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
8475 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8478 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
8479 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8481 /* Unused source rectangle. */
8482 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8483 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8485 /* Unused source surface. */
8486 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8487 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8488 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8489 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8491 /* Inverted destination or source rectangle. */
8492 SetRect(&rect
, 5, 7, 7, 5);
8493 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8494 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8495 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8496 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8497 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8498 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8499 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8500 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8502 /* Negative rectangle. */
8503 SetRect(&rect
, -1, -1, 5, 5);
8504 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8505 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8506 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8507 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8508 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8509 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8510 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8511 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8513 /* Out of bounds rectangle. */
8514 SetRect(&rect
, 0, 0, 65, 65);
8515 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8516 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8518 /* Combine multiple flags. */
8519 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8520 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8522 IDirectDrawSurface_Release(surface2
);
8523 IDirectDrawSurface_Release(surface
);
8526 IDirect3DDevice2_Release(device
);
8527 refcount
= IDirectDraw2_Release(ddraw
);
8528 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
8529 DestroyWindow(window
);
8532 static void test_colorkey_precision(void)
8534 static D3DLVERTEX quad
[] =
8536 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {0.0f
}, {0.0f
}},
8537 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {0.0f
}, {1.0f
}},
8538 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {1.0f
}, {0.0f
}},
8539 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {1.0f
}, {1.0f
}},
8541 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8542 IDirect3DDevice2
*device
;
8543 IDirectDraw2
*ddraw
;
8544 IDirectDrawSurface
*rt
;
8545 IDirect3DViewport2
*viewport
;
8548 IDirectDrawSurface
*src
, *dst
, *texture
;
8549 D3DTEXTUREHANDLE handle
;
8550 IDirect3DTexture2
*d3d_texture
;
8551 IDirect3DMaterial2
*green
;
8552 DDSURFACEDESC surface_desc
, lock_desc
;
8558 DWORD data
[4] = {0}, color_mask
;
8559 D3DDEVICEDESC device_desc
, hel_desc
;
8563 unsigned int max
, shift
, bpp
, clear
;
8570 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8",
8572 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8573 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
8578 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel",
8580 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8581 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
8586 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel",
8588 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8589 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
8594 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4",
8596 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8597 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
8603 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8604 0, 0, 640, 480, 0, 0, 0, 0);
8605 ddraw
= create_ddraw();
8606 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8607 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8609 skip("Failed to create a 3D device, skipping test.\n");
8610 DestroyWindow(window
);
8611 IDirectDraw2_Release(ddraw
);
8614 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8615 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8617 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
8618 * (color key doesn't match although the values are equal), and a false
8619 * positive when the color key is 0 and the texture contains the value 1.
8620 * I don't want to mark this broken unconditionally since this would
8621 * essentially disable the test on Windows. Try to detect WARP (and I
8622 * guess mismatch other SW renderers) by its ability to texture from
8623 * system memory. Also on random occasions 254 == 255 and 255 != 255.*/
8624 memset(&device_desc
, 0, sizeof(device_desc
));
8625 device_desc
.dwSize
= sizeof(device_desc
);
8626 memset(&hel_desc
, 0, sizeof(hel_desc
));
8627 hel_desc
.dwSize
= sizeof(hel_desc
);
8628 hr
= IDirect3DDevice2_GetCaps(device
, &device_desc
, &hel_desc
);
8629 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8630 warp
= !!(device_desc
.dwDevCaps
& D3DDEVCAPS_TEXTURESYSTEMMEMORY
);
8632 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
8633 viewport
= create_viewport(device
, 0, 0, 640, 480);
8634 viewport_set_background(device
, viewport
, green
);
8635 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
8636 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
8638 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8639 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
8640 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
8641 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
8642 /* There's no way to ignore the texture color in d3d2, so multiply the texture color
8643 * with a black vertex color. */
8644 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATEALPHA
);
8645 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8647 memset(&fx
, 0, sizeof(fx
));
8648 fx
.dwSize
= sizeof(fx
);
8649 memset(&lock_desc
, 0, sizeof(lock_desc
));
8650 lock_desc
.dwSize
= sizeof(lock_desc
);
8652 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
8654 memset(&surface_desc
, 0, sizeof(surface_desc
));
8655 surface_desc
.dwSize
= sizeof(surface_desc
);
8656 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8657 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8658 surface_desc
.dwWidth
= 4;
8659 surface_desc
.dwHeight
= 1;
8660 surface_desc
.ddpfPixelFormat
= tests
[t
].fmt
;
8661 /* Windows XP (at least with the r200 driver, other drivers untested) produces
8662 * garbage when doing color keyed texture->texture blits. */
8663 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
8664 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8665 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
8666 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8668 fx
.dwFillColor
= tests
[t
].clear
;
8669 /* On the w8 testbot (WARP driver) the blit result has different values in the
8671 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
8672 | U3(tests
[t
].fmt
).dwGBitMask
8673 | U4(tests
[t
].fmt
).dwBBitMask
;
8675 for (c
= 0; c
<= tests
[t
].max
; ++c
)
8677 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
8678 * texture after it has been set once... */
8679 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
8680 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8681 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
8682 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
8683 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
8684 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8686 hr
= IDirectDrawSurface4_QueryInterface(texture
, &IID_IDirect3DTexture2
, (void **)&d3d_texture
);
8687 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8688 hr
= IDirect3DTexture2_GetHandle(d3d_texture
, device
, &handle
);
8689 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8690 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, handle
);
8691 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
8692 IDirect3DTexture2_Release(d3d_texture
);
8694 hr
= IDirectDrawSurface_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8695 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
8697 hr
= IDirectDrawSurface_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
8698 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8699 switch (tests
[t
].bpp
)
8702 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
8703 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
8704 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
8705 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
8709 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
8710 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
8711 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
8712 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
8715 hr
= IDirectDrawSurface_Unlock(src
, 0);
8716 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8717 hr
= IDirectDrawSurface_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
8718 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
8720 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
8721 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
8722 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
8723 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8725 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
8726 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
8728 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
8729 hr
= IDirectDrawSurface_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
8730 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8731 switch (tests
[t
].bpp
)
8734 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
8735 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
8736 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
8737 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
8741 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
8742 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
8743 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
8744 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
8747 hr
= IDirectDrawSurface_Unlock(dst
, 0);
8748 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8752 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8753 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
8755 if (data
[3] == tests
[t
].clear
)
8757 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
8758 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
8759 * even when a different surface is used. The blit itself doesn't draw anything,
8760 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
8761 * never be masked out by the key.
8763 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
8764 * terrible on WARP. */
8765 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
8766 IDirectDrawSurface_Release(texture
);
8767 IDirectDrawSurface_Release(src
);
8768 IDirectDrawSurface_Release(dst
);
8773 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8774 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
8776 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8777 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
8779 if (c
== tests
[t
].max
)
8780 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8781 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
8783 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8784 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
8786 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8787 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
8789 hr
= IDirect3DDevice2_BeginScene(device
);
8790 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8791 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
8792 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8793 hr
= IDirect3DDevice2_EndScene(device
);
8794 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8796 color
= get_surface_color(rt
, 80, 240);
8798 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
8799 "Got unexpected color 0x%08x, format %s, c=%u.\n",
8800 color
, tests
[t
].name
, c
);
8802 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
8803 "Got unexpected color 0x%08x, format %s, c=%u.\n",
8804 color
, tests
[t
].name
, c
);
8806 color
= get_surface_color(rt
, 240, 240);
8807 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
8808 "Got unexpected color 0x%08x, format %s, c=%u.\n",
8809 color
, tests
[t
].name
, c
);
8811 color
= get_surface_color(rt
, 400, 240);
8812 if (c
== tests
[t
].max
)
8813 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
8814 "Got unexpected color 0x%08x, format %s, c=%u.\n",
8815 color
, tests
[t
].name
, c
);
8817 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
8818 "Got unexpected color 0x%08x, format %s, c=%u.\n",
8819 color
, tests
[t
].name
, c
);
8821 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
8822 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
8823 IDirectDrawSurface_Release(texture
);
8825 IDirectDrawSurface_Release(src
);
8826 IDirectDrawSurface_Release(dst
);
8830 destroy_viewport(device
, viewport
);
8831 destroy_material(green
);
8832 IDirectDrawSurface_Release(rt
);
8833 IDirect3DDevice2_Release(device
);
8834 refcount
= IDirectDraw2_Release(ddraw
);
8835 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
8836 DestroyWindow(window
);
8839 static void test_range_colorkey(void)
8841 IDirectDraw2
*ddraw
;
8844 IDirectDrawSurface
*surface
;
8845 DDSURFACEDESC surface_desc
;
8849 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8850 0, 0, 640, 480, 0, 0, 0, 0);
8851 ddraw
= create_ddraw();
8852 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8853 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8854 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8856 memset(&surface_desc
, 0, sizeof(surface_desc
));
8857 surface_desc
.dwSize
= sizeof(surface_desc
);
8858 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
8859 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8860 surface_desc
.dwWidth
= 1;
8861 surface_desc
.dwHeight
= 1;
8862 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8863 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8864 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8865 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8866 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8867 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
8869 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
8870 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
8871 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
8872 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8873 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8875 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
8876 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
8877 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8878 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8880 /* Same for DDSCAPS_OFFSCREENPLAIN. */
8881 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8882 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
8883 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
8884 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8885 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8887 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
8888 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
8889 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8890 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8892 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
8893 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
8894 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8895 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8897 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
8898 ckey
.dwColorSpaceLowValue
= 0x00000000;
8899 ckey
.dwColorSpaceHighValue
= 0x00000001;
8900 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8901 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8903 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8904 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
8905 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
8906 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
8908 ckey
.dwColorSpaceLowValue
= 0x00000001;
8909 ckey
.dwColorSpaceHighValue
= 0x00000000;
8910 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8911 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8913 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8914 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
8915 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
8916 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
8918 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
8919 ckey
.dwColorSpaceLowValue
= 0x00000000;
8920 ckey
.dwColorSpaceHighValue
= 0x00000000;
8921 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
8922 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8924 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
8925 ckey
.dwColorSpaceLowValue
= 0x00000001;
8926 ckey
.dwColorSpaceHighValue
= 0x00000000;
8927 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
8928 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8929 ckey
.dwColorSpaceLowValue
= 0x00000000;
8930 ckey
.dwColorSpaceHighValue
= 0x00000001;
8931 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
8932 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8933 /* Range destination keys don't work either. */
8934 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
8935 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8937 /* Just to show it's not because of A, R, and G having equal values. */
8938 ckey
.dwColorSpaceLowValue
= 0x00000000;
8939 ckey
.dwColorSpaceHighValue
= 0x01010101;
8940 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
8941 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8943 /* None of these operations modified the key. */
8944 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8945 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
8946 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
8947 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
8949 IDirectDrawSurface_Release(surface
),
8950 refcount
= IDirectDraw2_Release(ddraw
);
8951 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8952 DestroyWindow(window
);
8955 static void test_shademode(void)
8957 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8958 IDirect3DMaterial2
*background
;
8959 IDirect3DViewport2
*viewport
;
8960 IDirect3DDevice2
*device
;
8961 IDirectDrawSurface
*rt
;
8962 DWORD color0
, color1
;
8963 IDirectDraw2
*ddraw
;
8970 static D3DLVERTEX quad_strip
[] =
8972 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
8973 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
8974 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
8975 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
8979 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
8980 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
8981 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
8983 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
8984 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
8985 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
8991 DWORD color0
, color1
;
8995 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
8996 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
8997 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
8998 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
8999 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
9000 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
9003 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9004 0, 0, 640, 480, 0, 0, 0, 0);
9005 ddraw
= create_ddraw();
9006 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9007 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9009 skip("Failed to create a 3D device, skipping test.\n");
9010 IDirectDraw2_Release(ddraw
);
9011 DestroyWindow(window
);
9015 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
9016 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9017 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9018 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9020 background
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
9021 viewport
= create_viewport(device
, 0, 0, 640, 480);
9022 viewport_set_background(device
, viewport
, background
);
9023 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
9024 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
9026 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
9027 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
9029 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
9030 * the color fixups we have to do for FLAT shading will be dependent on that. */
9032 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
9034 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
9035 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
9037 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
9038 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
9040 hr
= IDirect3DDevice2_BeginScene(device
);
9041 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9042 quad
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? quad_strip
: quad_list
;
9043 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
9044 hr
= IDirect3DDevice2_DrawPrimitive(device
, tests
[i
].primtype
, D3DVT_LVERTEX
, quad
, count
, 0);
9045 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9046 hr
= IDirect3DDevice2_EndScene(device
);
9047 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9049 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
9050 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
9052 /* For D3DSHADE_FLAT it should take the color of the first vertex of
9053 * each triangle. This requires EXT_provoking_vertex or similar
9054 * functionality being available. */
9055 /* PHONG should be the same as GOURAUD, since no hardware implements
9057 ok(color0
== tests
[i
].color0
, "Test %u shading has color0 %08x, expected %08x.\n",
9058 i
, color0
, tests
[i
].color0
);
9059 ok(color1
== tests
[i
].color1
, "Test %u shading has color1 %08x, expected %08x.\n",
9060 i
, color1
, tests
[i
].color1
);
9063 destroy_viewport(device
, viewport
);
9064 destroy_material(background
);
9065 IDirectDrawSurface_Release(rt
);
9066 IDirect3D2_Release(d3d
);
9067 refcount
= IDirect3DDevice2_Release(device
);
9068 ok(!refcount
, "Device has %u references left.\n", refcount
);
9069 IDirectDraw_Release(ddraw
);
9070 DestroyWindow(window
);
9075 IDirectDraw2
*ddraw
;
9076 DEVMODEW current_mode
;
9078 if (!(ddraw
= create_ddraw()))
9080 skip("Failed to create a ddraw object, skipping tests.\n");
9083 IDirectDraw2_Release(ddraw
);
9085 memset(¤t_mode
, 0, sizeof(current_mode
));
9086 current_mode
.dmSize
= sizeof(current_mode
);
9087 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
9088 registry_mode
.dmSize
= sizeof(registry_mode
);
9089 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
9090 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
9091 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
9093 skip("Current mode does not match registry mode, skipping test.\n");
9097 test_coop_level_create_device_window();
9099 test_coop_level_d3d_state();
9100 test_surface_interface_mismatch();
9101 test_coop_level_threaded();
9103 test_texture_load_ckey();
9112 test_window_style();
9113 test_redundant_mode_set();
9114 test_coop_level_mode_set();
9115 test_coop_level_mode_set_multi();
9117 test_coop_level_surf_create();
9118 test_coop_level_multi_window();
9119 test_clear_rect_count();
9120 test_coop_level_versions();
9121 test_lighting_interface_versions();
9122 test_coop_level_activateapp();
9123 test_unsupported_formats();
9125 test_primary_caps();
9126 test_surface_lock();
9127 test_surface_discard();
9129 test_set_surface_desc();
9130 test_user_memory_getdc();
9131 test_sysmem_overlay();
9132 test_primary_palette();
9133 test_surface_attachment();
9134 test_pixel_format();
9135 test_create_surface_pitch();
9137 test_palette_complex();
9141 test_specular_lighting();
9143 test_palette_alpha();
9145 test_surface_desc_lock();
9146 test_texturemapblend();
9147 test_viewport_clear_rect();
9149 test_colorkey_precision();
9150 test_range_colorkey();