2 * Copyright 2005 Antoine Chavasse (a.chavasse@gmail.com)
3 * Copyright 2008, 2011, 2012-2014 Stefan Dösinger for CodeWeavers
4 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
27 static BOOL is_ddraw64
= sizeof(DWORD
) != sizeof(DWORD
*);
28 static DEVMODEW registry_mode
;
30 static HRESULT (WINAPI
*pDwmIsCompositionEnabled
)(BOOL
*);
32 struct create_window_thread_param
35 HANDLE window_created
;
36 HANDLE destroy_window
;
40 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
42 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
44 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
46 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
48 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
52 static IDirectDrawSurface
*create_overlay(IDirectDraw2
*ddraw
,
53 unsigned int width
, unsigned int height
, DWORD format
)
55 IDirectDrawSurface
*surface
;
58 memset(&desc
, 0, sizeof(desc
));
59 desc
.dwSize
= sizeof(desc
);
60 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
62 desc
.dwHeight
= height
;
63 desc
.ddsCaps
.dwCaps
= DDSCAPS_OVERLAY
;
64 desc
.ddpfPixelFormat
.dwSize
= sizeof(desc
.ddpfPixelFormat
);
65 desc
.ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
66 desc
.ddpfPixelFormat
.dwFourCC
= format
;
68 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &desc
, &surface
, NULL
)))
73 static DWORD WINAPI
create_window_thread_proc(void *param
)
75 struct create_window_thread_param
*p
= param
;
79 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
80 0, 0, 640, 480, 0, 0, 0, 0);
81 ret
= SetEvent(p
->window_created
);
82 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
88 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
89 DispatchMessageA(&msg
);
90 res
= WaitForSingleObject(p
->destroy_window
, 100);
91 if (res
== WAIT_OBJECT_0
)
93 if (res
!= WAIT_TIMEOUT
)
95 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
100 DestroyWindow(p
->window
);
105 static void create_window_thread(struct create_window_thread_param
*p
)
109 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
110 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
111 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
112 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
113 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
114 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
115 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
116 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
119 static void destroy_window_thread(struct create_window_thread_param
*p
)
121 SetEvent(p
->destroy_window
);
122 WaitForSingleObject(p
->thread
, INFINITE
);
123 CloseHandle(p
->destroy_window
);
124 CloseHandle(p
->window_created
);
125 CloseHandle(p
->thread
);
128 static IDirectDrawSurface
*get_depth_stencil(IDirect3DDevice2
*device
)
130 IDirectDrawSurface
*rt
, *ret
;
131 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
134 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
135 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
136 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ret
);
137 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
138 IDirectDrawSurface_Release(rt
);
142 static HRESULT
set_display_mode(IDirectDraw2
*ddraw
, DWORD width
, DWORD height
)
144 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
146 return IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
149 static D3DCOLOR
get_surface_color(IDirectDrawSurface
*surface
, UINT x
, UINT y
)
151 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
152 DDSURFACEDESC surface_desc
;
156 memset(&surface_desc
, 0, sizeof(surface_desc
));
157 surface_desc
.dwSize
= sizeof(surface_desc
);
159 hr
= IDirectDrawSurface_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
160 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
164 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
166 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
167 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
172 static DWORD
get_device_z_depth(IDirect3DDevice2
*device
)
174 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
175 IDirectDrawSurface
*ds
, *rt
;
179 if (FAILED(IDirect3DDevice2_GetRenderTarget(device
, &rt
)))
182 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ds
);
183 IDirectDrawSurface_Release(rt
);
187 desc
.dwSize
= sizeof(desc
);
188 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
189 IDirectDrawSurface_Release(ds
);
193 return U2(desc
).dwZBufferBitDepth
;
196 static IDirectDraw2
*create_ddraw(void)
198 IDirectDraw2
*ddraw2
;
202 if (FAILED(DirectDrawCreate(NULL
, &ddraw1
, NULL
)))
205 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw2
, (void **)&ddraw2
);
206 IDirectDraw_Release(ddraw1
);
213 static IDirect3DDevice2
*create_device(IDirectDraw2
*ddraw
, HWND window
, DWORD coop_level
)
215 static const DWORD z_depths
[] = {32, 24, 16};
216 IDirectDrawSurface
*surface
, *ds
;
217 IDirect3DDevice2
*device
= NULL
;
218 DDSURFACEDESC surface_desc
;
223 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, coop_level
);
224 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
226 memset(&surface_desc
, 0, sizeof(surface_desc
));
227 surface_desc
.dwSize
= sizeof(surface_desc
);
228 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
229 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
230 surface_desc
.dwWidth
= 640;
231 surface_desc
.dwHeight
= 480;
233 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
234 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
236 if (coop_level
& DDSCL_NORMAL
)
238 IDirectDrawClipper
*clipper
;
240 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
241 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
242 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
243 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
244 hr
= IDirectDrawSurface_SetClipper(surface
, clipper
);
245 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
246 IDirectDrawClipper_Release(clipper
);
249 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
252 IDirectDrawSurface_Release(surface
);
256 /* We used to use EnumDevices() for this, but it seems
257 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
258 * relationship with reality. */
259 for (i
= 0; i
< sizeof(z_depths
) / sizeof(*z_depths
); ++i
)
261 memset(&surface_desc
, 0, sizeof(surface_desc
));
262 surface_desc
.dwSize
= sizeof(surface_desc
);
263 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
264 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
265 U2(surface_desc
).dwZBufferBitDepth
= z_depths
[i
];
266 surface_desc
.dwWidth
= 640;
267 surface_desc
.dwHeight
= 480;
268 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
)))
271 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
272 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
273 IDirectDrawSurface_Release(ds
);
277 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
)))
280 IDirectDrawSurface_DeleteAttachedSurface(surface
, 0, ds
);
283 IDirect3D2_Release(d3d
);
284 IDirectDrawSurface_Release(surface
);
288 static IDirect3DViewport2
*create_viewport(IDirect3DDevice2
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
290 IDirect3DViewport2
*viewport
;
295 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
296 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
297 hr
= IDirect3D2_CreateViewport(d3d
, &viewport
, NULL
);
298 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
299 hr
= IDirect3DDevice2_AddViewport(device
, viewport
);
300 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
301 memset(&vp
, 0, sizeof(vp
));
302 vp
.dwSize
= sizeof(vp
);
309 vp
.dvClipWidth
= 2.0f
;
310 vp
.dvClipHeight
= 2.0f
;
313 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp
);
314 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
315 IDirect3D2_Release(d3d
);
320 static void viewport_set_background(IDirect3DDevice2
*device
, IDirect3DViewport2
*viewport
,
321 IDirect3DMaterial2
*material
)
323 D3DMATERIALHANDLE material_handle
;
326 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &material_handle
);
327 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
328 hr
= IDirect3DViewport2_SetBackground(viewport
, material_handle
);
329 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
332 static void destroy_viewport(IDirect3DDevice2
*device
, IDirect3DViewport2
*viewport
)
336 hr
= IDirect3DDevice2_DeleteViewport(device
, viewport
);
337 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
338 IDirect3DViewport2_Release(viewport
);
341 static IDirect3DMaterial2
*create_material(IDirect3DDevice2
*device
, D3DMATERIAL
*mat
)
343 IDirect3DMaterial2
*material
;
347 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
348 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
349 hr
= IDirect3D2_CreateMaterial(d3d
, &material
, NULL
);
350 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
351 hr
= IDirect3DMaterial2_SetMaterial(material
, mat
);
352 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
353 IDirect3D2_Release(d3d
);
358 static IDirect3DMaterial2
*create_diffuse_material(IDirect3DDevice2
*device
, float r
, float g
, float b
, float a
)
362 memset(&mat
, 0, sizeof(mat
));
363 mat
.dwSize
= sizeof(mat
);
364 U1(U(mat
).diffuse
).r
= r
;
365 U2(U(mat
).diffuse
).g
= g
;
366 U3(U(mat
).diffuse
).b
= b
;
367 U4(U(mat
).diffuse
).a
= a
;
369 return create_material(device
, &mat
);
372 static IDirect3DMaterial2
*create_specular_material(IDirect3DDevice2
*device
,
373 float r
, float g
, float b
, float a
, float power
)
377 memset(&mat
, 0, sizeof(mat
));
378 mat
.dwSize
= sizeof(mat
);
379 U1(U2(mat
).specular
).r
= r
;
380 U2(U2(mat
).specular
).g
= g
;
381 U3(U2(mat
).specular
).b
= b
;
382 U4(U2(mat
).specular
).a
= a
;
383 U4(mat
).power
= power
;
385 return create_material(device
, &mat
);
388 static IDirect3DMaterial2
*create_emissive_material(IDirect3DDevice2
*device
, float r
, float g
, float b
, float a
)
392 memset(&mat
, 0, sizeof(mat
));
393 mat
.dwSize
= sizeof(mat
);
394 U1(U3(mat
).emissive
).r
= r
;
395 U2(U3(mat
).emissive
).g
= g
;
396 U3(U3(mat
).emissive
).b
= b
;
397 U4(U3(mat
).emissive
).a
= a
;
399 return create_material(device
, &mat
);
402 static void destroy_material(IDirect3DMaterial2
*material
)
404 IDirect3DMaterial2_Release(material
);
411 WPARAM expect_wparam
;
414 static const struct message
*expect_messages
;
416 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
418 if (expect_messages
&& message
== expect_messages
->message
)
420 if (expect_messages
->check_wparam
)
421 ok (wparam
== expect_messages
->expect_wparam
,
422 "Got unexpected wparam %lx for message %x, expected %lx.\n",
423 wparam
, message
, expect_messages
->expect_wparam
);
428 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
431 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
432 * interface. This prevents subsequent SetCooperativeLevel() calls on a
433 * different window from failing with DDERR_HWNDALREADYSET. */
434 static void fix_wndproc(HWND window
, LONG_PTR proc
)
439 if (!(ddraw
= create_ddraw()))
442 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
443 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
444 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
445 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
446 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
448 IDirectDraw2_Release(ddraw
);
451 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
453 HRESULT hr
= IDirectDrawSurface_Restore(surface
);
454 ok(SUCCEEDED(hr
) || hr
== DDERR_IMPLICITLYCREATED
, "Failed to restore surface, hr %#x.\n", hr
);
455 IDirectDrawSurface_Release(surface
);
460 static HRESULT
restore_surfaces(IDirectDraw2
*ddraw
)
462 return IDirectDraw2_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
463 NULL
, NULL
, restore_callback
);
466 static void test_coop_level_create_device_window(void)
468 HWND focus_window
, device_window
;
472 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
473 0, 0, 640, 480, 0, 0, 0, 0);
474 ddraw
= create_ddraw();
475 ok(!!ddraw
, "Failed to create a ddraw object.\n");
477 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
478 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
479 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
480 ok(!device_window
, "Unexpected device window found.\n");
481 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
482 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
483 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
484 ok(!device_window
, "Unexpected device window found.\n");
485 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
486 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
487 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
488 ok(!device_window
, "Unexpected device window found.\n");
489 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
490 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
491 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
492 ok(!device_window
, "Unexpected device window found.\n");
493 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
494 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
495 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
496 ok(!device_window
, "Unexpected device window found.\n");
498 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
499 if (broken(hr
== DDERR_INVALIDPARAMS
))
501 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
502 IDirectDraw2_Release(ddraw
);
503 DestroyWindow(focus_window
);
507 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
508 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
509 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
510 ok(!device_window
, "Unexpected device window found.\n");
511 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
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");
516 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
517 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
518 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
519 ok(!device_window
, "Unexpected device window found.\n");
520 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
521 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
522 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
523 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
524 ok(!!device_window
, "Device window not found.\n");
526 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
527 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
528 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
529 ok(!device_window
, "Unexpected device window found.\n");
530 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
531 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
532 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
533 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
534 ok(!!device_window
, "Device window not found.\n");
536 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
537 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
538 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
539 ok(!device_window
, "Unexpected device window found.\n");
540 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
541 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
542 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
543 ok(!device_window
, "Unexpected device window found.\n");
544 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
545 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
546 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
547 ok(!device_window
, "Unexpected device window found.\n");
548 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
549 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
550 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
551 ok(!!device_window
, "Device window not found.\n");
553 IDirectDraw2_Release(ddraw
);
554 DestroyWindow(focus_window
);
557 static void test_clipper_blt(void)
559 IDirectDrawSurface
*src_surface
, *dst_surface
;
560 RECT client_rect
, src_rect
;
561 IDirectDrawClipper
*clipper
;
562 DDSURFACEDESC surface_desc
;
563 unsigned int i
, j
, x
, y
;
575 static const DWORD src_data
[] =
577 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
578 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
579 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
581 static const D3DCOLOR expected1
[] =
583 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
584 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
585 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
586 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
588 /* Nvidia on Windows seems to have an off-by-one error
589 * when processing source rectangles. Our left = 1 and
590 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
591 * read as well, but only for the edge pixels on the
592 * output image. The bug happens on the y axis as well,
593 * but we only read one row there, and all source rows
594 * contain the same data. This bug is not dependent on
595 * the presence of a clipper. */
596 static const D3DCOLOR expected1_broken
[] =
598 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
599 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
600 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
601 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
603 static const D3DCOLOR expected2
[] =
605 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
606 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
607 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
608 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
611 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
612 10, 10, 640, 480, 0, 0, 0, 0);
613 ShowWindow(window
, SW_SHOW
);
614 ddraw
= create_ddraw();
615 ok(!!ddraw
, "Failed to create a ddraw object.\n");
617 ret
= GetClientRect(window
, &client_rect
);
618 ok(ret
, "Failed to get client rect.\n");
619 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
620 ok(ret
, "Failed to map client rect.\n");
622 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
623 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
625 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
626 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
627 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
628 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
629 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
630 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
631 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
632 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
633 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
634 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
635 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
636 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
637 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
638 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
639 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
640 "Got unexpected bounding rect %s, expected %s.\n",
641 wine_dbgstr_rect(&rgn_data
->rdh
.rcBound
), wine_dbgstr_rect(&client_rect
));
642 HeapFree(GetProcessHeap(), 0, rgn_data
);
644 r1
= CreateRectRgn(0, 0, 320, 240);
645 ok(!!r1
, "Failed to create region.\n");
646 r2
= CreateRectRgn(320, 240, 640, 480);
647 ok(!!r2
, "Failed to create region.\n");
648 CombineRgn(r1
, r1
, r2
, RGN_OR
);
649 ret
= GetRegionData(r1
, 0, NULL
);
650 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
651 ret
= GetRegionData(r1
, ret
, rgn_data
);
652 ok(!!ret
, "Failed to get region data.\n");
657 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
658 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
659 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
660 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
661 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
662 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
664 HeapFree(GetProcessHeap(), 0, rgn_data
);
666 memset(&surface_desc
, 0, sizeof(surface_desc
));
667 surface_desc
.dwSize
= sizeof(surface_desc
);
668 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
669 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
670 surface_desc
.dwWidth
= 640;
671 surface_desc
.dwHeight
= 480;
672 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
673 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
674 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
675 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
676 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
677 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
679 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
680 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
681 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
682 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
684 memset(&fx
, 0, sizeof(fx
));
685 fx
.dwSize
= sizeof(fx
);
686 hr
= IDirectDrawSurface_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
687 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
688 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
689 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
691 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
692 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
693 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
694 ptr
= surface_desc
.lpSurface
;
695 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
696 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
697 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
698 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
699 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
701 hr
= IDirectDrawSurface_SetClipper(dst_surface
, clipper
);
702 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
704 SetRect(&src_rect
, 1, 1, 5, 2);
705 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
706 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
707 for (i
= 0; i
< 4; ++i
)
709 for (j
= 0; j
< 4; ++j
)
711 x
= 80 * ((2 * j
) + 1);
712 y
= 60 * ((2 * i
) + 1);
713 color
= get_surface_color(dst_surface
, x
, y
);
714 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
715 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
716 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
720 U5(fx
).dwFillColor
= 0xff0000ff;
721 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
722 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
723 for (i
= 0; i
< 4; ++i
)
725 for (j
= 0; j
< 4; ++j
)
727 x
= 80 * ((2 * j
) + 1);
728 y
= 60 * ((2 * i
) + 1);
729 color
= get_surface_color(dst_surface
, x
, y
);
730 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
731 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
735 hr
= IDirectDrawSurface_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
736 ok(hr
== DDERR_BLTFASTCANTCLIP
|| broken(hr
== E_NOTIMPL
/* NT4 */), "Got unexpected hr %#x.\n", hr
);
738 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
739 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
740 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
741 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
742 DestroyWindow(window
);
743 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
744 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
745 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
746 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
747 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
748 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
749 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
750 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
751 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
752 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
753 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
754 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
756 IDirectDrawSurface_Release(dst_surface
);
757 IDirectDrawSurface_Release(src_surface
);
758 refcount
= IDirectDrawClipper_Release(clipper
);
759 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
760 IDirectDraw2_Release(ddraw
);
763 static void test_coop_level_d3d_state(void)
765 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
766 IDirectDrawSurface
*rt
, *surface
;
767 IDirect3DMaterial2
*background
;
768 IDirect3DViewport2
*viewport
;
769 IDirect3DDevice2
*device
;
770 D3DMATERIAL material
;
777 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
778 0, 0, 640, 480, 0, 0, 0, 0);
779 ddraw
= create_ddraw();
780 ok(!!ddraw
, "Failed to create a ddraw object.\n");
781 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
783 skip("Failed to create a 3D device, skipping test.\n");
784 IDirectDraw2_Release(ddraw
);
785 DestroyWindow(window
);
789 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
790 viewport
= create_viewport(device
, 0, 0, 640, 480);
791 viewport_set_background(device
, viewport
, background
);
793 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
794 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
795 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
796 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
797 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
798 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
799 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
800 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
801 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
802 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
803 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
804 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
805 color
= get_surface_color(rt
, 320, 240);
806 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
808 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
809 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
810 hr
= IDirectDrawSurface_IsLost(rt
);
811 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
812 hr
= restore_surfaces(ddraw
);
813 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
815 memset(&material
, 0, sizeof(material
));
816 material
.dwSize
= sizeof(material
);
817 U1(U(material
).diffuse
).r
= 0.0f
;
818 U2(U(material
).diffuse
).g
= 1.0f
;
819 U3(U(material
).diffuse
).b
= 0.0f
;
820 U4(U(material
).diffuse
).a
= 1.0f
;
821 hr
= IDirect3DMaterial2_SetMaterial(background
, &material
);
822 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
824 hr
= IDirect3DDevice2_GetRenderTarget(device
, &surface
);
825 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
826 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
827 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
828 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
829 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
830 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
831 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
832 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
833 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
834 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
835 color
= get_surface_color(rt
, 320, 240);
836 ok(compare_color(color
, 0x0000ff00, 1) || broken(compare_color(color
, 0x00000000, 1)),
837 "Got unexpected color 0x%08x.\n", color
);
839 destroy_viewport(device
, viewport
);
840 destroy_material(background
);
841 IDirectDrawSurface_Release(surface
);
842 IDirectDrawSurface_Release(rt
);
843 IDirect3DDevice2_Release(device
);
844 IDirectDraw2_Release(ddraw
);
845 DestroyWindow(window
);
848 static void test_surface_interface_mismatch(void)
850 IDirectDraw2
*ddraw
= NULL
;
851 IDirect3D2
*d3d
= NULL
;
852 IDirectDrawSurface
*surface
= NULL
, *ds
;
853 IDirectDrawSurface3
*surface3
= NULL
;
854 IDirect3DDevice2
*device
= NULL
;
855 IDirect3DViewport2
*viewport
= NULL
;
856 IDirect3DMaterial2
*background
= NULL
;
857 DDSURFACEDESC surface_desc
;
863 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
865 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
866 0, 0, 640, 480, 0, 0, 0, 0);
867 ddraw
= create_ddraw();
868 ok(!!ddraw
, "Failed to create a ddraw object.\n");
869 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
871 skip("Failed to create a 3D device, skipping test.\n");
872 IDirectDraw2_Release(ddraw
);
873 DestroyWindow(window
);
876 z_depth
= get_device_z_depth(device
);
877 ok(!!z_depth
, "Failed to get device z depth.\n");
878 IDirect3DDevice2_Release(device
);
881 memset(&surface_desc
, 0, sizeof(surface_desc
));
882 surface_desc
.dwSize
= sizeof(surface_desc
);
883 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
884 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
885 surface_desc
.dwWidth
= 640;
886 surface_desc
.dwHeight
= 480;
888 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
889 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
891 hr
= IDirectDrawSurface2_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
894 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
898 if (FAILED(IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
)))
900 skip("D3D interface is not available, skipping test.\n");
904 memset(&surface_desc
, 0, sizeof(surface_desc
));
905 surface_desc
.dwSize
= sizeof(surface_desc
);
906 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
907 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
908 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
909 surface_desc
.dwWidth
= 640;
910 surface_desc
.dwHeight
= 480;
911 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
912 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
916 /* Using a different surface interface version still works */
917 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
918 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
919 refcount
= IDirectDrawSurface_Release(ds
);
920 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
925 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface
*)surface3
, &device
);
926 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
930 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
931 viewport
= create_viewport(device
, 0, 0, 640, 480);
932 viewport_set_background(device
, viewport
, background
);
934 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
935 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
936 color
= get_surface_color(surface
, 320, 240);
937 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
941 destroy_viewport(device
, viewport
);
943 destroy_material(background
);
944 if (surface3
) IDirectDrawSurface3_Release(surface3
);
945 if (surface
) IDirectDrawSurface_Release(surface
);
946 if (device
) IDirect3DDevice2_Release(device
);
947 if (d3d
) IDirect3D2_Release(d3d
);
948 if (ddraw
) IDirectDraw2_Release(ddraw
);
949 DestroyWindow(window
);
952 static void test_coop_level_threaded(void)
954 struct create_window_thread_param p
;
958 ddraw
= create_ddraw();
959 ok(!!ddraw
, "Failed to create a ddraw object.\n");
960 create_window_thread(&p
);
962 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
963 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
965 IDirectDraw2_Release(ddraw
);
966 destroy_window_thread(&p
);
969 static void test_depth_blit(void)
971 static D3DLVERTEX quad1
[] =
973 {{-1.0}, { 1.0}, {0.50f
}, 0, {0xff00ff00}},
974 {{ 1.0}, { 1.0}, {0.50f
}, 0, {0xff00ff00}},
975 {{-1.0}, {-1.0}, {0.50f
}, 0, {0xff00ff00}},
976 {{ 1.0}, {-1.0}, {0.50f
}, 0, {0xff00ff00}},
978 static const D3DCOLOR expected_colors
[4][4] =
980 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
981 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
982 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
983 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
985 DDSURFACEDESC ddsd_new
, ddsd_existing
;
987 IDirect3DDevice2
*device
;
988 IDirectDrawSurface
*ds1
, *ds2
, *ds3
, *rt
;
989 IDirect3DViewport2
*viewport
;
990 RECT src_rect
, dst_rect
;
998 IDirect3DMaterial2
*background
;
1000 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1001 0, 0, 640, 480, 0, 0, 0, 0);
1002 ddraw
= create_ddraw();
1003 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1004 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1006 skip("Failed to create a 3D device, skipping test.\n");
1007 IDirectDraw2_Release(ddraw
);
1008 DestroyWindow(window
);
1012 ds1
= get_depth_stencil(device
);
1014 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1015 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1016 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1017 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1018 hr
= IDirectDrawSurface_GetSurfaceDesc(ds1
, &ddsd_existing
);
1019 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
1020 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1021 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1022 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1023 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1024 ddsd_new
.ddpfPixelFormat
= ddsd_existing
.ddpfPixelFormat
;
1025 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1026 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1027 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1028 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1030 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1031 viewport
= create_viewport(device
, 0, 0, ddsd_existing
.dwWidth
, ddsd_existing
.dwHeight
);
1032 viewport_set_background(device
, viewport
, background
);
1033 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1034 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
1036 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1037 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1038 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1039 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1041 U1(d3drect
).x1
= U2(d3drect
).y1
= 0;
1042 U3(d3drect
).x2
= ddsd_existing
.dwWidth
; U4(d3drect
).y2
= ddsd_existing
.dwHeight
;
1043 hr
= IDirect3DViewport2_Clear(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
);
1044 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1047 SetRect(&src_rect
, 0, 0, 320, 240);
1048 SetRect(&dst_rect
, 0, 0, 320, 240);
1049 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1050 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1051 /* Different locations. */
1052 SetRect(&src_rect
, 0, 0, 320, 240);
1053 SetRect(&dst_rect
, 320, 240, 640, 480);
1054 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1055 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1057 SetRect(&src_rect
, 0, 0, 320, 240);
1058 SetRect(&dst_rect
, 0, 0, 640, 480);
1059 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1060 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1062 SetRect(&src_rect
, 0, 480, 640, 0);
1063 SetRect(&dst_rect
, 0, 0, 640, 480);
1064 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1065 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1066 SetRect(&src_rect
, 0, 0, 640, 480);
1067 SetRect(&dst_rect
, 0, 480, 640, 0);
1068 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1069 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1070 /* Full, explicit. */
1071 SetRect(&src_rect
, 0, 0, 640, 480);
1072 SetRect(&dst_rect
, 0, 0, 640, 480);
1073 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1074 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1075 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1077 /* Depth blit inside a BeginScene / EndScene pair */
1078 hr
= IDirect3DDevice2_BeginScene(device
);
1079 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1080 /* From the current depth stencil */
1081 hr
= IDirectDrawSurface_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1082 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1083 /* To the current depth stencil */
1084 hr
= IDirectDrawSurface_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1085 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1086 /* Between unbound surfaces */
1087 hr
= IDirectDrawSurface_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1088 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1089 hr
= IDirect3DDevice2_EndScene(device
);
1090 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1092 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1093 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1094 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1095 * a reliable result(z = 0.0) */
1096 memset(&fx
, 0, sizeof(fx
));
1097 fx
.dwSize
= sizeof(fx
);
1098 U5(fx
).dwFillDepth
= 0;
1099 hr
= IDirectDrawSurface_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1100 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1102 /* This clears the Z buffer with 1.0 */
1103 hr
= IDirect3DViewport2_Clear(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
);
1104 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1106 SetRect(&dst_rect
, 0, 0, 320, 240);
1107 hr
= IDirectDrawSurface_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1108 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1109 IDirectDrawSurface_Release(ds3
);
1110 IDirectDrawSurface_Release(ds2
);
1111 IDirectDrawSurface_Release(ds1
);
1113 hr
= IDirect3DDevice2_BeginScene(device
);
1114 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1115 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad1
, 4, 0);
1116 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1117 hr
= IDirect3DDevice2_EndScene(device
);
1118 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1120 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1121 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1122 for (i
= 0; i
< 4; ++i
)
1124 for (j
= 0; j
< 4; ++j
)
1126 unsigned int x
= 80 * ((2 * j
) + 1);
1127 unsigned int y
= 60 * ((2 * i
) + 1);
1128 color
= get_surface_color(rt
, x
, y
);
1129 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1130 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1133 IDirectDrawSurface_Release(rt
);
1135 destroy_viewport(device
, viewport
);
1136 destroy_material(background
);
1137 IDirect3DDevice2_Release(device
);
1138 IDirectDraw2_Release(ddraw
);
1139 DestroyWindow(window
);
1142 static void test_texture_load_ckey(void)
1144 IDirectDraw2
*ddraw
= NULL
;
1145 IDirectDrawSurface
*src
= NULL
;
1146 IDirectDrawSurface
*dst
= NULL
;
1147 IDirect3DTexture
*src_tex
= NULL
;
1148 IDirect3DTexture
*dst_tex
= NULL
;
1153 ddraw
= create_ddraw();
1154 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1155 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
1156 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1158 memset(&ddsd
, 0, sizeof(ddsd
));
1159 ddsd
.dwSize
= sizeof(ddsd
);
1160 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1161 ddsd
.dwHeight
= 128;
1163 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1164 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1165 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1166 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1167 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1168 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1170 hr
= IDirectDrawSurface_QueryInterface(src
, &IID_IDirect3DTexture
, (void **)&src_tex
);
1171 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get Direct3DTexture interface, hr %#x.\n", hr
);
1174 /* 64 bit ddraw does not support d3d */
1175 skip("Could not get Direct3DTexture interface, skipping texture::Load color keying tests.\n");
1178 hr
= IDirectDrawSurface_QueryInterface(dst
, &IID_IDirect3DTexture
, (void **)&dst_tex
);
1179 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture interface, hr %#x.\n", hr
);
1181 /* No surface has a color key */
1182 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1183 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDCAPS
), "Got unexpected hr %#x.\n", hr
);
1186 /* Testbot Windows NT VMs */
1187 skip("IDirect3DTexture::Load does not work, skipping color keying tests.\n");
1191 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1192 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1193 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1194 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1195 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1197 /* Source surface has a color key */
1198 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1199 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1200 ok(SUCCEEDED(hr
), "Failed to set color key, 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
);
1208 /* Both surfaces have a color key: Dest ckey is overwritten */
1209 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1210 hr
= IDirectDrawSurface_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1211 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1212 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1213 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1214 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1215 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1216 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1217 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1219 /* Only the destination has a color key: It is not deleted */
1220 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1221 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1222 hr
= IDirectDrawSurface_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1223 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1224 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1225 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1226 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1227 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1228 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1229 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1232 if (dst_tex
) IDirect3DTexture_Release(dst_tex
);
1233 if (src_tex
) IDirect3DTexture_Release(src_tex
);
1234 if (dst
) IDirectDrawSurface_Release(dst
);
1235 if (src
) IDirectDrawSurface_Release(src
);
1236 if (ddraw
) IDirectDraw2_Release(ddraw
);
1239 static ULONG
get_refcount(IUnknown
*test_iface
)
1241 IUnknown_AddRef(test_iface
);
1242 return IUnknown_Release(test_iface
);
1245 static void test_viewport(void)
1247 IDirectDraw2
*ddraw
;
1250 ULONG ref
, old_d3d_ref
;
1251 IDirect3DViewport
*viewport
;
1252 IDirect3DViewport2
*viewport2
, *another_vp
, *test_vp
;
1253 IDirect3DViewport3
*viewport3
;
1254 IDirectDrawGammaControl
*gamma
;
1256 IDirect3DDevice2
*device
;
1259 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1260 0, 0, 640, 480, 0, 0, 0, 0);
1261 ddraw
= create_ddraw();
1262 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1263 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1265 skip("Failed to create a 3D device, skipping test.\n");
1266 IDirectDraw_Release(ddraw
);
1267 DestroyWindow(window
);
1271 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
1272 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get d3d interface, hr %#x.\n", hr
);
1275 skip("D3D interface is not available, skipping test.\n");
1276 IDirectDraw2_Release(ddraw
);
1279 old_d3d_ref
= get_refcount((IUnknown
*)d3d
);
1281 hr
= IDirect3D2_CreateViewport(d3d
, &viewport2
, NULL
);
1282 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1283 ref
= get_refcount((IUnknown
*)viewport2
);
1284 ok(ref
== 1, "Initial IDirect3DViewport2 refcount is %u\n", ref
);
1285 ref
= get_refcount((IUnknown
*)d3d
);
1286 ok(ref
== old_d3d_ref
, "IDirect3D2 refcount is %u\n", ref
);
1288 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1289 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1290 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
1291 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1292 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1293 /* NULL iid: Segfaults */
1295 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirect3DViewport
, (void **)&viewport
);
1296 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport, hr %#x.\n", hr
);
1299 ref
= get_refcount((IUnknown
*)viewport
);
1300 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1301 ref
= get_refcount((IUnknown
*)viewport2
);
1302 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1303 IDirect3DViewport_Release(viewport
);
1307 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirect3DViewport3
, (void **)&viewport3
);
1308 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1311 ref
= get_refcount((IUnknown
*)viewport2
);
1312 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1313 ref
= get_refcount((IUnknown
*)viewport3
);
1314 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1315 IDirect3DViewport3_Release(viewport3
);
1318 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IUnknown
, (void **)&unknown
);
1319 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1322 ref
= get_refcount((IUnknown
*)viewport2
);
1323 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1324 ref
= get_refcount(unknown
);
1325 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1326 IUnknown_Release(unknown
);
1329 /* AddViewport(NULL): Segfault */
1330 hr
= IDirect3DDevice2_DeleteViewport(device
, NULL
);
1331 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1332 hr
= IDirect3DDevice2_GetCurrentViewport(device
, NULL
);
1333 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1335 hr
= IDirect3D2_CreateViewport(d3d
, &another_vp
, NULL
);
1336 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1338 /* Setting a viewport not in the viewport list fails */
1339 hr
= IDirect3DDevice2_SetCurrentViewport(device
, another_vp
);
1340 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1342 hr
= IDirect3DDevice2_AddViewport(device
, viewport2
);
1343 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1344 ref
= get_refcount((IUnknown
*) viewport2
);
1345 ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1346 hr
= IDirect3DDevice2_AddViewport(device
, another_vp
);
1347 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1348 ref
= get_refcount((IUnknown
*) another_vp
);
1349 ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1351 test_vp
= (IDirect3DViewport2
*) 0xbaadc0de;
1352 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1353 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1354 ok(test_vp
== (IDirect3DViewport2
*) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp
);
1356 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
1357 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1358 ref
= get_refcount((IUnknown
*) viewport2
);
1359 ok(ref
== 3, "viewport2 refcount is %d\n", ref
);
1360 ref
= get_refcount((IUnknown
*) device
);
1361 ok(ref
== 1, "device refcount is %d\n", ref
);
1364 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1365 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1366 ok(test_vp
== viewport2
, "Got unexpected viewport %p\n", test_vp
);
1367 ref
= get_refcount((IUnknown
*) viewport2
);
1368 ok(ref
== 4, "viewport2 refcount is %d\n", ref
);
1369 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1371 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1373 /* Cannot set the viewport to NULL */
1374 hr
= IDirect3DDevice2_SetCurrentViewport(device
, NULL
);
1375 ok(hr
== DDERR_INVALIDPARAMS
, "Failed to set viewport to NULL, hr %#x.\n", hr
);
1377 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1378 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1379 ok(test_vp
== viewport2
, "Got unexpected viewport %p\n", test_vp
);
1380 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1382 /* SetCurrentViewport properly releases the old viewport's reference */
1383 hr
= IDirect3DDevice2_SetCurrentViewport(device
, another_vp
);
1384 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1385 ref
= get_refcount((IUnknown
*) viewport2
);
1386 ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1387 ref
= get_refcount((IUnknown
*) another_vp
);
1388 ok(ref
== 3, "another_vp refcount is %d\n", ref
);
1390 /* Deleting the viewport removes the reference added by AddViewport, but not
1391 * the one added by SetCurrentViewport. */
1392 hr
= IDirect3DDevice2_DeleteViewport(device
, another_vp
);
1393 ok(SUCCEEDED(hr
), "Failed to delete viewport from device, hr %#x.\n", hr
);
1394 ref
= get_refcount((IUnknown
*) another_vp
);
1395 todo_wine
ok(ref
== 2, "IDirect3DViewport2 refcount is %d\n", ref
);
1397 /* GetCurrentViewport fails though */
1399 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1400 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1401 ok(test_vp
== NULL
, "Got unexpected viewport %p\n", test_vp
);
1402 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1404 /* Setting a different viewport does not free the leaked reference. How
1405 * do I get rid of it? Leak the viewport for now. */
1406 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
1407 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1408 ref
= get_refcount((IUnknown
*) viewport2
);
1409 ok(ref
== 3, "viewport2 refcount is %d\n", ref
);
1410 ref
= get_refcount((IUnknown
*) another_vp
);
1411 todo_wine
ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1413 /* Destroying the device removes the viewport, but does not free the reference
1414 * added by SetCurrentViewport. */
1415 IDirect3DDevice2_Release(device
);
1416 ref
= get_refcount((IUnknown
*) viewport2
);
1417 todo_wine
ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1419 IDirect3DViewport2_Release(another_vp
);
1420 IDirect3DViewport2_Release(viewport2
);
1421 IDirect3D2_Release(d3d
);
1422 DestroyWindow(window
);
1423 IDirectDraw2_Release(ddraw
);
1426 static void test_zenable(void)
1428 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1429 static D3DTLVERTEX tquad
[] =
1431 {{ 0.0f
}, {480.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1432 {{ 0.0f
}, { 0.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1433 {{640.0f
}, {480.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1434 {{640.0f
}, { 0.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1436 IDirect3DMaterial2
*background
;
1437 IDirect3DViewport2
*viewport
;
1438 IDirect3DDevice2
*device
;
1439 IDirectDrawSurface
*rt
;
1440 IDirectDraw2
*ddraw
;
1447 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1448 0, 0, 640, 480, 0, 0, 0, 0);
1449 ddraw
= create_ddraw();
1450 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1451 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1453 skip("Failed to create a 3D device, skipping test.\n");
1454 IDirectDraw2_Release(ddraw
);
1455 DestroyWindow(window
);
1459 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1460 viewport
= create_viewport(device
, 0, 0, 640, 480);
1461 viewport_set_background(device
, viewport
, background
);
1462 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1463 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1465 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1466 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1468 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1469 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1470 hr
= IDirect3DDevice2_BeginScene(device
);
1471 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1472 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, tquad
, 4, 0);
1473 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1474 hr
= IDirect3DDevice2_EndScene(device
);
1475 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1477 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1478 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1479 for (i
= 0; i
< 4; ++i
)
1481 for (j
= 0; j
< 4; ++j
)
1483 x
= 80 * ((2 * j
) + 1);
1484 y
= 60 * ((2 * i
) + 1);
1485 color
= get_surface_color(rt
, x
, y
);
1486 ok(compare_color(color
, 0x0000ff00, 1),
1487 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1490 IDirectDrawSurface_Release(rt
);
1492 destroy_viewport(device
, viewport
);
1493 destroy_material(background
);
1494 IDirect3DDevice2_Release(device
);
1495 IDirectDraw2_Release(ddraw
);
1496 DestroyWindow(window
);
1499 static void test_ck_rgba(void)
1501 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1502 static D3DTLVERTEX tquad
[] =
1504 {{ 0.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1505 {{ 0.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1506 {{640.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1507 {{640.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1508 {{ 0.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1509 {{ 0.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1510 {{640.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1511 {{640.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1515 D3DCOLOR fill_color
;
1518 D3DCOLOR result1
, result1_broken
;
1519 D3DCOLOR result2
, result2_broken
;
1523 /* r200 on Windows doesn't check the alpha component when applying the color
1524 * key, so the key matches on every texel. */
1525 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1526 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1527 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1528 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1529 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1530 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1531 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1532 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1535 D3DTEXTUREHANDLE texture_handle
;
1536 IDirect3DMaterial2
*background
;
1537 IDirectDrawSurface
*surface
;
1538 IDirect3DViewport2
*viewport
;
1539 IDirect3DTexture2
*texture
;
1540 DDSURFACEDESC surface_desc
;
1541 IDirect3DDevice2
*device
;
1542 IDirectDrawSurface
*rt
;
1543 IDirectDraw2
*ddraw
;
1550 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1551 0, 0, 640, 480, 0, 0, 0, 0);
1552 ddraw
= create_ddraw();
1553 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1554 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1556 skip("Failed to create a 3D device, skipping test.\n");
1557 IDirectDraw2_Release(ddraw
);
1558 DestroyWindow(window
);
1562 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1563 viewport
= create_viewport(device
, 0, 0, 640, 480);
1564 viewport_set_background(device
, viewport
, background
);
1565 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1566 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1568 memset(&surface_desc
, 0, sizeof(surface_desc
));
1569 surface_desc
.dwSize
= sizeof(surface_desc
);
1570 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1571 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1572 surface_desc
.dwWidth
= 256;
1573 surface_desc
.dwHeight
= 256;
1574 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1575 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1576 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1577 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1578 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1579 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1580 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1581 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1582 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1583 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1584 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1585 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1586 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1587 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
1588 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1589 IDirect3DTexture2_Release(texture
);
1591 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1592 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1593 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1594 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1595 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1596 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1598 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1599 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1601 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1603 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1604 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1605 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1606 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1608 memset(&fx
, 0, sizeof(fx
));
1609 fx
.dwSize
= sizeof(fx
);
1610 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1611 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1612 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1614 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
1615 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1616 hr
= IDirect3DDevice2_BeginScene(device
);
1617 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1618 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1619 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1620 hr
= IDirect3DDevice2_EndScene(device
);
1621 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1623 color
= get_surface_color(rt
, 320, 240);
1624 ok(compare_color(color
, tests
[i
].result1
, 1) || compare_color(color
, tests
[i
].result1_broken
, 1),
1625 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1626 tests
[i
].result1
, i
, color
);
1628 U5(fx
).dwFillColor
= 0xff0000ff;
1629 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1630 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1632 hr
= IDirect3DDevice2_BeginScene(device
);
1633 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1634 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[4], 4, 0);
1635 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1636 hr
= IDirect3DDevice2_EndScene(device
);
1637 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1639 /* This tests that fragments that are masked out by the color key are
1640 * discarded, instead of just fully transparent. */
1641 color
= get_surface_color(rt
, 320, 240);
1642 ok(compare_color(color
, tests
[i
].result2
, 1) || compare_color(color
, tests
[i
].result2_broken
, 1),
1643 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1644 tests
[i
].result2
, i
, color
);
1647 IDirectDrawSurface_Release(rt
);
1648 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1649 ok(SUCCEEDED(hr
), "Failed to unset texture, hr %#x.\n", hr
);
1650 IDirectDrawSurface_Release(surface
);
1651 destroy_viewport(device
, viewport
);
1652 destroy_material(background
);
1653 IDirect3DDevice2_Release(device
);
1654 IDirectDraw2_Release(ddraw
);
1655 DestroyWindow(window
);
1658 static void test_ck_default(void)
1660 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1661 static D3DTLVERTEX tquad
[] =
1663 {{ 0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1664 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1665 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1666 {{640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1668 IDirectDrawSurface
*surface
, *rt
;
1669 D3DTEXTUREHANDLE texture_handle
;
1670 IDirect3DMaterial2
*background
;
1671 IDirect3DViewport2
*viewport
;
1672 DDSURFACEDESC surface_desc
;
1673 IDirect3DTexture2
*texture
;
1674 IDirect3DDevice2
*device
;
1675 IDirectDraw2
*ddraw
;
1682 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1683 0, 0, 640, 480, 0, 0, 0, 0);
1684 ddraw
= create_ddraw();
1685 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1686 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1688 skip("Failed to create a 3D device, skipping test.\n");
1689 IDirectDraw2_Release(ddraw
);
1690 DestroyWindow(window
);
1694 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1695 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1697 background
= create_diffuse_material(device
, 0.0, 1.0f
, 0.0f
, 1.0f
);
1698 viewport
= create_viewport(device
, 0, 0, 640, 480);
1699 viewport_set_background(device
, viewport
, background
);
1700 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1701 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1703 memset(&surface_desc
, 0, sizeof(surface_desc
));
1704 surface_desc
.dwSize
= sizeof(surface_desc
);
1705 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1706 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1707 surface_desc
.dwWidth
= 256;
1708 surface_desc
.dwHeight
= 256;
1709 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1710 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1711 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1712 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1713 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1714 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1715 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1716 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1717 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1718 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1719 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1720 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1721 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
1722 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1723 IDirect3DTexture_Release(texture
);
1725 memset(&fx
, 0, sizeof(fx
));
1726 fx
.dwSize
= sizeof(fx
);
1727 U5(fx
).dwFillColor
= 0x000000ff;
1728 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1729 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1731 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1732 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1733 hr
= IDirect3DDevice2_BeginScene(device
);
1734 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1735 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1736 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
1737 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1738 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1739 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1740 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1741 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1742 hr
= IDirect3DDevice2_EndScene(device
);
1743 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1744 color
= get_surface_color(rt
, 320, 240);
1745 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1747 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1748 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1749 hr
= IDirect3DDevice2_BeginScene(device
);
1750 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1751 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1752 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1753 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1754 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1755 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1756 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1757 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1758 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1759 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
1760 hr
= IDirect3DDevice2_EndScene(device
);
1761 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1762 color
= get_surface_color(rt
, 320, 240);
1763 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1765 IDirectDrawSurface_Release(surface
);
1766 destroy_viewport(device
, viewport
);
1767 destroy_material(background
);
1768 IDirectDrawSurface_Release(rt
);
1769 IDirect3DDevice2_Release(device
);
1770 IDirectDraw2_Release(ddraw
);
1771 DestroyWindow(window
);
1774 static void test_ck_complex(void)
1776 IDirectDrawSurface
*surface
, *mipmap
, *tmp
;
1777 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
1778 DDSURFACEDESC surface_desc
;
1779 IDirect3DDevice2
*device
;
1780 DDCOLORKEY color_key
;
1781 IDirectDraw2
*ddraw
;
1787 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1788 0, 0, 640, 480, 0, 0, 0, 0);
1789 ddraw
= create_ddraw();
1790 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1791 if (!(device
= create_device(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1793 skip("Failed to create a 3D device, skipping test.\n");
1794 DestroyWindow(window
);
1795 IDirectDraw2_Release(ddraw
);
1798 IDirect3DDevice2_Release(device
);
1800 memset(&surface_desc
, 0, sizeof(surface_desc
));
1801 surface_desc
.dwSize
= sizeof(surface_desc
);
1802 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1803 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1804 surface_desc
.dwWidth
= 128;
1805 surface_desc
.dwHeight
= 128;
1806 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1807 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1809 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1810 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1811 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1812 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1813 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1814 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1815 memset(&color_key
, 0, sizeof(color_key
));
1816 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1817 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1818 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1819 color_key
.dwColorSpaceLowValue
);
1820 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1821 color_key
.dwColorSpaceHighValue
);
1824 IDirectDrawSurface_AddRef(mipmap
);
1825 for (i
= 0; i
< 7; ++i
)
1827 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1828 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1830 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1831 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1832 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1833 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1834 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1835 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x, i %u.\n", hr
, i
);
1836 memset(&color_key
, 0, sizeof(color_key
));
1837 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1838 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x, i %u.\n", hr
, i
);
1839 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1840 color_key
.dwColorSpaceLowValue
, i
);
1841 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1842 color_key
.dwColorSpaceHighValue
, i
);
1844 IDirectDrawSurface_Release(mipmap
);
1848 memset(&color_key
, 0, sizeof(color_key
));
1849 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1850 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1851 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1852 color_key
.dwColorSpaceLowValue
);
1853 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1854 color_key
.dwColorSpaceHighValue
);
1856 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1857 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1858 IDirectDrawSurface_Release(mipmap
);
1859 refcount
= IDirectDrawSurface_Release(surface
);
1860 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1862 memset(&surface_desc
, 0, sizeof(surface_desc
));
1863 surface_desc
.dwSize
= sizeof(surface_desc
);
1864 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1865 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1866 surface_desc
.dwBackBufferCount
= 1;
1867 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1868 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1870 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1871 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1872 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1873 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1874 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1875 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1876 memset(&color_key
, 0, sizeof(color_key
));
1877 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1878 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1879 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1880 color_key
.dwColorSpaceLowValue
);
1881 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1882 color_key
.dwColorSpaceHighValue
);
1884 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
1885 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
1887 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1888 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1889 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1890 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1891 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1892 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1893 memset(&color_key
, 0, sizeof(color_key
));
1894 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1895 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1896 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1897 color_key
.dwColorSpaceLowValue
);
1898 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1899 color_key
.dwColorSpaceHighValue
);
1901 IDirectDrawSurface_Release(tmp
);
1903 refcount
= IDirectDrawSurface_Release(surface
);
1904 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1905 refcount
= IDirectDraw2_Release(ddraw
);
1906 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1907 DestroyWindow(window
);
1913 REFIID refcount_iid
;
1917 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
1918 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
1920 ULONG refcount
, expected_refcount
;
1921 IUnknown
*iface1
, *iface2
;
1925 for (i
= 0; i
< entry_count
; ++i
)
1927 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
1928 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
1931 for (j
= 0; j
< entry_count
; ++j
)
1933 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
1934 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
1937 expected_refcount
= 0;
1938 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
1939 ++expected_refcount
;
1940 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
1941 ++expected_refcount
;
1942 refcount
= IUnknown_Release(iface2
);
1943 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1944 refcount
, test_name
, i
, j
, expected_refcount
);
1948 expected_refcount
= 0;
1949 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
1950 ++expected_refcount
;
1951 refcount
= IUnknown_Release(iface1
);
1952 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1953 refcount
, test_name
, i
, expected_refcount
);
1958 static void test_surface_qi(void)
1960 static const struct qi_test tests
[] =
1962 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface
, S_OK
},
1963 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface
, S_OK
},
1964 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1965 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1966 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1967 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1968 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1969 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1970 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1971 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
1972 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
1973 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
1974 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
1975 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
1976 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
1977 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
1978 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
1979 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
1980 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
1981 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
1982 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
1983 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
1984 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
1985 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
1986 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
1987 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
1988 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
1989 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
1990 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
1991 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
1992 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
1993 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
1994 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
1995 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
1996 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1999 IDirectDrawSurface
*surface
;
2000 DDSURFACEDESC surface_desc
;
2001 IDirect3DDevice2
*device
;
2002 IDirectDraw2
*ddraw
;
2006 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2008 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2012 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2013 0, 0, 640, 480, 0, 0, 0, 0);
2014 ddraw
= create_ddraw();
2015 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2016 /* Try to create a D3D device to see if the ddraw implementation supports
2017 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2018 * doesn't support e.g. the IDirect3DTexture interfaces. */
2019 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
2021 skip("Failed to create a 3D device, skipping test.\n");
2022 IDirectDraw2_Release(ddraw
);
2023 DestroyWindow(window
);
2026 IDirect3DDevice_Release(device
);
2028 memset(&surface_desc
, 0, sizeof(surface_desc
));
2029 surface_desc
.dwSize
= sizeof(surface_desc
);
2030 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2031 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2032 surface_desc
.dwWidth
= 512;
2033 surface_desc
.dwHeight
= 512;
2034 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2035 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2037 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface
, tests
, sizeof(tests
) / sizeof(*tests
));
2039 IDirectDrawSurface_Release(surface
);
2040 IDirectDraw2_Release(ddraw
);
2041 DestroyWindow(window
);
2044 static void test_device_qi(void)
2046 static const struct qi_test tests
[] =
2048 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
2049 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
2050 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
2051 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2052 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
2053 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
2054 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
2055 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
2056 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
2057 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
2058 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
2059 {&IID_IDirect3DDevice2
, &IID_IDirect3DDevice2
, S_OK
},
2060 {&IID_IDirect3DDevice
, &IID_IDirect3DDevice2
, S_OK
},
2061 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
2062 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
2063 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
2064 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
2065 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
2066 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
2067 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
2068 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
2069 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
2070 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
2071 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
2072 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
2073 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
2074 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
2075 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
2076 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
2077 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
2078 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
2079 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
2080 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
2081 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
2082 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
2083 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
2084 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
2085 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
2086 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
2087 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
2088 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
2089 {&IID_IUnknown
, &IID_IDirect3DDevice2
, S_OK
},
2092 IDirect3DDevice2
*device
;
2093 IDirectDraw2
*ddraw
;
2096 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2097 0, 0, 640, 480, 0, 0, 0, 0);
2098 ddraw
= create_ddraw();
2099 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2100 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
2102 skip("Failed to create a 3D device, skipping test.\n");
2103 IDirectDraw2_Release(ddraw
);
2104 DestroyWindow(window
);
2108 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice2
, tests
, sizeof(tests
) / sizeof(*tests
));
2110 IDirect3DDevice2_Release(device
);
2111 IDirectDraw2_Release(ddraw
);
2112 DestroyWindow(window
);
2115 static void test_wndproc(void)
2117 LONG_PTR proc
, ddraw_proc
;
2118 IDirectDraw2
*ddraw
;
2124 static struct message messages
[] =
2126 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2127 {WM_MOVE
, FALSE
, 0},
2128 {WM_SIZE
, FALSE
, 0},
2129 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2130 {WM_ACTIVATE
, FALSE
, 0},
2131 {WM_SETFOCUS
, FALSE
, 0},
2135 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2136 ddraw
= create_ddraw();
2137 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2139 wc
.lpfnWndProc
= test_proc
;
2140 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2141 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2143 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2144 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2146 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2147 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2148 (LONG_PTR
)test_proc
, proc
);
2149 expect_messages
= messages
;
2150 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2151 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2152 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2153 expect_messages
= NULL
;
2154 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2155 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2156 (LONG_PTR
)test_proc
, proc
);
2157 ref
= IDirectDraw2_Release(ddraw
);
2158 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2159 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2160 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2161 (LONG_PTR
)test_proc
, proc
);
2163 /* DDSCL_NORMAL doesn't. */
2164 ddraw
= create_ddraw();
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
);
2168 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2169 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2170 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2171 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2172 (LONG_PTR
)test_proc
, proc
);
2173 ref
= IDirectDraw2_Release(ddraw
);
2174 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2175 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2176 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2177 (LONG_PTR
)test_proc
, proc
);
2179 /* The original window proc is only restored by ddraw if the current
2180 * window proc matches the one ddraw set. This also affects switching
2181 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2182 ddraw
= create_ddraw();
2183 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2184 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2185 (LONG_PTR
)test_proc
, proc
);
2186 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2187 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2188 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2189 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2190 (LONG_PTR
)test_proc
, proc
);
2192 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2193 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2194 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2195 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2196 (LONG_PTR
)test_proc
, proc
);
2197 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2198 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2199 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2200 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2201 (LONG_PTR
)test_proc
, proc
);
2202 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2203 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2204 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2205 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2206 (LONG_PTR
)DefWindowProcA
, proc
);
2207 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2208 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2209 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2210 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2211 (LONG_PTR
)DefWindowProcA
, proc
);
2212 ref
= IDirectDraw2_Release(ddraw
);
2213 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2214 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2215 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2216 (LONG_PTR
)test_proc
, proc
);
2218 ddraw
= create_ddraw();
2219 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2220 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2221 (LONG_PTR
)test_proc
, proc
);
2222 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2223 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2224 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2225 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2226 (LONG_PTR
)test_proc
, proc
);
2227 ref
= IDirectDraw2_Release(ddraw
);
2228 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2229 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2230 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2231 (LONG_PTR
)DefWindowProcA
, proc
);
2233 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2234 expect_messages
= NULL
;
2235 DestroyWindow(window
);
2236 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2239 static void test_window_style(void)
2241 LONG style
, exstyle
, tmp
, expected_style
;
2242 RECT fullscreen_rect
, r
;
2243 IDirectDraw2
*ddraw
;
2249 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2250 0, 0, 100, 100, 0, 0, 0, 0);
2251 ddraw
= create_ddraw();
2252 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2254 style
= GetWindowLongA(window
, GWL_STYLE
);
2255 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2256 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2258 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2259 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2261 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2262 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2263 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2264 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2266 GetWindowRect(window
, &r
);
2267 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
2268 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
2269 GetClientRect(window
, &r
);
2270 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2272 ret
= SetForegroundWindow(GetDesktopWindow());
2273 ok(ret
, "Failed to set foreground window.\n");
2275 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2276 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2277 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2278 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2280 ret
= SetForegroundWindow(window
);
2281 ok(ret
, "Failed to set foreground window.\n");
2282 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2283 * the next tests expect this. */
2284 ShowWindow(window
, SW_HIDE
);
2286 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2287 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2289 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2290 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2291 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2292 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2294 ShowWindow(window
, SW_SHOW
);
2295 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2296 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2298 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2299 expected_style
= style
| WS_VISIBLE
;
2300 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2301 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2302 expected_style
= exstyle
| WS_EX_TOPMOST
;
2303 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2305 ret
= SetForegroundWindow(GetDesktopWindow());
2306 ok(ret
, "Failed to set foreground window.\n");
2307 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2308 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2309 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2310 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2311 expected_style
= exstyle
| WS_EX_TOPMOST
;
2312 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2314 ref
= IDirectDraw2_Release(ddraw
);
2315 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2317 DestroyWindow(window
);
2320 static void test_redundant_mode_set(void)
2322 DDSURFACEDESC surface_desc
= {0};
2323 IDirectDraw2
*ddraw
;
2329 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2330 0, 0, 100, 100, 0, 0, 0, 0);
2331 ddraw
= create_ddraw();
2332 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2334 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2335 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2337 surface_desc
.dwSize
= sizeof(surface_desc
);
2338 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
2339 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
2341 hr
= IDirectDraw2_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2342 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2343 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2345 GetWindowRect(window
, &r
);
2348 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2349 GetWindowRect(window
, &s
);
2350 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2352 hr
= IDirectDraw2_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2353 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2354 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2356 GetWindowRect(window
, &s
);
2357 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2359 ref
= IDirectDraw2_Release(ddraw
);
2360 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2362 DestroyWindow(window
);
2365 static SIZE screen_size
, screen_size2
;
2367 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2369 if (message
== WM_SIZE
)
2371 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2372 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2375 return test_proc(hwnd
, message
, wparam
, lparam
);
2378 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2380 if (message
== WM_SIZE
)
2382 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2383 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2386 return test_proc(hwnd
, message
, wparam
, lparam
);
2389 struct test_coop_level_mode_set_enum_param
2391 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2394 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC
*surface_desc
, void *context
)
2396 struct test_coop_level_mode_set_enum_param
*param
= context
;
2398 if (U1(surface_desc
->ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2399 return DDENUMRET_OK
;
2400 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2401 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2402 return DDENUMRET_OK
;
2404 if (!param
->ddraw_width
)
2406 param
->ddraw_width
= surface_desc
->dwWidth
;
2407 param
->ddraw_height
= surface_desc
->dwHeight
;
2408 return DDENUMRET_OK
;
2410 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2411 return DDENUMRET_OK
;
2413 param
->user32_width
= surface_desc
->dwWidth
;
2414 param
->user32_height
= surface_desc
->dwHeight
;
2415 return DDENUMRET_CANCEL
;
2418 static void test_coop_level_mode_set(void)
2420 IDirectDrawSurface
*primary
;
2421 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2422 IDirectDraw2
*ddraw
;
2425 HWND window
, window2
;
2429 struct test_coop_level_mode_set_enum_param param
;
2434 static const struct message exclusive_messages
[] =
2436 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2437 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2438 {WM_SIZE
, FALSE
, 0},
2439 {WM_DISPLAYCHANGE
, FALSE
, 0},
2442 static const struct message exclusive_focus_loss_messages
[] =
2444 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2445 {WM_DISPLAYCHANGE
, FALSE
, 0},
2446 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2447 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2448 * SW_MINIMIZED, causing a recursive window activation that does not
2449 * produce the same result in Wine yet. Ignore the difference for now.
2450 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2451 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2452 {WM_MOVE
, FALSE
, 0},
2453 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2454 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2457 static const struct message exclusive_focus_restore_messages
[] =
2459 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2460 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2461 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2462 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2463 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2464 /* Native redundantly sets the window size here. */
2465 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2466 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2467 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2468 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2471 static const struct message sc_restore_messages
[] =
2473 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2474 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2475 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2476 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2479 static const struct message sc_minimize_messages
[] =
2481 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2482 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2483 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2484 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2487 static const struct message sc_maximize_messages
[] =
2489 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2490 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2491 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2492 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2496 static const struct message normal_messages
[] =
2498 {WM_DISPLAYCHANGE
, FALSE
, 0},
2502 ddraw
= create_ddraw();
2503 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2505 memset(¶m
, 0, sizeof(param
));
2506 hr
= IDirectDraw2_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2507 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2508 ref
= IDirectDraw2_Release(ddraw
);
2509 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2511 if (!param
.user32_height
)
2513 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2517 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2518 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2519 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2521 memset(&devmode
, 0, sizeof(devmode
));
2522 devmode
.dmSize
= sizeof(devmode
);
2523 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2524 devmode
.dmPelsWidth
= param
.user32_width
;
2525 devmode
.dmPelsHeight
= param
.user32_height
;
2526 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2527 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2529 ddraw
= create_ddraw();
2530 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2532 wc
.lpfnWndProc
= mode_set_proc
;
2533 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2534 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2535 wc
.lpfnWndProc
= mode_set_proc2
;
2536 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2537 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2539 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2540 0, 0, 100, 100, 0, 0, 0, 0);
2541 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2542 0, 0, 100, 100, 0, 0, 0, 0);
2544 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2545 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2547 GetWindowRect(window
, &r
);
2548 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2549 wine_dbgstr_rect(&r
));
2551 memset(&ddsd
, 0, sizeof(ddsd
));
2552 ddsd
.dwSize
= sizeof(ddsd
);
2553 ddsd
.dwFlags
= DDSD_CAPS
;
2554 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2556 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2557 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2558 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2559 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2560 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2561 param
.user32_width
, ddsd
.dwWidth
);
2562 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2563 param
.user32_height
, ddsd
.dwHeight
);
2565 GetWindowRect(window
, &r
);
2566 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2567 wine_dbgstr_rect(&r
));
2569 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2570 expect_messages
= exclusive_messages
;
2574 hr
= IDirectDrawSurface_IsLost(primary
);
2575 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2576 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2577 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2578 hr
= IDirectDrawSurface_IsLost(primary
);
2579 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2581 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2582 expect_messages
= NULL
;
2583 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2584 "Expected screen size %ux%u, got %ux%u.\n",
2585 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2587 GetWindowRect(window
, &r
);
2588 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2589 wine_dbgstr_rect(&r
));
2591 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2592 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2593 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2594 param
.user32_width
, ddsd
.dwWidth
);
2595 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2596 param
.user32_height
, ddsd
.dwHeight
);
2597 IDirectDrawSurface_Release(primary
);
2599 memset(&ddsd
, 0, sizeof(ddsd
));
2600 ddsd
.dwSize
= sizeof(ddsd
);
2601 ddsd
.dwFlags
= DDSD_CAPS
;
2602 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2604 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2605 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2606 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2607 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2608 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2609 param
.ddraw_width
, ddsd
.dwWidth
);
2610 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2611 param
.ddraw_height
, ddsd
.dwHeight
);
2613 GetWindowRect(window
, &r
);
2614 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2615 wine_dbgstr_rect(&r
));
2617 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2618 expect_messages
= exclusive_messages
;
2622 hr
= IDirectDrawSurface_IsLost(primary
);
2623 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2624 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2625 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2626 hr
= IDirectDrawSurface_IsLost(primary
);
2627 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2629 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2630 expect_messages
= NULL
;
2631 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2632 "Expected screen size %ux%u, got %ux%u.\n",
2633 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2635 GetWindowRect(window
, &r
);
2636 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2637 wine_dbgstr_rect(&r
));
2639 expect_messages
= exclusive_focus_loss_messages
;
2640 ret
= SetForegroundWindow(GetDesktopWindow());
2641 ok(ret
, "Failed to set foreground window.\n");
2642 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2643 memset(&devmode
, 0, sizeof(devmode
));
2644 devmode
.dmSize
= sizeof(devmode
);
2645 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2646 ok(ret
, "Failed to get display mode.\n");
2647 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2648 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2649 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2651 expect_messages
= exclusive_focus_restore_messages
;
2652 ShowWindow(window
, SW_RESTORE
);
2653 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2655 GetWindowRect(window
, &r
);
2656 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2657 wine_dbgstr_rect(&r
));
2658 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2659 ok(ret
, "Failed to get display mode.\n");
2660 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2661 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2662 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2664 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2665 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2666 /* Normally the primary should be restored here. Unfortunately this causes the
2667 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2668 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2669 * the point of the GetSurfaceDesc call. */
2671 expect_messages
= sc_minimize_messages
;
2672 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2673 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2674 expect_messages
= NULL
;
2676 expect_messages
= sc_restore_messages
;
2677 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2678 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2679 expect_messages
= NULL
;
2681 expect_messages
= sc_maximize_messages
;
2682 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2683 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2684 expect_messages
= NULL
;
2686 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2687 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2689 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2690 expect_messages
= exclusive_messages
;
2694 hr
= IDirectDrawSurface_IsLost(primary
);
2695 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2696 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
2697 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2698 hr
= IDirectDrawSurface_IsLost(primary
);
2699 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2701 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2702 expect_messages
= NULL
;
2703 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2704 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2705 "Expected screen size %ux%u, got %ux%u.\n",
2706 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2708 GetWindowRect(window
, &r
);
2709 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2710 wine_dbgstr_rect(&r
));
2712 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2713 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2714 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2715 param
.ddraw_width
, ddsd
.dwWidth
);
2716 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2717 param
.ddraw_height
, ddsd
.dwHeight
);
2718 IDirectDrawSurface_Release(primary
);
2721 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2722 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2724 memset(&ddsd
, 0, sizeof(ddsd
));
2725 ddsd
.dwSize
= sizeof(ddsd
);
2726 ddsd
.dwFlags
= DDSD_CAPS
;
2727 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2729 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2730 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2731 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2732 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2733 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2734 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2735 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2736 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2738 GetWindowRect(window
, &r
);
2739 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2740 wine_dbgstr_rect(&r
));
2742 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2743 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2745 GetWindowRect(window
, &r
);
2746 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2747 wine_dbgstr_rect(&r
));
2749 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2750 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2751 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2752 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2753 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2754 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2755 IDirectDrawSurface_Release(primary
);
2757 memset(&ddsd
, 0, sizeof(ddsd
));
2758 ddsd
.dwSize
= sizeof(ddsd
);
2759 ddsd
.dwFlags
= DDSD_CAPS
;
2760 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2762 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2763 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2764 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2765 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2766 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2767 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2768 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2769 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2771 GetWindowRect(window
, &r
);
2772 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2773 wine_dbgstr_rect(&r
));
2775 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2776 expect_messages
= normal_messages
;
2780 hr
= IDirectDrawSurface_IsLost(primary
);
2781 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2782 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2783 devmode
.dmPelsWidth
= param
.user32_width
;
2784 devmode
.dmPelsHeight
= param
.user32_height
;
2785 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2786 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2787 hr
= IDirectDrawSurface_IsLost(primary
);
2788 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2790 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2791 expect_messages
= NULL
;
2792 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2794 GetWindowRect(window
, &r
);
2795 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2796 wine_dbgstr_rect(&r
));
2798 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2799 expect_messages
= normal_messages
;
2803 hr
= IDirectDrawSurface_Restore(primary
);
2804 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2805 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2806 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
2808 win_skip("Broken SetDisplayMode(), skipping remaining tests.\n");
2809 IDirectDrawSurface_Release(primary
);
2810 IDirectDraw2_Release(ddraw
);
2813 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2814 hr
= IDirectDrawSurface_Restore(primary
);
2815 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2816 hr
= IDirectDrawSurface_IsLost(primary
);
2817 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2819 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2820 expect_messages
= NULL
;
2821 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2823 GetWindowRect(window
, &r
);
2824 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2825 wine_dbgstr_rect(&r
));
2827 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2828 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2829 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2830 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2831 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2832 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2833 IDirectDrawSurface_Release(primary
);
2835 memset(&ddsd
, 0, sizeof(ddsd
));
2836 ddsd
.dwSize
= sizeof(ddsd
);
2837 ddsd
.dwFlags
= DDSD_CAPS
;
2838 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2840 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2841 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2842 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2843 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2844 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2845 param
.ddraw_width
, ddsd
.dwWidth
);
2846 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2847 param
.ddraw_height
, ddsd
.dwHeight
);
2849 GetWindowRect(window
, &r
);
2850 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2851 wine_dbgstr_rect(&r
));
2853 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2854 expect_messages
= normal_messages
;
2858 hr
= IDirectDrawSurface_IsLost(primary
);
2859 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2860 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2861 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2862 hr
= IDirectDrawSurface_IsLost(primary
);
2863 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2865 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2866 expect_messages
= NULL
;
2867 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2869 GetWindowRect(window
, &r
);
2870 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2871 wine_dbgstr_rect(&r
));
2873 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2874 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2875 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2876 param
.ddraw_width
, ddsd
.dwWidth
);
2877 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2878 param
.ddraw_height
, ddsd
.dwHeight
);
2879 IDirectDrawSurface_Release(primary
);
2881 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2882 ok(ret
, "Failed to get display mode.\n");
2883 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2884 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2885 "Expected resolution %ux%u, got %ux%u.\n",
2886 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2887 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2888 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2889 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2891 memset(&ddsd
, 0, sizeof(ddsd
));
2892 ddsd
.dwSize
= sizeof(ddsd
);
2893 ddsd
.dwFlags
= DDSD_CAPS
;
2894 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2896 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2897 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2898 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2899 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2900 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2901 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2902 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2903 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2905 GetWindowRect(window
, &r
);
2906 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2907 wine_dbgstr_rect(&r
));
2909 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2910 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2911 * not DDSCL_FULLSCREEN. */
2912 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2913 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2915 GetWindowRect(window
, &r
);
2916 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2917 wine_dbgstr_rect(&r
));
2919 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2920 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2921 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2922 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2923 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2924 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2925 IDirectDrawSurface_Release(primary
);
2927 memset(&ddsd
, 0, sizeof(ddsd
));
2928 ddsd
.dwSize
= sizeof(ddsd
);
2929 ddsd
.dwFlags
= DDSD_CAPS
;
2930 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2932 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2933 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2934 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2935 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2936 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2937 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2938 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2939 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2941 GetWindowRect(window
, &r
);
2942 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2943 wine_dbgstr_rect(&r
));
2945 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2946 expect_messages
= normal_messages
;
2950 hr
= IDirectDrawSurface_IsLost(primary
);
2951 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2952 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2953 devmode
.dmPelsWidth
= param
.user32_width
;
2954 devmode
.dmPelsHeight
= param
.user32_height
;
2955 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2956 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2957 hr
= IDirectDrawSurface_IsLost(primary
);
2958 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2960 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2961 expect_messages
= NULL
;
2962 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2964 GetWindowRect(window
, &r
);
2965 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2966 wine_dbgstr_rect(&r
));
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 %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2988 wine_dbgstr_rect(&r
));
2990 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2991 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2992 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2993 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2994 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2995 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2996 IDirectDrawSurface_Release(primary
);
2998 memset(&ddsd
, 0, sizeof(ddsd
));
2999 ddsd
.dwSize
= sizeof(ddsd
);
3000 ddsd
.dwFlags
= DDSD_CAPS
;
3001 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3003 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3004 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3005 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3006 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3007 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3008 param
.ddraw_width
, ddsd
.dwWidth
);
3009 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3010 param
.ddraw_height
, ddsd
.dwHeight
);
3012 GetWindowRect(window
, &r
);
3013 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3014 wine_dbgstr_rect(&r
));
3016 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3017 expect_messages
= normal_messages
;
3021 hr
= IDirectDrawSurface_IsLost(primary
);
3022 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3023 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3024 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3025 hr
= IDirectDrawSurface_IsLost(primary
);
3026 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3028 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3029 expect_messages
= NULL
;
3030 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3032 GetWindowRect(window
, &r
);
3033 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3034 wine_dbgstr_rect(&r
));
3036 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3037 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3038 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3039 param
.ddraw_width
, ddsd
.dwWidth
);
3040 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3041 param
.ddraw_height
, ddsd
.dwHeight
);
3042 IDirectDrawSurface_Release(primary
);
3044 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3045 ok(ret
, "Failed to get display mode.\n");
3046 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3047 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3048 "Expected resolution %ux%u, got %ux%u.\n",
3049 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3050 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3051 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3052 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3054 memset(&ddsd
, 0, sizeof(ddsd
));
3055 ddsd
.dwSize
= sizeof(ddsd
);
3056 ddsd
.dwFlags
= DDSD_CAPS
;
3057 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3059 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3060 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3061 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3062 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3063 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3064 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3065 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3066 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3067 IDirectDrawSurface_Release(primary
);
3069 GetWindowRect(window
, &r
);
3070 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3071 wine_dbgstr_rect(&r
));
3073 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3074 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3075 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3076 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3077 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3079 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3080 expect_messages
= exclusive_messages
;
3084 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3085 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3087 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3088 expect_messages
= NULL
;
3089 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
3090 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
3091 "Expected screen size %ux%u, got %ux%u.\n",
3092 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3093 screen_size
.cx
, screen_size
.cy
);
3095 GetWindowRect(window
, &r
);
3096 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3097 wine_dbgstr_rect(&r
));
3099 memset(&ddsd
, 0, sizeof(ddsd
));
3100 ddsd
.dwSize
= sizeof(ddsd
);
3101 ddsd
.dwFlags
= DDSD_CAPS
;
3102 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3104 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3105 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3106 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3107 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3108 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3109 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3110 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3111 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3112 IDirectDrawSurface_Release(primary
);
3114 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3115 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3116 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3117 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3118 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3120 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3121 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3123 memset(&ddsd
, 0, sizeof(ddsd
));
3124 ddsd
.dwSize
= sizeof(ddsd
);
3125 ddsd
.dwFlags
= DDSD_CAPS
;
3126 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3128 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3129 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3130 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3131 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3132 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3133 param
.ddraw_width
, ddsd
.dwWidth
);
3134 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3135 param
.ddraw_height
, ddsd
.dwHeight
);
3136 IDirectDrawSurface_Release(primary
);
3138 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3139 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3141 /* If the window is changed at the same time, messages are sent to the new window. */
3142 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3143 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3144 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3145 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3147 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3148 expect_messages
= exclusive_messages
;
3151 screen_size2
.cx
= 0;
3152 screen_size2
.cy
= 0;
3154 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3155 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3157 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3158 expect_messages
= NULL
;
3159 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
3160 screen_size
.cx
, screen_size
.cy
);
3161 ok(screen_size2
.cx
== registry_mode
.dmPelsWidth
&& screen_size2
.cy
== registry_mode
.dmPelsHeight
,
3162 "Expected screen size 2 %ux%u, got %ux%u.\n",
3163 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size2
.cx
, screen_size2
.cy
);
3165 GetWindowRect(window
, &r
);
3166 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
3167 wine_dbgstr_rect(&r
));
3168 GetWindowRect(window2
, &r
);
3169 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3170 wine_dbgstr_rect(&r
));
3172 memset(&ddsd
, 0, sizeof(ddsd
));
3173 ddsd
.dwSize
= sizeof(ddsd
);
3174 ddsd
.dwFlags
= DDSD_CAPS
;
3175 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3177 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3178 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3179 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3180 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3181 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3182 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3183 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3184 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3185 IDirectDrawSurface_Release(primary
);
3187 ref
= IDirectDraw2_Release(ddraw
);
3188 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3190 GetWindowRect(window
, &r
);
3191 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
3192 wine_dbgstr_rect(&r
));
3195 expect_messages
= NULL
;
3196 DestroyWindow(window
);
3197 DestroyWindow(window2
);
3198 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3199 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3202 static void test_coop_level_mode_set_multi(void)
3204 IDirectDraw2
*ddraw1
, *ddraw2
;
3210 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3211 0, 0, 100, 100, 0, 0, 0, 0);
3212 ddraw1
= create_ddraw();
3213 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3215 /* With just a single ddraw object, the display mode is restored on
3217 hr
= set_display_mode(ddraw1
, 800, 600);
3218 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
3220 win_skip("Broken SetDisplayMode(), skipping test.\n");
3221 IDirectDraw2_Release(ddraw1
);
3222 DestroyWindow(window
);
3225 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3226 w
= GetSystemMetrics(SM_CXSCREEN
);
3227 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3228 h
= GetSystemMetrics(SM_CYSCREEN
);
3229 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3231 ref
= IDirectDraw2_Release(ddraw1
);
3232 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3233 w
= GetSystemMetrics(SM_CXSCREEN
);
3234 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3235 h
= GetSystemMetrics(SM_CYSCREEN
);
3236 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3238 /* When there are multiple ddraw objects, the display mode is restored to
3239 * the initial mode, before the first SetDisplayMode() call. */
3240 ddraw1
= create_ddraw();
3241 hr
= set_display_mode(ddraw1
, 800, 600);
3242 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3243 w
= GetSystemMetrics(SM_CXSCREEN
);
3244 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3245 h
= GetSystemMetrics(SM_CYSCREEN
);
3246 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3248 ddraw2
= create_ddraw();
3249 hr
= set_display_mode(ddraw2
, 640, 480);
3250 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3251 w
= GetSystemMetrics(SM_CXSCREEN
);
3252 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3253 h
= GetSystemMetrics(SM_CYSCREEN
);
3254 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3256 ref
= IDirectDraw2_Release(ddraw2
);
3257 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3258 w
= GetSystemMetrics(SM_CXSCREEN
);
3259 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3260 h
= GetSystemMetrics(SM_CYSCREEN
);
3261 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3263 ref
= IDirectDraw2_Release(ddraw1
);
3264 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3265 w
= GetSystemMetrics(SM_CXSCREEN
);
3266 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3267 h
= GetSystemMetrics(SM_CYSCREEN
);
3268 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3270 /* Regardless of release ordering. */
3271 ddraw1
= create_ddraw();
3272 hr
= set_display_mode(ddraw1
, 800, 600);
3273 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3274 w
= GetSystemMetrics(SM_CXSCREEN
);
3275 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3276 h
= GetSystemMetrics(SM_CYSCREEN
);
3277 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3279 ddraw2
= create_ddraw();
3280 hr
= set_display_mode(ddraw2
, 640, 480);
3281 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3282 w
= GetSystemMetrics(SM_CXSCREEN
);
3283 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3284 h
= GetSystemMetrics(SM_CYSCREEN
);
3285 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3287 ref
= IDirectDraw2_Release(ddraw1
);
3288 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3289 w
= GetSystemMetrics(SM_CXSCREEN
);
3290 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3291 h
= GetSystemMetrics(SM_CYSCREEN
);
3292 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3294 ref
= IDirectDraw2_Release(ddraw2
);
3295 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3296 w
= GetSystemMetrics(SM_CXSCREEN
);
3297 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3298 h
= GetSystemMetrics(SM_CYSCREEN
);
3299 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3301 /* But only for ddraw objects that called SetDisplayMode(). */
3302 ddraw1
= create_ddraw();
3303 ddraw2
= create_ddraw();
3304 hr
= set_display_mode(ddraw2
, 640, 480);
3305 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3306 w
= GetSystemMetrics(SM_CXSCREEN
);
3307 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3308 h
= GetSystemMetrics(SM_CYSCREEN
);
3309 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3311 ref
= IDirectDraw2_Release(ddraw1
);
3312 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3313 w
= GetSystemMetrics(SM_CXSCREEN
);
3314 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3315 h
= GetSystemMetrics(SM_CYSCREEN
);
3316 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3318 ref
= IDirectDraw2_Release(ddraw2
);
3319 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3320 w
= GetSystemMetrics(SM_CXSCREEN
);
3321 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3322 h
= GetSystemMetrics(SM_CYSCREEN
);
3323 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3325 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3326 * restoring the display mode. */
3327 ddraw1
= create_ddraw();
3328 hr
= set_display_mode(ddraw1
, 800, 600);
3329 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3330 w
= GetSystemMetrics(SM_CXSCREEN
);
3331 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3332 h
= GetSystemMetrics(SM_CYSCREEN
);
3333 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3335 ddraw2
= create_ddraw();
3336 hr
= set_display_mode(ddraw2
, 640, 480);
3337 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3338 w
= GetSystemMetrics(SM_CXSCREEN
);
3339 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3340 h
= GetSystemMetrics(SM_CYSCREEN
);
3341 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3343 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3344 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3346 ref
= IDirectDraw2_Release(ddraw1
);
3347 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3348 w
= GetSystemMetrics(SM_CXSCREEN
);
3349 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3350 h
= GetSystemMetrics(SM_CYSCREEN
);
3351 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3353 ref
= IDirectDraw2_Release(ddraw2
);
3354 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3355 w
= GetSystemMetrics(SM_CXSCREEN
);
3356 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3357 h
= GetSystemMetrics(SM_CYSCREEN
);
3358 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3360 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3361 ddraw1
= create_ddraw();
3362 hr
= set_display_mode(ddraw1
, 800, 600);
3363 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3364 w
= GetSystemMetrics(SM_CXSCREEN
);
3365 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3366 h
= GetSystemMetrics(SM_CYSCREEN
);
3367 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3369 hr
= IDirectDraw2_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3370 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3372 ddraw2
= create_ddraw();
3373 hr
= set_display_mode(ddraw2
, 640, 480);
3374 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3376 ref
= IDirectDraw2_Release(ddraw1
);
3377 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3378 w
= GetSystemMetrics(SM_CXSCREEN
);
3379 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3380 h
= GetSystemMetrics(SM_CYSCREEN
);
3381 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3383 ref
= IDirectDraw2_Release(ddraw2
);
3384 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3385 w
= GetSystemMetrics(SM_CXSCREEN
);
3386 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3387 h
= GetSystemMetrics(SM_CYSCREEN
);
3388 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3390 DestroyWindow(window
);
3393 static void test_initialize(void)
3395 IDirectDraw2
*ddraw
;
3398 ddraw
= create_ddraw();
3399 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3401 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3402 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3403 IDirectDraw2_Release(ddraw
);
3406 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw2
, (void **)&ddraw
);
3407 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw2 instance, hr %#x.\n", hr
);
3408 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3409 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3410 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3411 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3412 IDirectDraw2_Release(ddraw
);
3416 static void test_coop_level_surf_create(void)
3418 IDirectDrawSurface
*surface
;
3419 IDirectDraw2
*ddraw
;
3423 ddraw
= create_ddraw();
3424 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3426 memset(&ddsd
, 0, sizeof(ddsd
));
3427 ddsd
.dwSize
= sizeof(ddsd
);
3428 ddsd
.dwFlags
= DDSD_CAPS
;
3429 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3430 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3431 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3433 IDirectDraw2_Release(ddraw
);
3436 static void test_coop_level_multi_window(void)
3438 HWND window1
, window2
;
3439 IDirectDraw2
*ddraw
;
3442 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3443 0, 0, 640, 480, 0, 0, 0, 0);
3444 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3445 0, 0, 640, 480, 0, 0, 0, 0);
3446 ddraw
= create_ddraw();
3447 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3449 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3450 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3451 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3452 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3453 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3454 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3456 IDirectDraw2_Release(ddraw
);
3457 DestroyWindow(window2
);
3458 DestroyWindow(window1
);
3461 static void test_clear_rect_count(void)
3463 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3464 IDirect3DMaterial2
*white
, *red
, *green
, *blue
;
3465 IDirect3DViewport2
*viewport
;
3466 IDirect3DDevice2
*device
;
3467 IDirectDrawSurface
*rt
;
3468 IDirectDraw2
*ddraw
;
3473 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3474 0, 0, 640, 480, 0, 0, 0, 0);
3475 ddraw
= create_ddraw();
3476 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3477 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3479 skip("Failed to create a 3D device, skipping test.\n");
3480 IDirectDraw2_Release(ddraw
);
3481 DestroyWindow(window
);
3485 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
3486 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3488 white
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
3489 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
3490 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
3491 blue
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
3493 viewport
= create_viewport(device
, 0, 0, 640, 480);
3494 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
3495 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3497 viewport_set_background(device
, viewport
, white
);
3498 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3499 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3500 viewport_set_background(device
, viewport
, red
);
3501 hr
= IDirect3DViewport2_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3502 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3503 viewport_set_background(device
, viewport
, green
);
3504 hr
= IDirect3DViewport2_Clear(viewport
, 0, NULL
, D3DCLEAR_TARGET
);
3505 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3506 viewport_set_background(device
, viewport
, blue
);
3507 hr
= IDirect3DViewport2_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3508 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3510 color
= get_surface_color(rt
, 320, 240);
3511 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x000000ff, 1)),
3512 "Got unexpected color 0x%08x.\n", color
);
3514 IDirectDrawSurface_Release(rt
);
3515 destroy_viewport(device
, viewport
);
3516 destroy_material(white
);
3517 destroy_material(red
);
3518 destroy_material(green
);
3519 destroy_material(blue
);
3520 IDirect3DDevice2_Release(device
);
3521 IDirectDraw2_Release(ddraw
);
3522 DestroyWindow(window
);
3525 static BOOL
test_mode_restored(IDirectDraw2
*ddraw
, HWND window
)
3527 DDSURFACEDESC ddsd1
, ddsd2
;
3530 memset(&ddsd1
, 0, sizeof(ddsd1
));
3531 ddsd1
.dwSize
= sizeof(ddsd1
);
3532 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &ddsd1
);
3533 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3535 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3536 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3537 hr
= set_display_mode(ddraw
, 640, 480);
3538 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3539 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3540 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3542 memset(&ddsd2
, 0, sizeof(ddsd2
));
3543 ddsd2
.dwSize
= sizeof(ddsd2
);
3544 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &ddsd2
);
3545 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3546 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3547 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3549 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
3552 static void test_coop_level_versions(void)
3558 IDirectDrawSurface
*surface
;
3559 IDirectDraw2
*ddraw2
;
3562 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3563 0, 0, 640, 480, 0, 0, 0, 0);
3565 ddraw2
= create_ddraw();
3566 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3567 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3568 restored
= test_mode_restored(ddraw2
, window
);
3569 ok(restored
, "Display mode not restored in new ddraw object\n");
3571 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3572 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3573 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3575 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3576 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3577 restored
= test_mode_restored(ddraw2
, window
);
3578 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3580 /* A successful one does */
3581 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3582 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3583 restored
= test_mode_restored(ddraw2
, window
);
3584 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3586 IDirectDraw_Release(ddraw
);
3587 IDirectDraw2_Release(ddraw2
);
3589 ddraw2
= create_ddraw();
3590 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3591 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3592 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3594 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
3595 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3596 restored
= test_mode_restored(ddraw2
, window
);
3597 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3599 IDirectDraw_Release(ddraw
);
3600 IDirectDraw2_Release(ddraw2
);
3602 /* A failing call does not restore the ddraw2+ behavior */
3603 ddraw2
= create_ddraw();
3604 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3605 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3606 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3608 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3609 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3610 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3611 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3612 restored
= test_mode_restored(ddraw2
, window
);
3613 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3615 IDirectDraw_Release(ddraw
);
3616 IDirectDraw2_Release(ddraw2
);
3618 /* Neither does a sequence of successful calls with the new interface */
3619 ddraw2
= create_ddraw();
3620 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3621 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3622 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3624 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3625 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3626 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3627 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3628 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_NORMAL
);
3629 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3631 restored
= test_mode_restored(ddraw2
, window
);
3632 ok(!restored
, "Display mode restored after ddraw1-ddraw2 SetCooperativeLevel() call sequence\n");
3633 IDirectDraw_Release(ddraw
);
3634 IDirectDraw2_Release(ddraw2
);
3636 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3637 ddraw2
= create_ddraw();
3638 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3639 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3640 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3642 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_NORMAL
);
3643 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3645 memset(&ddsd
, 0, sizeof(ddsd
));
3646 ddsd
.dwSize
= sizeof(ddsd
);
3647 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
3648 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
3649 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
3650 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3651 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
3652 IDirectDrawSurface_Release(surface
);
3653 restored
= test_mode_restored(ddraw2
, window
);
3654 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
3656 IDirectDraw_Release(ddraw
);
3657 IDirectDraw2_Release(ddraw2
);
3658 DestroyWindow(window
);
3661 static void test_lighting_interface_versions(void)
3663 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3664 IDirect3DMaterial2
*emissive
, *background
;
3665 IDirect3DViewport2
*viewport
;
3666 IDirect3DDevice2
*device
;
3667 IDirectDrawSurface
*rt
;
3668 IDirectDraw2
*ddraw
;
3672 D3DMATERIALHANDLE mat_handle
;
3676 static D3DVERTEX quad
[] =
3678 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3679 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3680 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3681 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3683 static D3DLVERTEX lquad
[] =
3685 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3686 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3687 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3688 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3690 static D3DTLVERTEX tlquad
[] =
3692 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3693 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3694 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3695 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3699 D3DVERTEXTYPE vertextype
;
3701 DWORD d3drs_lighting
, d3drs_specular
;
3707 /* Lighting is enabled when D3DVT_VERTEX is used and D3DDP_DONOTLIGHT is not
3708 * set. D3DVT_VERTEX has diffuse = 0xffffffff and specular = 0x00000000, as
3709 * in later d3d versions */
3710 { D3DVT_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x0000ff00},
3711 { D3DVT_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
3712 { D3DVT_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3713 { D3DVT_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3714 { D3DVT_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x0000ff00},
3715 { D3DVT_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
3716 { D3DVT_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3717 { D3DVT_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3719 { D3DVT_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
3720 { D3DVT_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x00ff0000},
3721 { D3DVT_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3722 { D3DVT_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3723 { D3DVT_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
3724 { D3DVT_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x00ff8080},
3725 { D3DVT_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3726 { D3DVT_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3728 { D3DVT_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
3729 { D3DVT_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
3730 { D3DVT_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3731 { D3DVT_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3732 { D3DVT_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
3733 { D3DVT_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
3734 { D3DVT_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3735 { D3DVT_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3738 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3739 0, 0, 640, 480, 0, 0, 0, 0);
3740 ddraw
= create_ddraw();
3741 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3742 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3744 skip("Failed to create a 3D device, skipping test.\n");
3745 IDirectDraw2_Release(ddraw
);
3746 DestroyWindow(window
);
3750 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
3751 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3753 viewport
= create_viewport(device
, 0, 0, 640, 480);
3754 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
3755 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3757 emissive
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
3758 hr
= IDirect3DMaterial2_GetHandle(emissive
, device
, &mat_handle
);
3759 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
3760 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
3761 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
3762 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
3763 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
3765 background
= create_diffuse_material(device
, 0.1f
, 0.1f
, 0.1f
, 0.1f
);
3766 viewport_set_background(device
, viewport
, background
);
3768 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
3769 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
3770 ok(rs
== TRUE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected TRUE.\n", rs
);
3772 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
3774 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3775 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3777 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
3778 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
3779 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
3780 tests
[i
].d3drs_specular
);
3781 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
3783 hr
= IDirect3DDevice2_BeginScene(device
);
3784 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3785 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
3786 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
3787 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3788 hr
= IDirect3DDevice2_EndScene(device
);
3789 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3791 color
= get_surface_color(rt
, 320, 240);
3792 ok(compare_color(color
, tests
[i
].color
, 1),
3793 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3794 color
, tests
[i
].color
, i
);
3797 destroy_material(background
);
3798 destroy_material(emissive
);
3799 IDirectDrawSurface_Release(rt
);
3800 IDirect3DDevice2_Release(device
);
3801 ref
= IDirectDraw2_Release(ddraw
);
3802 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
3803 DestroyWindow(window
);
3809 IDirectDraw2
*ddraw
;
3812 } activateapp_testdata
;
3814 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
3816 if (message
== WM_ACTIVATEAPP
)
3818 if (activateapp_testdata
.ddraw
)
3821 activateapp_testdata
.received
= FALSE
;
3822 hr
= IDirectDraw2_SetCooperativeLevel(activateapp_testdata
.ddraw
,
3823 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
3824 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
3825 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3827 activateapp_testdata
.received
= TRUE
;
3830 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
3833 static void test_coop_level_activateapp(void)
3835 IDirectDraw2
*ddraw
;
3840 IDirectDrawSurface
*surface
;
3842 ddraw
= create_ddraw();
3843 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3845 wc
.lpfnWndProc
= activateapp_test_proc
;
3846 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
3847 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3849 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3850 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3852 /* Exclusive with window already active. */
3853 SetForegroundWindow(window
);
3854 activateapp_testdata
.received
= FALSE
;
3855 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3856 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3857 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
3858 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3859 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3861 /* Exclusive with window not active. */
3862 SetForegroundWindow(GetDesktopWindow());
3863 activateapp_testdata
.received
= FALSE
;
3864 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3865 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3866 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3867 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3868 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3870 /* Normal with window not active, then exclusive with the same window. */
3871 SetForegroundWindow(GetDesktopWindow());
3872 activateapp_testdata
.received
= FALSE
;
3873 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3874 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3875 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3876 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3877 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3878 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3879 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3880 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3882 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3883 SetForegroundWindow(GetDesktopWindow());
3884 activateapp_testdata
.received
= FALSE
;
3885 activateapp_testdata
.ddraw
= ddraw
;
3886 activateapp_testdata
.window
= window
;
3887 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
3888 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3889 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3890 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3891 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3892 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3894 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3895 * succeeding. Another switch to exclusive and back to normal is needed to release the
3896 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3897 * WM_ACTIVATEAPP messages. */
3898 activateapp_testdata
.ddraw
= NULL
;
3899 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3900 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3901 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3902 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3904 /* Setting DDSCL_NORMAL with recursive invocation. */
3905 SetForegroundWindow(GetDesktopWindow());
3906 activateapp_testdata
.received
= FALSE
;
3907 activateapp_testdata
.ddraw
= ddraw
;
3908 activateapp_testdata
.window
= window
;
3909 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
3910 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3911 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3912 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3914 /* DDraw is in exlusive mode now. */
3915 memset(&ddsd
, 0, sizeof(ddsd
));
3916 ddsd
.dwSize
= sizeof(ddsd
);
3917 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
3918 ddsd
.dwBackBufferCount
= 1;
3919 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
3920 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3921 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3922 IDirectDrawSurface_Release(surface
);
3924 /* Recover again, just to be sure. */
3925 activateapp_testdata
.ddraw
= NULL
;
3926 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3927 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3928 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3929 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3931 DestroyWindow(window
);
3932 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3933 IDirectDraw2_Release(ddraw
);
3936 struct format_support_check
3938 const DDPIXELFORMAT
*format
;
3942 static HRESULT WINAPI
test_unsupported_formats_cb(DDSURFACEDESC
*desc
, void *ctx
)
3944 struct format_support_check
*format
= ctx
;
3946 if (!memcmp(format
->format
, &desc
->ddpfPixelFormat
, sizeof(*format
->format
)))
3948 format
->supported
= TRUE
;
3949 return DDENUMRET_CANCEL
;
3952 return DDENUMRET_OK
;
3955 static void test_unsupported_formats(void)
3958 BOOL expect_success
;
3960 IDirectDraw2
*ddraw
;
3961 IDirect3DDevice2
*device
;
3962 IDirectDrawSurface
*surface
;
3965 DWORD expected_caps
;
3976 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
3977 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
3983 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
3984 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3988 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
3990 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3991 0, 0, 640, 480, 0, 0, 0, 0);
3992 ddraw
= create_ddraw();
3993 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3994 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3996 skip("Failed to create a 3D device, skipping test.\n");
3997 IDirectDraw2_Release(ddraw
);
3998 DestroyWindow(window
);
4002 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
4004 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
4005 hr
= IDirect3DDevice2_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
4006 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4008 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
4010 memset(&ddsd
, 0, sizeof(ddsd
));
4011 ddsd
.dwSize
= sizeof(ddsd
);
4012 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
4013 ddsd
.ddpfPixelFormat
= formats
[i
].fmt
;
4016 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
4018 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
4019 expect_success
= FALSE
;
4021 expect_success
= TRUE
;
4023 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4024 ok(SUCCEEDED(hr
) == expect_success
,
4025 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4026 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
4030 memset(&ddsd
, 0, sizeof(ddsd
));
4031 ddsd
.dwSize
= sizeof(ddsd
);
4032 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &ddsd
);
4033 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4035 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
4036 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4037 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
4038 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4039 else if (check
.supported
)
4040 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4042 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4044 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
4045 "Expected capability %#x, format %s, input cap %#x.\n",
4046 expected_caps
, formats
[i
].name
, caps
[j
]);
4048 IDirectDrawSurface_Release(surface
);
4052 IDirect3DDevice2_Release(device
);
4053 IDirectDraw2_Release(ddraw
);
4054 DestroyWindow(window
);
4057 static void test_rt_caps(void)
4059 PALETTEENTRY palette_entries
[256];
4060 IDirectDrawPalette
*palette
;
4061 IDirect3DDevice2
*device
;
4062 IDirectDraw2
*ddraw
;
4070 static const DDPIXELFORMAT p8_fmt
=
4072 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4073 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4078 const DDPIXELFORMAT
*pf
;
4081 HRESULT create_device_hr
;
4083 HRESULT alternative_set_rt_hr
;
4084 BOOL create_may_fail
;
4090 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4091 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4099 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4100 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4108 DDSCAPS_OFFSCREENPLAIN
,
4109 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4117 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4118 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4119 D3DERR_SURFACENOTINVIDMEM
,
4126 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4127 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4135 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4136 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4145 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4154 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4162 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4163 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4164 D3DERR_SURFACENOTINVIDMEM
,
4171 DDSCAPS_SYSTEMMEMORY
,
4172 DDSCAPS_SYSTEMMEMORY
,
4181 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4189 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4191 DDERR_NOPALETTEATTACHED
,
4198 DDSCAPS_OFFSCREENPLAIN
,
4199 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4207 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4208 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4209 DDERR_NOPALETTEATTACHED
,
4216 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4217 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4225 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
4226 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4228 DDERR_INVALIDPIXELFORMAT
,
4230 TRUE
/* AMD Evergreen */,
4234 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4235 ~0U /* AMD Evergreen */,
4237 DDERR_INVALIDPIXELFORMAT
,
4244 ~0U /* AMD Evergreen */,
4252 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4253 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4255 DDERR_INVALIDPIXELFORMAT
,
4256 DDERR_INVALIDPIXELFORMAT
,
4257 TRUE
/* Nvidia Kepler */,
4261 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4262 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4266 TRUE
/* Nvidia Kepler */,
4270 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4271 0, 0, 640, 480, 0, 0, 0, 0);
4272 ddraw
= create_ddraw();
4273 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4274 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4276 skip("Failed to create a 3D device, skipping test.\n");
4277 IDirectDraw2_Release(ddraw
);
4278 DestroyWindow(window
);
4281 z_depth
= get_device_z_depth(device
);
4282 ok(!!z_depth
, "Failed to get device z depth.\n");
4283 IDirect3DDevice2_Release(device
);
4285 if (FAILED(IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
)))
4287 skip("D3D interface is not available, skipping test.\n");
4291 memset(palette_entries
, 0, sizeof(palette_entries
));
4292 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
4293 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
4295 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4297 IDirectDrawSurface
*surface
, *rt
, *expected_rt
, *tmp
;
4298 DDSURFACEDESC surface_desc
;
4299 IDirect3DDevice2
*device
;
4301 memset(&surface_desc
, 0, sizeof(surface_desc
));
4302 surface_desc
.dwSize
= sizeof(surface_desc
);
4303 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4304 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4305 if (test_data
[i
].pf
)
4307 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4308 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
4310 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
4312 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4313 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
4315 surface_desc
.dwWidth
= 640;
4316 surface_desc
.dwHeight
= 480;
4317 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4318 ok(SUCCEEDED(hr
) || broken(test_data
[i
].create_may_fail
),
4319 "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4320 i
, test_data
[i
].caps_in
, hr
);
4324 memset(&surface_desc
, 0, sizeof(surface_desc
));
4325 surface_desc
.dwSize
= sizeof(surface_desc
);
4326 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4327 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4328 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
4329 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4330 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4332 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4333 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4334 i
, hr
, test_data
[i
].create_device_hr
);
4337 if (hr
== DDERR_NOPALETTEATTACHED
)
4339 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
4340 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
4341 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4342 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
4343 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4345 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4347 IDirectDrawSurface_Release(surface
);
4349 memset(&surface_desc
, 0, sizeof(surface_desc
));
4350 surface_desc
.dwSize
= sizeof(surface_desc
);
4351 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4352 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
4353 surface_desc
.dwWidth
= 640;
4354 surface_desc
.dwHeight
= 480;
4355 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4356 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
4358 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4359 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
4362 memset(&surface_desc
, 0, sizeof(surface_desc
));
4363 surface_desc
.dwSize
= sizeof(surface_desc
);
4364 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4365 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4366 if (test_data
[i
].pf
)
4368 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4369 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
4371 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
4373 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4374 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
4376 surface_desc
.dwWidth
= 640;
4377 surface_desc
.dwHeight
= 480;
4378 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
4379 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4380 i
, test_data
[i
].caps_in
, hr
);
4382 hr
= IDirect3DDevice2_SetRenderTarget(device
, rt
, 0);
4383 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
4384 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4385 i
, hr
, test_data
[i
].set_rt_hr
);
4386 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
4389 expected_rt
= surface
;
4391 /* It appears the surface is set as render target in this case, but no
4392 * reference is taken. */
4393 if (hr
== DDERR_INVALIDPIXELFORMAT
)
4395 refcount
= IDirectDrawSurface_AddRef(rt
);
4396 ok(refcount
== 2, "Test %u: Got unexpected refcount %u.\n", i
, refcount
);
4399 hr
= IDirect3DDevice2_GetRenderTarget(device
, &tmp
);
4400 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
4401 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
4403 IDirectDrawSurface_Release(tmp
);
4404 IDirectDrawSurface_Release(rt
);
4405 refcount
= IDirect3DDevice2_Release(device
);
4406 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
4407 refcount
= IDirectDrawSurface_Release(surface
);
4408 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
4411 IDirectDrawPalette_Release(palette
);
4412 IDirect3D2_Release(d3d
);
4415 refcount
= IDirectDraw2_Release(ddraw
);
4416 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4417 DestroyWindow(window
);
4420 static void test_primary_caps(void)
4422 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4423 IDirectDrawSurface
*surface
;
4424 DDSURFACEDESC surface_desc
;
4425 IDirectDraw2
*ddraw
;
4435 DWORD back_buffer_count
;
4443 DDSCAPS_PRIMARYSURFACE
,
4446 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
4450 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
4457 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
4464 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
4471 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
4478 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
4485 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4492 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4499 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4501 DDERR_NOEXCLUSIVEMODE
,
4505 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4506 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4512 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4513 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4516 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
4519 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4520 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
4526 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4527 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
4534 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4535 0, 0, 640, 480, 0, 0, 0, 0);
4536 ddraw
= create_ddraw();
4537 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4539 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4541 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
4542 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4544 memset(&surface_desc
, 0, sizeof(surface_desc
));
4545 surface_desc
.dwSize
= sizeof(surface_desc
);
4546 surface_desc
.dwFlags
= DDSD_CAPS
;
4547 if (test_data
[i
].back_buffer_count
!= ~0u)
4548 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4549 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4550 surface_desc
.dwBackBufferCount
= test_data
[i
].back_buffer_count
;
4551 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4552 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
4556 memset(&surface_desc
, 0, sizeof(surface_desc
));
4557 surface_desc
.dwSize
= sizeof(surface_desc
);
4558 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4559 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4560 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
4561 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4562 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4564 IDirectDrawSurface_Release(surface
);
4567 refcount
= IDirectDraw2_Release(ddraw
);
4568 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4569 DestroyWindow(window
);
4572 static void test_surface_lock(void)
4574 IDirectDraw2
*ddraw
;
4575 IDirectDrawSurface
*surface
;
4576 IDirect3DDevice2
*device
;
4591 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
4592 "videomemory offscreenplain"
4595 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4596 "systemmemory offscreenplain"
4599 DDSCAPS_PRIMARYSURFACE
,
4603 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
4604 "videomemory texture"
4607 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
4608 "systemmemory texture"
4611 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4620 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4621 0, 0, 640, 480, 0, 0, 0, 0);
4622 ddraw
= create_ddraw();
4623 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4624 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4626 skip("Failed to create a 3D device, skipping test.\n");
4627 IDirectDraw2_Release(ddraw
);
4628 DestroyWindow(window
);
4631 z_depth
= get_device_z_depth(device
);
4632 ok(!!z_depth
, "Failed to get device z depth.\n");
4633 IDirect3DDevice2_Release(device
);
4635 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4637 memset(&ddsd
, 0, sizeof(ddsd
));
4638 ddsd
.dwSize
= sizeof(ddsd
);
4639 ddsd
.dwFlags
= DDSD_CAPS
;
4640 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4642 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4646 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
4648 ddsd
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4649 U2(ddsd
).dwZBufferBitDepth
= z_depth
;
4651 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4653 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4654 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4656 memset(&ddsd
, 0, sizeof(ddsd
));
4657 ddsd
.dwSize
= sizeof(ddsd
);
4658 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4659 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4662 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4663 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4666 IDirectDrawSurface_Release(surface
);
4669 refcount
= IDirectDraw2_Release(ddraw
);
4670 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4671 DestroyWindow(window
);
4674 static void test_surface_discard(void)
4676 IDirectDraw2
*ddraw
;
4677 IDirect3DDevice2
*device
;
4681 IDirectDrawSurface
*surface
, *target
;
4690 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4691 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4692 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4693 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4697 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4698 0, 0, 640, 480, 0, 0, 0, 0);
4699 ddraw
= create_ddraw();
4700 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4701 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4703 skip("Failed to create a 3D device, skipping test.\n");
4704 DestroyWindow(window
);
4705 IDirectDraw2_Release(ddraw
);
4709 hr
= IDirect3DDevice2_GetRenderTarget(device
, &target
);
4710 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4712 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4716 memset(&ddsd
, 0, sizeof(ddsd
));
4717 ddsd
.dwSize
= sizeof(ddsd
);
4718 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4719 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4722 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4725 skip("Failed to create surface, skipping.\n");
4729 memset(&ddsd
, 0, sizeof(ddsd
));
4730 ddsd
.dwSize
= sizeof(ddsd
);
4731 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4732 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4733 addr
= ddsd
.lpSurface
;
4734 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4735 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4737 memset(&ddsd
, 0, sizeof(ddsd
));
4738 ddsd
.dwSize
= sizeof(ddsd
);
4739 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4740 ok(SUCCEEDED(hr
) , "Failed to lock surface, hr %#x.\n", hr
);
4741 discarded
= ddsd
.lpSurface
!= addr
;
4742 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4743 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4745 hr
= IDirectDrawSurface_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
4746 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
4748 memset(&ddsd
, 0, sizeof(ddsd
));
4749 ddsd
.dwSize
= sizeof(ddsd
);
4750 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4751 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4752 discarded
|= ddsd
.lpSurface
!= addr
;
4753 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4754 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4756 IDirectDrawSurface_Release(surface
);
4758 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4759 * AMD r500, evergreen). Windows XP, at least on AMD r200, never changes the pointer. */
4760 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
4763 IDirectDrawSurface_Release(target
);
4764 IDirect3DDevice2_Release(device
);
4765 IDirectDraw2_Release(ddraw
);
4766 DestroyWindow(window
);
4769 static void test_flip(void)
4771 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4772 IDirectDrawSurface
*frontbuffer
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
4773 DDSCAPS caps
= {DDSCAPS_FLIP
};
4774 DDSURFACEDESC surface_desc
;
4775 BOOL sysmem_primary
;
4776 IDirectDraw2
*ddraw
;
4777 DWORD expected_caps
;
4792 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE
},
4793 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN
},
4794 {"TEXTURE", DDSCAPS_TEXTURE
},
4797 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4798 0, 0, 640, 480, 0, 0, 0, 0);
4799 ddraw
= create_ddraw();
4800 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4802 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4803 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4805 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4807 memset(&surface_desc
, 0, sizeof(surface_desc
));
4808 surface_desc
.dwSize
= sizeof(surface_desc
);
4809 surface_desc
.dwFlags
= DDSD_CAPS
;
4810 if (!(test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4811 surface_desc
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4812 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
4813 surface_desc
.dwWidth
= 512;
4814 surface_desc
.dwHeight
= 512;
4815 surface_desc
.dwBackBufferCount
= 3;
4816 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4817 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4819 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_FLIP
;
4820 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4821 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4822 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4824 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_COMPLEX
;
4825 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_FLIP
;
4826 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4827 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4829 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_COMPLEX
;
4830 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4831 todo_wine_if(test_data
[i
].caps
& DDSCAPS_TEXTURE
)
4832 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
4836 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
4837 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
4838 hr
= IDirectDrawSurface_IsLost(frontbuffer
);
4839 ok(hr
== DD_OK
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4840 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4841 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
4842 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4844 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4845 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4846 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
4847 hr
= IDirectDrawSurface_IsLost(frontbuffer
);
4848 todo_wine
ok(hr
== DDERR_SURFACELOST
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4849 hr
= restore_surfaces(ddraw
);
4850 ok(SUCCEEDED(hr
), "%s: Failed to restore surfaces, hr %#x.\n", test_data
[i
].name
, hr
);
4852 memset(&surface_desc
, 0, sizeof(surface_desc
));
4853 surface_desc
.dwSize
= sizeof(surface_desc
);
4854 hr
= IDirectDrawSurface_GetSurfaceDesc(frontbuffer
, &surface_desc
);
4855 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4856 expected_caps
= DDSCAPS_FRONTBUFFER
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
4857 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
4858 expected_caps
|= DDSCAPS_VISIBLE
;
4859 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4860 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4861 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
4863 hr
= IDirectDrawSurface_GetAttachedSurface(frontbuffer
, &caps
, &backbuffer1
);
4864 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4865 memset(&surface_desc
, 0, sizeof(surface_desc
));
4866 surface_desc
.dwSize
= sizeof(surface_desc
);
4867 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer1
, &surface_desc
);
4868 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4869 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4870 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4871 expected_caps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
);
4872 expected_caps
|= DDSCAPS_BACKBUFFER
;
4873 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4874 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4876 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
4877 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4878 memset(&surface_desc
, 0, sizeof(surface_desc
));
4879 surface_desc
.dwSize
= sizeof(surface_desc
);
4880 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer2
, &surface_desc
);
4881 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4882 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4883 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4884 expected_caps
&= ~DDSCAPS_BACKBUFFER
;
4885 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4886 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4888 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
4889 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4890 memset(&surface_desc
, 0, sizeof(surface_desc
));
4891 surface_desc
.dwSize
= sizeof(surface_desc
);
4892 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer3
, &surface_desc
);
4893 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4894 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4895 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4896 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4897 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4899 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
4900 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4901 ok(surface
== frontbuffer
, "%s: Got unexpected surface %p, expected %p.\n",
4902 test_data
[i
].name
, surface
, frontbuffer
);
4903 IDirectDrawSurface_Release(surface
);
4905 memset(&surface_desc
, 0, sizeof(surface_desc
));
4906 surface_desc
.dwSize
= sizeof(surface_desc
);
4907 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4908 surface_desc
.ddsCaps
.dwCaps
= 0;
4909 surface_desc
.dwWidth
= 640;
4910 surface_desc
.dwHeight
= 480;
4911 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4912 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
4913 hr
= IDirectDrawSurface_Flip(frontbuffer
, surface
, DDFLIP_WAIT
);
4914 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4915 IDirectDrawSurface_Release(surface
);
4917 hr
= IDirectDrawSurface_Flip(frontbuffer
, frontbuffer
, DDFLIP_WAIT
);
4918 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4919 hr
= IDirectDrawSurface_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
4920 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4921 hr
= IDirectDrawSurface_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
4922 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4923 hr
= IDirectDrawSurface_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
4924 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4926 memset(&fx
, 0, sizeof(fx
));
4927 fx
.dwSize
= sizeof(fx
);
4928 U5(fx
).dwFillColor
= 0xffff0000;
4929 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4930 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4931 U5(fx
).dwFillColor
= 0xff00ff00;
4932 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4933 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4934 U5(fx
).dwFillColor
= 0xff0000ff;
4935 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4936 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4938 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4939 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4940 color
= get_surface_color(backbuffer1
, 320, 240);
4941 /* The testbot seems to just copy the contents of one surface to all the
4942 * others, instead of properly flipping. */
4943 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
4944 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4945 color
= get_surface_color(backbuffer2
, 320, 240);
4946 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4947 U5(fx
).dwFillColor
= 0xffff0000;
4948 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4949 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4951 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4952 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4953 color
= get_surface_color(backbuffer1
, 320, 240);
4954 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
4955 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4956 color
= get_surface_color(backbuffer2
, 320, 240);
4957 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4958 U5(fx
).dwFillColor
= 0xff00ff00;
4959 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4960 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4962 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4963 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4964 color
= get_surface_color(backbuffer1
, 320, 240);
4965 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
4966 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4967 color
= get_surface_color(backbuffer2
, 320, 240);
4968 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4969 U5(fx
).dwFillColor
= 0xff0000ff;
4970 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4971 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4973 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer1
, DDFLIP_WAIT
);
4974 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4975 color
= get_surface_color(backbuffer2
, 320, 240);
4976 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
4977 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4978 color
= get_surface_color(backbuffer3
, 320, 240);
4979 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4980 U5(fx
).dwFillColor
= 0xffff0000;
4981 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4982 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4984 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer2
, DDFLIP_WAIT
);
4985 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4986 color
= get_surface_color(backbuffer1
, 320, 240);
4987 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4988 color
= get_surface_color(backbuffer3
, 320, 240);
4989 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
4990 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4991 U5(fx
).dwFillColor
= 0xff00ff00;
4992 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4993 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4995 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer3
, DDFLIP_WAIT
);
4996 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4997 color
= get_surface_color(backbuffer1
, 320, 240);
4998 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
4999 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5000 color
= get_surface_color(backbuffer2
, 320, 240);
5001 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5003 IDirectDrawSurface_Release(backbuffer3
);
5004 IDirectDrawSurface_Release(backbuffer2
);
5005 IDirectDrawSurface_Release(backbuffer1
);
5006 IDirectDrawSurface_Release(frontbuffer
);
5009 refcount
= IDirectDraw2_Release(ddraw
);
5010 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5011 DestroyWindow(window
);
5014 static void reset_ddsd(DDSURFACEDESC
*ddsd
)
5016 memset(ddsd
, 0, sizeof(*ddsd
));
5017 ddsd
->dwSize
= sizeof(*ddsd
);
5020 static void test_set_surface_desc(void)
5022 IDirectDraw2
*ddraw
;
5026 IDirectDrawSurface
*surface
;
5027 IDirectDrawSurface3
*surface3
;
5037 invalid_caps_tests
[] =
5039 {DDSCAPS_VIDEOMEMORY
, FALSE
, "videomemory plain"},
5040 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, TRUE
, "systemmemory texture"},
5041 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, FALSE
, "systemmemory primary"},
5044 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5045 0, 0, 640, 480, 0, 0, 0, 0);
5046 ddraw
= create_ddraw();
5047 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5048 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5049 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5052 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5055 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5056 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5057 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5058 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5059 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5060 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5061 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5063 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5064 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5066 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5067 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5068 IDirectDrawSurface_Release(surface
);
5071 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5072 ddsd
.lpSurface
= data
;
5073 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5074 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5076 /* Redundantly setting the same lpSurface is not an error. */
5077 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5078 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5079 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5080 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5081 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5082 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
5084 hr
= IDirectDrawSurface3_Lock(surface3
, NULL
, &ddsd
, 0, NULL
);
5085 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5086 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5087 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
5088 hr
= IDirectDrawSurface3_Unlock(surface3
, NULL
);
5089 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5092 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5093 ddsd
.lpSurface
= data
;
5094 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 1);
5095 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
5097 ddsd
.lpSurface
= NULL
;
5098 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5099 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
5101 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, NULL
, 0);
5102 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
5104 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5105 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5106 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5107 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5109 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5110 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5111 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
5113 ddsd
.dwFlags
= DDSD_CAPS
;
5114 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5115 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5117 /* dwCaps = 0 is allowed, but ignored. */
5118 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
5119 ddsd
.lpSurface
= data
;
5120 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5121 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5122 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5123 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5124 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5125 ddsd
.ddsCaps
.dwCaps
= 0;
5126 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5127 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5129 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5130 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5131 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5132 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5134 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5136 ddsd
.dwFlags
= DDSD_HEIGHT
;
5138 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5139 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
5141 ddsd
.lpSurface
= data
;
5142 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
5143 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5144 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5147 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5148 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
5151 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5152 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
5153 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5154 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5156 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
5158 ddsd
.dwFlags
= DDSD_PITCH
;
5159 U1(ddsd
).lPitch
= 8 * 4;
5160 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5161 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
5163 ddsd
.dwFlags
= DDSD_WIDTH
;
5165 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5166 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
5168 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
5169 ddsd
.lpSurface
= data
;
5170 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5171 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
5173 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
5174 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5175 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
5177 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5178 U1(ddsd
).lPitch
= 16 * 4;
5180 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5181 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5184 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5185 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5186 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5187 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5188 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
5190 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5192 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5193 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5194 U1(ddsd
).lPitch
= 4 * 4;
5195 ddsd
.lpSurface
= data
;
5196 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5197 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5199 U1(ddsd
).lPitch
= 4;
5200 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5201 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5203 U1(ddsd
).lPitch
= 16 * 4 + 1;
5204 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5205 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5207 U1(ddsd
).lPitch
= 16 * 4 + 3;
5208 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5209 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5211 U1(ddsd
).lPitch
= -4;
5212 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5213 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
5215 U1(ddsd
).lPitch
= 16 * 4;
5216 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5217 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5220 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5221 U1(ddsd
).lPitch
= 0;
5223 ddsd
.lpSurface
= data
;
5224 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5225 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
5227 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5228 U1(ddsd
).lPitch
= 16 * 4;
5230 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5231 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
5233 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5234 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
5235 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5236 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5237 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5238 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5239 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5240 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5241 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5242 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
5244 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
5245 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5246 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5248 /* Can't set color keys. */
5250 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
5251 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
5252 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
5253 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5254 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5256 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
5257 ddsd
.lpSurface
= data
;
5258 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5259 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5261 IDirectDrawSurface3_Release(surface3
);
5263 /* SetSurfaceDesc needs systemmemory surfaces.
5265 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5266 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
5269 ddsd
.dwFlags
= DDSD_CAPS
;
5270 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
5271 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5273 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5276 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5277 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5278 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5279 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5280 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5281 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5284 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5285 ok(SUCCEEDED(hr
) || hr
== DDERR_NODIRECTDRAWHW
, "Failed to create surface, hr %#x.\n", hr
);
5288 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5289 invalid_caps_tests
[i
].name
);
5292 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5293 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5294 IDirectDrawSurface_Release(surface
);
5297 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5298 ddsd
.lpSurface
= data
;
5299 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5300 if (invalid_caps_tests
[i
].supported
)
5302 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5306 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5307 invalid_caps_tests
[i
].name
, hr
);
5309 /* Check priority of error conditions. */
5310 ddsd
.dwFlags
= DDSD_WIDTH
;
5311 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5312 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5313 invalid_caps_tests
[i
].name
, hr
);
5316 IDirectDrawSurface3_Release(surface3
);
5320 ref
= IDirectDraw2_Release(ddraw
);
5321 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5322 DestroyWindow(window
);
5325 static void test_user_memory_getdc(void)
5327 IDirectDraw2
*ddraw
;
5331 IDirectDrawSurface
*surface
;
5332 IDirectDrawSurface3
*surface3
;
5341 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5342 0, 0, 640, 480, 0, 0, 0, 0);
5343 ddraw
= create_ddraw();
5344 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5346 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5347 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5350 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5353 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5354 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5355 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5356 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5357 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5358 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5359 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5360 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5361 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5363 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5364 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5365 IDirectDrawSurface_Release(surface
);
5367 memset(data
, 0xaa, sizeof(data
));
5369 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5370 ddsd
.lpSurface
= data
;
5371 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5372 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5374 hr
= IDirectDrawSurface3_GetDC(surface3
, &dc
);
5375 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5376 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
5377 ok(!!bitmap
, "Failed to get bitmap.\n");
5378 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
5379 ok(size
== sizeof(dib
), "Got unexpected size %d.\n", size
);
5380 ok(dib
.dsBm
.bmBits
== data
, "Got unexpected bits %p, expected %p.\n", dib
.dsBm
.bmBits
, data
);
5381 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
5382 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
5383 hr
= IDirectDrawSurface3_ReleaseDC(surface3
, dc
);
5384 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5386 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
5387 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
5389 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
5390 ddsd
.lpSurface
= data
;
5393 U1(ddsd
).lPitch
= sizeof(*data
);
5394 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5395 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5397 memset(data
, 0xaa, sizeof(data
));
5398 hr
= IDirectDrawSurface3_GetDC(surface3
, &dc
);
5399 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5400 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
5401 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
5402 hr
= IDirectDrawSurface3_ReleaseDC(surface3
, dc
);
5403 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5405 for (y
= 0; y
< 4; y
++)
5407 for (x
= 0; x
< 4; x
++)
5409 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
5410 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5413 ok(data
[y
][x
] == 0x00000000, "Expected color 0xaaaaaaaa on position %ux%u, got %#x.\n",
5417 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5419 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5421 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5423 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5426 IDirectDrawSurface3_Release(surface3
);
5427 ref
= IDirectDraw2_Release(ddraw
);
5428 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5429 DestroyWindow(window
);
5432 static void test_sysmem_overlay(void)
5434 IDirectDraw2
*ddraw
;
5438 IDirectDrawSurface
*surface
;
5441 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5442 0, 0, 640, 480, 0, 0, 0, 0);
5443 ddraw
= create_ddraw();
5444 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5446 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5447 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5450 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
5453 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
5454 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5455 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5456 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5457 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5458 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5459 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5460 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5461 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
5463 ref
= IDirectDraw2_Release(ddraw
);
5464 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5465 DestroyWindow(window
);
5468 static void test_primary_palette(void)
5470 DDSCAPS surface_caps
= {DDSCAPS_FLIP
};
5471 IDirectDrawSurface
*primary
, *backbuffer
;
5472 PALETTEENTRY palette_entries
[256];
5473 IDirectDrawPalette
*palette
, *tmp
;
5474 DDSURFACEDESC surface_desc
;
5475 IDirectDraw2
*ddraw
;
5481 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5482 0, 0, 640, 480, 0, 0, 0, 0);
5483 ddraw
= create_ddraw();
5484 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5485 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
5487 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5488 IDirectDraw2_Release(ddraw
);
5489 DestroyWindow(window
);
5492 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5493 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5495 memset(&surface_desc
, 0, sizeof(surface_desc
));
5496 surface_desc
.dwSize
= sizeof(surface_desc
);
5497 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
5498 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
5499 surface_desc
.dwBackBufferCount
= 1;
5500 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
5501 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5502 hr
= IDirectDrawSurface_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
5503 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5505 memset(palette_entries
, 0, sizeof(palette_entries
));
5506 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
5507 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5508 refcount
= get_refcount((IUnknown
*)palette
);
5509 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5511 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5512 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5513 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5515 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5516 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5518 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
5519 * and is generally somewhat broken with respect to 8 bpp / palette
5521 if (SUCCEEDED(IDirectDrawSurface_GetPalette(backbuffer
, &tmp
)))
5523 win_skip("Broken palette handling detected, skipping tests.\n");
5524 IDirectDrawPalette_Release(tmp
);
5525 IDirectDrawPalette_Release(palette
);
5526 /* The Windows 8 testbot keeps extra references to the primary and
5527 * backbuffer while in 8 bpp mode. */
5528 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
5529 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
5533 refcount
= get_refcount((IUnknown
*)palette
);
5534 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5536 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5537 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5538 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
5539 "Got unexpected palette caps %#x.\n", palette_caps
);
5541 hr
= IDirectDrawSurface_SetPalette(primary
, NULL
);
5542 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5543 refcount
= get_refcount((IUnknown
*)palette
);
5544 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5546 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5547 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5548 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5550 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5551 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5552 refcount
= get_refcount((IUnknown
*)palette
);
5553 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5555 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
5556 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
5557 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
5558 IDirectDrawPalette_Release(tmp
);
5559 hr
= IDirectDrawSurface_GetPalette(backbuffer
, &tmp
);
5560 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5562 refcount
= IDirectDrawPalette_Release(palette
);
5563 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5564 refcount
= IDirectDrawPalette_Release(palette
);
5565 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5567 /* Note that this only seems to work when the palette is attached to the
5568 * primary surface. When attached to a regular surface, attempting to get
5569 * the palette here will cause an access violation. */
5570 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
5571 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5574 refcount
= IDirectDrawSurface_Release(backbuffer
);
5575 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5576 refcount
= IDirectDrawSurface_Release(primary
);
5577 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5578 refcount
= IDirectDraw2_Release(ddraw
);
5579 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5580 DestroyWindow(window
);
5583 static HRESULT WINAPI
surface_counter(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
5585 UINT
*surface_count
= context
;
5588 IDirectDrawSurface_Release(surface
);
5590 return DDENUMRET_OK
;
5593 static void test_surface_attachment(void)
5595 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
5596 DDSCAPS caps
= {DDSCAPS_TEXTURE
};
5597 DDSURFACEDESC surface_desc
;
5598 IDirectDraw2
*ddraw
;
5604 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5605 0, 0, 640, 480, 0, 0, 0, 0);
5606 ddraw
= create_ddraw();
5607 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5608 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5609 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5611 memset(&surface_desc
, 0, sizeof(surface_desc
));
5612 surface_desc
.dwSize
= sizeof(surface_desc
);
5613 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
5614 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
5615 U2(surface_desc
).dwMipMapCount
= 3;
5616 surface_desc
.dwWidth
= 128;
5617 surface_desc
.dwHeight
= 128;
5618 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5619 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5621 hr
= IDirectDrawSurface_GetAttachedSurface(surface1
, &caps
, &surface2
);
5622 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5623 hr
= IDirectDrawSurface_GetAttachedSurface(surface2
, &caps
, &surface3
);
5624 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5625 hr
= IDirectDrawSurface_GetAttachedSurface(surface3
, &caps
, &surface4
);
5626 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5629 IDirectDrawSurface_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
5630 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5632 IDirectDrawSurface_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
5633 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5635 IDirectDrawSurface_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
5636 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
5638 memset(&surface_desc
, 0, sizeof(surface_desc
));
5639 surface_desc
.dwSize
= sizeof(surface_desc
);
5640 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5641 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
5642 surface_desc
.dwWidth
= 16;
5643 surface_desc
.dwHeight
= 16;
5644 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5645 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5647 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
5648 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5649 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5650 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5651 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
5652 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5653 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
5654 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5655 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
5656 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5657 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
5658 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5660 IDirectDrawSurface_Release(surface4
);
5662 memset(&surface_desc
, 0, sizeof(surface_desc
));
5663 surface_desc
.dwSize
= sizeof(surface_desc
);
5664 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5665 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5666 surface_desc
.dwWidth
= 16;
5667 surface_desc
.dwHeight
= 16;
5668 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5669 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5671 if (SUCCEEDED(hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
)))
5673 skip("Running on refrast, skipping some tests.\n");
5674 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface4
);
5675 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5679 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5680 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5681 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5682 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
5683 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5684 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
5685 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5686 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
5687 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5688 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
5689 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5692 IDirectDrawSurface_Release(surface4
);
5693 IDirectDrawSurface_Release(surface3
);
5694 IDirectDrawSurface_Release(surface2
);
5695 IDirectDrawSurface_Release(surface1
);
5697 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5698 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5700 /* Try a single primary and two offscreen plain surfaces. */
5701 memset(&surface_desc
, 0, sizeof(surface_desc
));
5702 surface_desc
.dwSize
= sizeof(surface_desc
);
5703 surface_desc
.dwFlags
= DDSD_CAPS
;
5704 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
5705 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5706 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5708 memset(&surface_desc
, 0, sizeof(surface_desc
));
5709 surface_desc
.dwSize
= sizeof(surface_desc
);
5710 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5711 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5712 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
5713 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
5714 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5715 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5717 memset(&surface_desc
, 0, sizeof(surface_desc
));
5718 surface_desc
.dwSize
= sizeof(surface_desc
);
5719 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5720 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5721 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
5722 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
5723 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5724 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5726 /* This one has a different size. */
5727 memset(&surface_desc
, 0, sizeof(surface_desc
));
5728 surface_desc
.dwSize
= sizeof(surface_desc
);
5729 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5730 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5731 surface_desc
.dwWidth
= 128;
5732 surface_desc
.dwHeight
= 128;
5733 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5734 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5736 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5737 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5738 /* Try the reverse without detaching first. */
5739 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
5740 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5741 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5742 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5744 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
5745 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5746 /* Try to detach reversed. */
5747 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5748 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5749 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
5750 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5752 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
);
5753 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5754 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
5755 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5757 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
5758 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5759 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5760 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5762 IDirectDrawSurface_Release(surface4
);
5763 IDirectDrawSurface_Release(surface3
);
5764 IDirectDrawSurface_Release(surface2
);
5765 IDirectDrawSurface_Release(surface1
);
5767 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
5768 memset(&surface_desc
, 0, sizeof(surface_desc
));
5769 surface_desc
.dwSize
= sizeof(surface_desc
);
5770 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5771 surface_desc
.dwWidth
= 64;
5772 surface_desc
.dwHeight
= 64;
5773 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5774 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5775 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
5776 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
5777 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
5778 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
5779 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
5780 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5781 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5782 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5783 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5785 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
5786 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
5787 U1(surface_desc
.ddpfPixelFormat
).dwZBufferBitDepth
= 16;
5788 U3(surface_desc
.ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
5789 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5790 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5792 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5793 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5794 refcount
= get_refcount((IUnknown
*)surface2
);
5795 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5796 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5797 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5799 /* Attaching while already attached to other surface. */
5800 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface2
);
5801 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5802 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface3
, 0, surface2
);
5803 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5804 IDirectDrawSurface_Release(surface3
);
5806 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5807 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5808 refcount
= get_refcount((IUnknown
*)surface2
);
5809 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5811 /* Automatic detachment on release. */
5812 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5813 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5814 refcount
= get_refcount((IUnknown
*)surface2
);
5815 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5816 refcount
= IDirectDrawSurface_Release(surface1
);
5817 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5818 refcount
= IDirectDrawSurface_Release(surface2
);
5819 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5820 refcount
= IDirectDraw2_Release(ddraw
);
5821 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5822 DestroyWindow(window
);
5825 static void test_pixel_format(void)
5827 HWND window
, window2
= NULL
;
5828 HDC hdc
, hdc2
= NULL
;
5830 int format
, test_format
;
5831 PIXELFORMATDESCRIPTOR pfd
;
5832 IDirectDraw2
*ddraw
= NULL
;
5833 IDirectDrawClipper
*clipper
= NULL
;
5835 IDirectDrawSurface
*primary
= NULL
;
5839 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
5840 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
5843 skip("Failed to create window\n");
5847 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
5848 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
5850 hdc
= GetDC(window
);
5853 skip("Failed to get DC\n");
5858 hdc2
= GetDC(window2
);
5860 gl
= LoadLibraryA("opengl32.dll");
5861 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
5863 format
= GetPixelFormat(hdc
);
5864 ok(format
== 0, "new window has pixel format %d\n", format
);
5866 ZeroMemory(&pfd
, sizeof(pfd
));
5867 pfd
.nSize
= sizeof(pfd
);
5869 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
5870 pfd
.iPixelType
= PFD_TYPE_RGBA
;
5871 pfd
.iLayerType
= PFD_MAIN_PLANE
;
5872 format
= ChoosePixelFormat(hdc
, &pfd
);
5875 skip("no pixel format available\n");
5879 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
5881 skip("failed to set pixel format\n");
5885 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
5887 skip("failed to set pixel format on second window\n");
5890 ReleaseDC(window2
, hdc2
);
5895 ddraw
= create_ddraw();
5896 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5898 test_format
= GetPixelFormat(hdc
);
5899 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5901 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5904 skip("Failed to set cooperative level, hr %#x.\n", hr
);
5908 test_format
= GetPixelFormat(hdc
);
5909 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5913 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
5914 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
5915 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
5916 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
5918 test_format
= GetPixelFormat(hdc
);
5919 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5921 test_format
= GetPixelFormat(hdc2
);
5922 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
5925 memset(&ddsd
, 0, sizeof(ddsd
));
5926 ddsd
.dwSize
= sizeof(ddsd
);
5927 ddsd
.dwFlags
= DDSD_CAPS
;
5928 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
5930 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
5931 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
5933 test_format
= GetPixelFormat(hdc
);
5934 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5938 test_format
= GetPixelFormat(hdc2
);
5939 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
5944 hr
= IDirectDrawSurface2_SetClipper(primary
, clipper
);
5945 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
5947 test_format
= GetPixelFormat(hdc
);
5948 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5950 test_format
= GetPixelFormat(hdc2
);
5951 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
5954 memset(&fx
, 0, sizeof(fx
));
5955 fx
.dwSize
= sizeof(fx
);
5956 hr
= IDirectDrawSurface2_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5957 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
5959 test_format
= GetPixelFormat(hdc
);
5960 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
5964 test_format
= GetPixelFormat(hdc2
);
5965 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
5969 if (primary
) IDirectDrawSurface2_Release(primary
);
5970 if (clipper
) IDirectDrawClipper_Release(clipper
);
5971 if (ddraw
) IDirectDraw2_Release(ddraw
);
5972 if (gl
) FreeLibrary(gl
);
5973 if (hdc
) ReleaseDC(window
, hdc
);
5974 if (hdc2
) ReleaseDC(window2
, hdc2
);
5975 if (window
) DestroyWindow(window
);
5976 if (window2
) DestroyWindow(window2
);
5979 static void test_create_surface_pitch(void)
5981 IDirectDrawSurface
*surface
;
5982 DDSURFACEDESC surface_desc
;
5983 IDirectDraw2
*ddraw
;
6003 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6005 DDSD_PITCH
, 0x100, 0x100},
6006 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6007 DDSD_PITCH
, 0x104, DD_OK
,
6008 DDSD_PITCH
, 0x100, 0x100},
6009 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6010 DDSD_PITCH
, 0x0f8, DD_OK
,
6011 DDSD_PITCH
, 0x100, 0x100},
6012 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6013 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
6015 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6017 DDSD_PITCH
, 0x100, 0x0fc},
6019 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6020 DDSD_PITCH
, 0x104, DD_OK
,
6021 DDSD_PITCH
, 0x100, 0x0fc},
6022 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6023 DDSD_PITCH
, 0x0f8, DD_OK
,
6024 DDSD_PITCH
, 0x100, 0x0fc},
6025 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6026 DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
6027 DDSD_PITCH
, 0x100, 0x0fc},
6028 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6029 DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
6031 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6032 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
6035 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
6036 0, 0, DDERR_INVALIDCAPS
,
6038 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6040 DDSD_PITCH
, 0x100, 0 },
6041 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6042 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
6044 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
6045 0, 0, DDERR_INVALIDCAPS
,
6047 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6049 DDSD_PITCH
, 0x100, 0 },
6051 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6052 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
6055 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
6057 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6058 0, 0, 640, 480, 0, 0, 0, 0);
6059 ddraw
= create_ddraw();
6060 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6061 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6062 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6064 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
6066 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6068 memset(&surface_desc
, 0, sizeof(surface_desc
));
6069 surface_desc
.dwSize
= sizeof(surface_desc
);
6070 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
6071 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
6072 surface_desc
.dwWidth
= 63;
6073 surface_desc
.dwHeight
= 63;
6074 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
6075 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6076 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6077 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6078 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6079 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6080 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6081 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6082 if (test_data
[i
].flags_in
& DDSD_LPSURFACE
)
6084 HRESULT expected_hr
= SUCCEEDED(test_data
[i
].hr
) ? DDERR_INVALIDPARAMS
: test_data
[i
].hr
;
6085 ok(hr
== expected_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, expected_hr
);
6086 surface_desc
.lpSurface
= mem
;
6087 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6089 if ((test_data
[i
].caps
& DDSCAPS_VIDEOMEMORY
) && hr
== DDERR_NODIRECTDRAWHW
)
6091 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
6095 memset(&surface_desc
, 0, sizeof(surface_desc
));
6096 surface_desc
.dwSize
= sizeof(surface_desc
);
6097 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
6098 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
6099 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
6100 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6101 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
6102 /* The pitch for textures seems to be implementation specific. */
6103 if (!(test_data
[i
].caps
& DDSCAPS_TEXTURE
))
6105 if (is_ddraw64
&& test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
6106 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
6107 "Test %u: Got unexpected pitch %u, expected %u.\n",
6108 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
6110 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
6111 "Test %u: Got unexpected pitch %u, expected %u.\n",
6112 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
6114 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
6116 IDirectDrawSurface_Release(surface
);
6119 HeapFree(GetProcessHeap(), 0, mem
);
6120 refcount
= IDirectDraw2_Release(ddraw
);
6121 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6122 DestroyWindow(window
);
6125 static void test_mipmap(void)
6127 IDirectDrawSurface
*surface1
;
6128 IDirectDrawSurface2
*surface
, *surface2
;
6129 DDSURFACEDESC surface_desc
;
6130 IDirectDraw2
*ddraw
;
6135 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
6144 DWORD mipmap_count_in
;
6146 DWORD mipmap_count_out
;
6150 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 3, DD_OK
, 3},
6151 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDPARAMS
, 0},
6152 {0, DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 1},
6153 {0, DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDCAPS
, 0},
6154 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 6},
6155 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 32, 64, 0, DD_OK
, 6},
6158 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6159 0, 0, 640, 480, 0, 0, 0, 0);
6160 ddraw
= create_ddraw();
6161 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6162 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6163 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6165 memset(&hal_caps
, 0, sizeof(hal_caps
));
6166 hal_caps
.dwSize
= sizeof(hal_caps
);
6167 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
6168 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6169 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6171 skip("Mipmapped textures not supported, skipping tests.\n");
6172 IDirectDraw2_Release(ddraw
);
6173 DestroyWindow(window
);
6177 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
6179 memset(&surface_desc
, 0, sizeof(surface_desc
));
6180 surface_desc
.dwSize
= sizeof(surface_desc
);
6181 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| tests
[i
].flags
;
6182 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
6183 surface_desc
.dwWidth
= tests
[i
].width
;
6184 surface_desc
.dwHeight
= tests
[i
].height
;
6185 if (tests
[i
].flags
& DDSD_MIPMAPCOUNT
)
6186 U2(surface_desc
).dwMipMapCount
= tests
[i
].mipmap_count_in
;
6187 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6188 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
6192 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
6193 ok(SUCCEEDED(hr
), "Test %u: Failed to get IDirectDrawSurface2 interface, hr %#x.\n", i
, hr
);
6194 IDirectDrawSurface_Release(surface1
);
6196 memset(&surface_desc
, 0, sizeof(surface_desc
));
6197 surface_desc
.dwSize
= sizeof(surface_desc
);
6198 hr
= IDirectDrawSurface2_GetSurfaceDesc(surface
, &surface_desc
);
6199 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
6200 ok(surface_desc
.dwFlags
& DDSD_MIPMAPCOUNT
,
6201 "Test %u: Got unexpected flags %#x.\n", i
, surface_desc
.dwFlags
);
6202 ok(U2(surface_desc
).dwMipMapCount
== tests
[i
].mipmap_count_out
,
6203 "Test %u: Got unexpected mipmap count %u.\n", i
, U2(surface_desc
).dwMipMapCount
);
6205 if (U2(surface_desc
).dwMipMapCount
> 1)
6207 hr
= IDirectDrawSurface2_GetAttachedSurface(surface
, &caps
, &surface2
);
6208 ok(SUCCEEDED(hr
), "Test %u: Failed to get attached surface, hr %#x.\n", i
, hr
);
6210 memset(&surface_desc
, 0, sizeof(surface_desc
));
6211 surface_desc
.dwSize
= sizeof(surface_desc
);
6212 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
6213 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
6214 memset(&surface_desc
, 0, sizeof(surface_desc
));
6215 surface_desc
.dwSize
= sizeof(surface_desc
);
6216 hr
= IDirectDrawSurface2_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
6217 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
6218 IDirectDrawSurface2_Unlock(surface2
, NULL
);
6219 IDirectDrawSurface2_Unlock(surface
, NULL
);
6221 IDirectDrawSurface2_Release(surface2
);
6224 IDirectDrawSurface2_Release(surface
);
6227 refcount
= IDirectDraw2_Release(ddraw
);
6228 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6229 DestroyWindow(window
);
6232 static void test_palette_complex(void)
6234 IDirectDrawSurface
*surface1
;
6235 IDirectDrawSurface2
*surface
, *mipmap
, *tmp
;
6236 DDSURFACEDESC surface_desc
;
6237 IDirectDraw2
*ddraw
;
6238 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
6242 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
6244 PALETTEENTRY palette_entries
[256];
6250 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6251 0, 0, 640, 480, 0, 0, 0, 0);
6252 ddraw
= create_ddraw();
6253 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6254 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6255 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6257 memset(&hal_caps
, 0, sizeof(hal_caps
));
6258 hal_caps
.dwSize
= sizeof(hal_caps
);
6259 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
6260 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6261 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6263 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
6264 IDirectDraw2_Release(ddraw
);
6265 DestroyWindow(window
);
6269 memset(&surface_desc
, 0, sizeof(surface_desc
));
6270 surface_desc
.dwSize
= sizeof(surface_desc
);
6271 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6272 surface_desc
.dwWidth
= 128;
6273 surface_desc
.dwHeight
= 128;
6274 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6275 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6276 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6277 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6278 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6279 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6280 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
6281 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
6282 IDirectDrawSurface_Release(surface1
);
6284 memset(palette_entries
, 0, sizeof(palette_entries
));
6285 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6286 palette_entries
, &palette
, NULL
);
6287 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6289 memset(palette_entries
, 0, sizeof(palette_entries
));
6290 palette_entries
[1].peRed
= 0xff;
6291 palette_entries
[1].peGreen
= 0x80;
6292 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6293 palette_entries
, &palette_mipmap
, NULL
);
6294 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6296 palette2
= (void *)0xdeadbeef;
6297 hr
= IDirectDrawSurface2_GetPalette(surface
, &palette2
);
6298 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6299 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
6300 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
6301 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6302 hr
= IDirectDrawSurface2_GetPalette(surface
, &palette2
);
6303 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6304 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
6305 IDirectDrawPalette_Release(palette2
);
6308 IDirectDrawSurface2_AddRef(mipmap
);
6309 for (i
= 0; i
< 7; ++i
)
6311 hr
= IDirectDrawSurface2_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6312 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
6313 palette2
= (void *)0xdeadbeef;
6314 hr
= IDirectDrawSurface2_GetPalette(tmp
, &palette2
);
6315 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
6316 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
6318 hr
= IDirectDrawSurface2_SetPalette(tmp
, palette_mipmap
);
6319 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
6321 hr
= IDirectDrawSurface2_GetPalette(tmp
, &palette2
);
6322 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
6323 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
6324 IDirectDrawPalette_Release(palette2
);
6326 hr
= IDirectDrawSurface2_GetDC(tmp
, &dc
);
6327 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
6328 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
6329 ok(count
== 1, "Expected count 1, got %u.\n", count
);
6330 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
6331 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
6332 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
6333 hr
= IDirectDrawSurface2_ReleaseDC(tmp
, dc
);
6334 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
6336 IDirectDrawSurface2_Release(mipmap
);
6340 hr
= IDirectDrawSurface2_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6341 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6342 IDirectDrawSurface2_Release(mipmap
);
6343 refcount
= IDirectDrawSurface2_Release(surface
);
6344 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6345 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
6346 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6347 refcount
= IDirectDrawPalette_Release(palette
);
6348 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6350 refcount
= IDirectDraw2_Release(ddraw
);
6351 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6352 DestroyWindow(window
);
6355 static BOOL
ddraw_is_warp(IDirectDraw2
*ddraw
)
6357 IDirectDraw4
*ddraw4
;
6358 DDDEVICEIDENTIFIER identifier
;
6361 if (!strcmp(winetest_platform
, "wine"))
6364 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
6365 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
6366 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, &identifier
, 0);
6367 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
6368 IDirectDraw4_Release(ddraw4
);
6369 return !!strstr(identifier
.szDriver
, "warp");
6372 static void test_p8_blit(void)
6374 IDirectDrawSurface
*src
, *dst
, *dst_p8
;
6375 DDSURFACEDESC surface_desc
;
6376 IDirectDraw2
*ddraw
;
6377 IDirectDrawPalette
*palette
, *palette2
;
6381 PALETTEENTRY palette_entries
[256];
6385 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
6386 static const BYTE src_data2
[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
6387 static const BYTE expected_p8
[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
6388 static const D3DCOLOR expected
[] =
6390 0x00101010, 0x00010101, 0x00020202, 0x00030303,
6391 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
6395 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6396 0, 0, 640, 480, 0, 0, 0, 0);
6397 ddraw
= create_ddraw();
6398 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6399 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6400 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6401 is_warp
= ddraw_is_warp(ddraw
);
6403 memset(palette_entries
, 0, sizeof(palette_entries
));
6404 palette_entries
[1].peGreen
= 0xff;
6405 palette_entries
[2].peBlue
= 0xff;
6406 palette_entries
[3].peFlags
= 0xff;
6407 palette_entries
[4].peRed
= 0xff;
6408 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6409 palette_entries
, &palette
, NULL
);
6410 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6411 palette_entries
[1].peBlue
= 0xff;
6412 palette_entries
[2].peGreen
= 0xff;
6413 palette_entries
[3].peRed
= 0xff;
6414 palette_entries
[4].peFlags
= 0x0;
6415 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6416 palette_entries
, &palette2
, NULL
);
6417 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6419 memset(&surface_desc
, 0, sizeof(surface_desc
));
6420 surface_desc
.dwSize
= sizeof(surface_desc
);
6421 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6422 surface_desc
.dwWidth
= 8;
6423 surface_desc
.dwHeight
= 1;
6424 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6425 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6426 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6427 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6428 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
6429 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6430 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst_p8
, NULL
);
6431 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6432 hr
= IDirectDrawSurface_SetPalette(dst_p8
, palette2
);
6433 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6435 memset(&surface_desc
, 0, sizeof(surface_desc
));
6436 surface_desc
.dwSize
= sizeof(surface_desc
);
6437 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6438 surface_desc
.dwWidth
= 8;
6439 surface_desc
.dwHeight
= 1;
6440 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6441 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6442 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6443 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6444 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6445 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6446 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6447 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6448 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
6449 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6451 memset(&surface_desc
, 0, sizeof(surface_desc
));
6452 surface_desc
.dwSize
= sizeof(surface_desc
);
6453 hr
= IDirectDrawSurface_Lock(src
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
6454 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
6455 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
6456 hr
= IDirectDrawSurface_Unlock(src
, NULL
);
6457 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
6459 hr
= IDirectDrawSurface_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
6460 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
6461 memcpy(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
));
6462 hr
= IDirectDrawSurface_Unlock(dst_p8
, NULL
);
6463 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
6465 hr
= IDirectDrawSurface_SetPalette(src
, palette
);
6466 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6467 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
6468 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
6469 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
6470 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
6471 "Failed to blit, hr %#x.\n", hr
);
6475 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
6477 color
= get_surface_color(dst
, x
, 0);
6478 todo_wine
ok(compare_color(color
, expected
[x
], 0),
6479 "Pixel %u: Got color %#x, expected %#x.\n",
6480 x
, color
, expected
[x
]);
6484 memset(&fx
, 0, sizeof(fx
));
6485 fx
.dwSize
= sizeof(fx
);
6486 fx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 0x2;
6487 fx
.ddckSrcColorkey
.dwColorSpaceLowValue
= 0x2;
6488 hr
= IDirectDrawSurface7_Blt(dst_p8
, NULL
, src
, NULL
, DDBLT_WAIT
| DDBLT_KEYSRCOVERRIDE
, &fx
);
6489 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
6491 hr
= IDirectDrawSurface_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
6492 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
6493 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
6494 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
6495 * for example) also works as expected.
6497 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
6498 * the display mode set to P8 doesn't help either. */
6499 ok(!memcmp(surface_desc
.lpSurface
, expected_p8
, sizeof(expected_p8
))
6500 || broken(is_warp
&& !memcmp(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
))),
6501 "Got unexpected P8 color key blit result.\n");
6502 hr
= IDirectDrawSurface_Unlock(dst_p8
, NULL
);
6503 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
6505 IDirectDrawSurface_Release(src
);
6506 IDirectDrawSurface_Release(dst
);
6507 IDirectDrawSurface_Release(dst_p8
);
6508 IDirectDrawPalette_Release(palette
);
6509 IDirectDrawPalette_Release(palette2
);
6511 refcount
= IDirectDraw2_Release(ddraw
);
6512 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6513 DestroyWindow(window
);
6516 static void test_material(void)
6518 IDirect3DMaterial2
*background
, *material
;
6519 D3DMATERIALHANDLE mat_handle
, tmp
;
6520 IDirect3DViewport2
*viewport
;
6521 IDirect3DDevice2
*device
;
6522 IDirectDrawSurface
*rt
;
6523 IDirectDraw2
*ddraw
;
6531 static D3DVERTEX quad
[] =
6533 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6534 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6535 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6536 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6541 D3DCOLOR expected_color
;
6546 {FALSE
, 0x00ffffff},
6548 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6550 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6551 0, 0, 640, 480, 0, 0, 0, 0);
6552 ddraw
= create_ddraw();
6553 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6554 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6556 skip("Failed to create a 3D device, skipping test.\n");
6557 DestroyWindow(window
);
6561 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6562 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6564 background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
6565 viewport
= create_viewport(device
, 0, 0, 640, 480);
6566 viewport_set_background(device
, viewport
, background
);
6567 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6568 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6570 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
6571 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6572 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6574 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6575 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6576 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6577 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6578 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6579 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6580 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6581 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6582 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, 0);
6583 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6584 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6585 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6586 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6588 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6590 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
6591 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6593 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
6594 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6596 hr
= IDirect3DDevice2_BeginScene(device
);
6597 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6598 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_VERTEX
, quad
, 4, 0);
6599 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6600 hr
= IDirect3DDevice2_EndScene(device
);
6601 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6602 color
= get_surface_color(rt
, 320, 240);
6603 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
6604 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
6607 destroy_material(material
);
6608 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
6609 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6610 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6612 hr
= IDirect3DViewport2_SetBackground(viewport
, mat_handle
);
6613 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
6614 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6615 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6616 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6617 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6618 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6619 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6620 color
= get_surface_color(rt
, 320, 240);
6621 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6623 hr
= IDirect3DViewport2_SetBackground(viewport
, 0);
6624 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6625 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6626 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6627 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6628 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6629 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6630 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6631 color
= get_surface_color(rt
, 320, 240);
6632 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6634 destroy_viewport(device
, viewport
);
6635 viewport
= create_viewport(device
, 0, 0, 640, 480);
6637 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6638 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6639 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6640 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
6641 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6642 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6643 color
= get_surface_color(rt
, 320, 240);
6644 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
6646 destroy_viewport(device
, viewport
);
6647 destroy_material(background
);
6648 destroy_material(material
);
6649 IDirectDrawSurface_Release(rt
);
6650 refcount
= IDirect3DDevice2_Release(device
);
6651 ok(!refcount
, "Device has %u references left.\n", refcount
);
6652 refcount
= IDirectDraw2_Release(ddraw
);
6653 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
6654 DestroyWindow(window
);
6657 static void test_lighting(void)
6659 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6660 static D3DMATRIX mat
=
6662 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6663 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6664 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6665 0.0f
, 0.0f
, 0.0f
, 1.0f
,
6669 1.0f
, 0.0f
, 1.0f
, 0.0f
,
6670 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6671 1.0f
, 0.0f
, 1.0f
, 0.0f
,
6672 0.0f
, 0.0f
, 0.5f
, 1.0f
,
6676 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6677 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6678 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
6679 10.f
, 10.0f
, 10.0f
, 1.0f
,
6683 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6684 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6685 0.0f
, 0.0f
, 1.0f
, -1.0f
,
6686 10.f
, 10.0f
, 10.0f
, 0.0f
,
6688 static D3DLVERTEX unlitquad
[] =
6690 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6691 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6692 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6693 {{ 0.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6697 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6698 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6699 {{ 0.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6700 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6702 static D3DVERTEX unlitnquad
[] =
6704 {{0.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6705 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6706 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6707 {{1.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6711 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6712 {{0.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6713 {{1.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6714 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6718 {{-1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6719 {{-1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6720 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6721 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6725 {{-10.0f
}, {-11.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6726 {{-10.0f
}, { -9.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6727 {{-10.0f
}, { -9.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6728 {{-10.0f
}, {-11.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6732 {{-11.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6733 {{-11.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6734 {{ -9.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6735 {{ -9.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6737 static WORD indices
[] = {0, 1, 2, 2, 3, 0};
6740 D3DMATRIX
*world_matrix
;
6743 const char *message
;
6747 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
6748 {&mat_singular
, nquad
, 0x000000b4, "Lit quad with singular world matrix"},
6749 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
6750 {&mat_nonaffine
, translatedquad
, 0x000000ff, "Lit quad with non-affine matrix"},
6755 IDirect3DDevice2
*device
;
6756 IDirectDraw2
*ddraw
;
6757 IDirectDrawSurface
*rt
;
6758 IDirect3DViewport2
*viewport
;
6759 IDirect3DMaterial2
*material
;
6760 IDirect3DLight
*light
;
6761 D3DMATERIALHANDLE mat_handle
;
6762 D3DLIGHT2 light_desc
;
6768 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6769 0, 0, 640, 480, 0, 0, 0, 0);
6770 ddraw
= create_ddraw();
6771 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6772 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6774 skip("Failed to create a 3D device, skipping test.\n");
6775 DestroyWindow(window
);
6779 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
6780 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
6782 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6783 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6785 viewport
= create_viewport(device
, 0, 0, 640, 480);
6786 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6787 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6789 material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
6790 viewport_set_background(device
, viewport
, material
);
6792 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6793 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6795 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
6796 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
6797 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
6798 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
6799 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
6800 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
6801 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
6802 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
6803 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
6804 ok(SUCCEEDED(hr
), "Failed to disable zbuffer, hr %#x.\n", hr
);
6805 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
6806 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
6807 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
6808 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
6810 hr
= IDirect3DDevice2_BeginScene(device
);
6811 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6813 /* There is no D3DRENDERSTATE_LIGHTING on ddraw < 7. */
6814 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
6815 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6816 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_LVERTEX
, unlitquad
,
6818 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6820 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
6821 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
6822 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_LVERTEX
, litquad
,
6824 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6826 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
6827 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6828 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, unlitnquad
,
6830 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6832 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
6833 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6834 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, litnquad
,
6836 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6838 hr
= IDirect3DDevice2_EndScene(device
);
6839 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6841 color
= get_surface_color(rt
, 160, 360);
6842 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color
);
6843 color
= get_surface_color(rt
, 160, 120);
6844 ok(color
== 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color
);
6845 color
= get_surface_color(rt
, 480, 360);
6846 ok(color
== 0x00ffffff, "Unlit quad with normals has color 0x%08x.\n", color
);
6847 color
= get_surface_color(rt
, 480, 120);
6848 ok(color
== 0x00ffffff, "Lit quad with normals has color 0x%08x.\n", color
);
6850 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6851 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6852 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6853 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6855 hr
= IDirect3D2_CreateLight(d3d
, &light
, NULL
);
6856 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
6857 memset(&light_desc
, 0, sizeof(light_desc
));
6858 light_desc
.dwSize
= sizeof(light_desc
);
6859 light_desc
.dltType
= D3DLIGHT_DIRECTIONAL
;
6860 U1(light_desc
.dcvColor
).r
= 0.0f
;
6861 U2(light_desc
.dcvColor
).g
= 0.0f
;
6862 U3(light_desc
.dcvColor
).b
= 1.0f
;
6863 U4(light_desc
.dcvColor
).a
= 1.0f
;
6864 U3(light_desc
.dvDirection
).z
= 1.0f
;
6865 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
6866 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
6867 hr
= IDirect3DViewport2_AddLight(viewport
, light
);
6868 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
6870 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6871 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6873 hr
= IDirect3DDevice2_BeginScene(device
);
6874 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6876 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, nquad
,
6878 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6880 hr
= IDirect3DDevice2_EndScene(device
);
6881 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6883 color
= get_surface_color(rt
, 320, 240);
6884 ok(color
== 0x00000000, "Lit quad with no light has color 0x%08x.\n", color
);
6886 light_desc
.dwFlags
= D3DLIGHT_ACTIVE
;
6887 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
6888 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
6890 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
6892 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, tests
[i
].world_matrix
);
6893 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
6895 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6896 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6898 hr
= IDirect3DDevice2_BeginScene(device
);
6899 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6901 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
,
6902 tests
[i
].quad
, 4, indices
, 6, 0);
6903 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6905 hr
= IDirect3DDevice2_EndScene(device
);
6906 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6908 color
= get_surface_color(rt
, 320, 240);
6909 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
6912 hr
= IDirect3DViewport2_DeleteLight(viewport
, light
);
6913 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
6914 IDirect3DLight_Release(light
);
6915 destroy_material(material
);
6916 destroy_viewport(device
, viewport
);
6917 IDirectDrawSurface2_Release(rt
);
6918 refcount
= IDirect3DDevice2_Release(device
);
6919 ok(!refcount
, "Device has %u references left.\n", refcount
);
6920 IDirect3D2_Release(d3d
);
6921 refcount
= IDirectDraw2_Release(ddraw
);
6922 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
6923 DestroyWindow(window
);
6926 static void test_specular_lighting(void)
6928 static const unsigned int vertices_side
= 5;
6929 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
6930 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6931 static D3DMATRIX mat
=
6933 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6934 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6935 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6936 0.0f
, 0.0f
, 0.0f
, 1.0f
,
6938 static D3DLIGHT2 directional
=
6941 D3DLIGHT_DIRECTIONAL
,
6942 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
6943 {{0.0f
}, {0.0f
}, {0.0f
}},
6944 {{0.0f
}, {0.0f
}, {1.0f
}},
6950 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
6951 {{0.0f
}, {0.0f
}, {0.0f
}},
6952 {{0.0f
}, {0.0f
}, {0.0f
}},
6961 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
6962 {{0.0f
}, {0.0f
}, {0.0f
}},
6963 {{0.0f
}, {0.0f
}, {1.0f
}},
6967 M_PI
/ 12.0f
, M_PI
/ 3.0f
6972 D3DLIGHT_PARALLELPOINT
,
6973 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
6974 {{0.5f
}, {0.0f
}, {-1.0f
}},
6975 {{0.0f
}, {0.0f
}, {0.0f
}},
6977 static const struct expected_color
6982 expected_directional_local
[] =
6984 {160, 120, 0x003c3c3c},
6985 {320, 120, 0x00717171},
6986 {480, 120, 0x003c3c3c},
6987 {160, 240, 0x00717171},
6988 {320, 240, 0x00ffffff},
6989 {480, 240, 0x00717171},
6990 {160, 360, 0x003c3c3c},
6991 {320, 360, 0x00717171},
6992 {480, 360, 0x003c3c3c},
6994 expected_point_local
[] =
6996 {160, 120, 0x00000000},
6997 {320, 120, 0x00090909},
6998 {480, 120, 0x00000000},
6999 {160, 240, 0x00090909},
7000 {320, 240, 0x00fafafa},
7001 {480, 240, 0x00090909},
7002 {160, 360, 0x00000000},
7003 {320, 360, 0x00090909},
7004 {480, 360, 0x00000000},
7006 expected_spot_local
[] =
7008 {160, 120, 0x00000000},
7009 {320, 120, 0x00020202},
7010 {480, 120, 0x00000000},
7011 {160, 240, 0x00020202},
7012 {320, 240, 0x00fafafa},
7013 {480, 240, 0x00020202},
7014 {160, 360, 0x00000000},
7015 {320, 360, 0x00020202},
7016 {480, 360, 0x00000000},
7018 expected_parallelpoint
[] =
7020 {160, 120, 0x00050505},
7021 {320, 120, 0x002c2c2c},
7022 {480, 120, 0x006e6e6e},
7023 {160, 240, 0x00090909},
7024 {320, 240, 0x00717171},
7025 {480, 240, 0x00ffffff},
7026 {160, 360, 0x00050505},
7027 {320, 360, 0x002c2c2c},
7028 {480, 360, 0x006e6e6e},
7033 const struct expected_color
*expected
;
7034 unsigned int expected_count
;
7038 {&directional
, expected_directional_local
,
7039 sizeof(expected_directional_local
) / sizeof(expected_directional_local
[0])},
7040 {&point
, expected_point_local
,
7041 sizeof(expected_point_local
) / sizeof(expected_point_local
[0])},
7042 {&spot
, expected_spot_local
,
7043 sizeof(expected_spot_local
) / sizeof(expected_spot_local
[0])},
7044 {¶llelpoint
, expected_parallelpoint
,
7045 sizeof(expected_parallelpoint
) / sizeof(expected_parallelpoint
[0])},
7048 IDirect3DDevice2
*device
;
7049 IDirectDraw2
*ddraw
;
7050 IDirectDrawSurface
*rt
;
7051 IDirect3DViewport2
*viewport
;
7052 IDirect3DMaterial2
*material
, *background_material
;
7053 IDirect3DLight
*light
;
7054 D3DMATERIALHANDLE mat_handle
;
7059 unsigned int i
, j
, x
, y
;
7063 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7064 0, 0, 640, 480, 0, 0, 0, 0);
7065 ddraw
= create_ddraw();
7066 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7067 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
7069 skip("Failed to create a 3D device, skipping test.\n");
7070 DestroyWindow(window
);
7074 quad
= HeapAlloc(GetProcessHeap(), 0, vertices_side
* vertices_side
* sizeof(*quad
));
7075 indices
= HeapAlloc(GetProcessHeap(), 0, indices_count
* sizeof(*indices
));
7076 for (i
= 0, y
= 0; y
< vertices_side
; ++y
)
7078 for (x
= 0; x
< vertices_side
; ++x
)
7080 U1(quad
[i
]).x
= x
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
7081 U2(quad
[i
]).y
= y
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
7082 U3(quad
[i
]).z
= 1.0f
;
7083 U4(quad
[i
]).nx
= 0.0f
;
7084 U5(quad
[i
]).ny
= 0.0f
;
7085 U6(quad
[i
]).nz
= -1.0f
;
7086 U7(quad
[i
]).tu
= 0.0f
;
7087 U8(quad
[i
++]).tv
= 0.0f
;
7090 for (i
= 0, y
= 0; y
< (vertices_side
- 1); ++y
)
7092 for (x
= 0; x
< (vertices_side
- 1); ++x
)
7094 indices
[i
++] = y
* vertices_side
+ x
+ 1;
7095 indices
[i
++] = y
* vertices_side
+ x
;
7096 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
7097 indices
[i
++] = y
* vertices_side
+ x
+ 1;
7098 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
7099 indices
[i
++] = (y
+ 1) * vertices_side
+ x
+ 1;
7103 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
7104 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
7106 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
7107 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
7109 viewport
= create_viewport(device
, 0, 0, 640, 480);
7110 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
7111 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
7113 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
7114 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
7115 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
7116 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
7117 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
7118 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
7119 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
7120 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
7121 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
7122 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
7123 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
7124 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
7126 background_material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
7127 viewport_set_background(device
, viewport
, background_material
);
7129 material
= create_specular_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 30.0f
);
7130 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
7131 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
7132 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
7133 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
7135 hr
= IDirect3D2_CreateLight(d3d
, &light
, NULL
);
7136 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
7137 hr
= IDirect3DViewport2_AddLight(viewport
, light
);
7138 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
7140 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, TRUE
);
7141 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
7143 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
7145 tests
[i
].light
->dwFlags
= D3DLIGHT_ACTIVE
;
7146 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)tests
[i
].light
);
7147 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
7149 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7150 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7152 hr
= IDirect3DDevice2_BeginScene(device
);
7153 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7155 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
,
7156 quad
, vertices_side
* vertices_side
, indices
, indices_count
, 0);
7157 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7159 hr
= IDirect3DDevice2_EndScene(device
);
7160 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7162 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
7164 color
= get_surface_color(rt
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
7165 ok(compare_color(color
, tests
[i
].expected
[j
].color
, 1),
7166 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
7167 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
7168 tests
[i
].expected
[j
].y
, color
, i
);
7172 hr
= IDirect3DViewport2_DeleteLight(viewport
, light
);
7173 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
7174 IDirect3DLight_Release(light
);
7175 destroy_material(material
);
7176 destroy_material(background_material
);
7177 destroy_viewport(device
, viewport
);
7178 IDirectDrawSurface2_Release(rt
);
7179 refcount
= IDirect3DDevice2_Release(device
);
7180 ok(!refcount
, "Device has %u references left.\n", refcount
);
7181 IDirect3D2_Release(d3d
);
7182 refcount
= IDirectDraw2_Release(ddraw
);
7183 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
7184 DestroyWindow(window
);
7185 HeapFree(GetProcessHeap(), 0, indices
);
7186 HeapFree(GetProcessHeap(), 0, quad
);
7189 static void test_palette_gdi(void)
7191 IDirectDrawSurface
*surface
, *primary
;
7192 DDSURFACEDESC surface_desc
;
7193 IDirectDraw2
*ddraw
;
7194 IDirectDrawPalette
*palette
, *palette2
;
7198 PALETTEENTRY palette_entries
[256];
7204 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7205 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7206 * not the point of this test. */
7207 static const RGBQUAD expected1
[] =
7209 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7210 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7212 static const RGBQUAD expected2
[] =
7214 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7215 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7217 static const RGBQUAD expected3
[] =
7219 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7220 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7222 HPALETTE ddraw_palette_handle
;
7223 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7224 RGBQUAD rgbquad
[255];
7225 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
7227 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7228 0, 0, 640, 480, 0, 0, 0, 0);
7229 ddraw
= create_ddraw();
7230 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7231 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7232 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7234 memset(&surface_desc
, 0, sizeof(surface_desc
));
7235 surface_desc
.dwSize
= sizeof(surface_desc
);
7236 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7237 surface_desc
.dwWidth
= 16;
7238 surface_desc
.dwHeight
= 16;
7239 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7240 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7241 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7242 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
7243 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7244 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7246 /* Avoid colors from the Windows default palette. */
7247 memset(palette_entries
, 0, sizeof(palette_entries
));
7248 palette_entries
[1].peRed
= 0x01;
7249 palette_entries
[2].peGreen
= 0x02;
7250 palette_entries
[3].peBlue
= 0x03;
7251 palette_entries
[4].peRed
= 0x13;
7252 palette_entries
[4].peGreen
= 0x14;
7253 palette_entries
[4].peBlue
= 0x15;
7254 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7255 palette_entries
, &palette
, NULL
);
7256 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7258 /* If there is no palette assigned and the display mode is not 8 bpp, some
7259 * drivers refuse to create a DC while others allow it. If a DC is created,
7260 * the DIB color table is uninitialized and contains random colors. No error
7261 * is generated when trying to read pixels and random garbage is returned.
7263 * The most likely explanation is that if the driver creates a DC, it (or
7264 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7265 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7266 * contains uninitialized garbage. See comments below for the P8 case. */
7268 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
7269 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7270 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7271 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7272 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7273 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7274 "Got unexpected palette %p, expected %p.\n",
7275 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7277 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7278 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7279 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
7281 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
7282 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7283 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7284 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
7286 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7288 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7289 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7290 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7293 /* Update the palette while the DC is in use. This does not modify the DC. */
7294 palette_entries
[4].peRed
= 0x23;
7295 palette_entries
[4].peGreen
= 0x24;
7296 palette_entries
[4].peBlue
= 0x25;
7297 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
7298 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
7300 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7301 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7302 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7303 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7304 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7305 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7307 /* Neither does re-setting the palette. */
7308 hr
= IDirectDrawSurface_SetPalette(surface
, NULL
);
7309 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7310 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
7311 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7313 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7314 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7315 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7316 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7317 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7318 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7320 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7321 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7323 /* Refresh the DC. This updates the palette. */
7324 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7325 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7326 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7327 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7328 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7330 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7331 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7332 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7333 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7335 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7337 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7338 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7339 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7341 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7342 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7344 refcount
= IDirectDrawSurface_Release(surface
);
7345 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7347 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
7348 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7349 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7351 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7352 IDirectDrawPalette_Release(palette
);
7353 IDirectDraw2_Release(ddraw
);
7354 DestroyWindow(window
);
7357 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
7359 memset(&surface_desc
, 0, sizeof(surface_desc
));
7360 surface_desc
.dwSize
= sizeof(surface_desc
);
7361 surface_desc
.dwFlags
= DDSD_CAPS
;
7362 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7363 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
7364 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7366 memset(&fx
, 0, sizeof(fx
));
7367 fx
.dwSize
= sizeof(fx
);
7369 SetRect(&r
, 0, 0, 319, 479);
7370 hr
= IDirectDrawSurface_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7371 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
7372 SetRect(&r
, 320, 0, 639, 479);
7374 hr
= IDirectDrawSurface_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7375 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
7377 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
7378 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7379 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
7380 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7382 color
= GetPixel(dc
, 160, 240);
7383 ok(color
== 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color
);
7384 color
= GetPixel(dc
, 480, 240);
7385 ok(color
== 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color
);
7387 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7388 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
7389 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
7390 "Got unexpected palette %p, expected %p.\n",
7391 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7392 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
7394 /* The primary uses the system palette. In exclusive mode, the system palette matches
7395 * the ddraw palette attached to the primary, so the result is what you would expect
7396 * from a regular surface. Tests for the interaction between the ddraw palette and
7397 * the system palette are not included pending an application that depends on this.
7398 * The relation between those causes problems on Windows Vista and newer for games
7399 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
7400 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7401 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7402 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7404 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7405 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7406 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7407 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7409 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7411 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7412 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7413 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7415 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
7416 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7418 memset(&surface_desc
, 0, sizeof(surface_desc
));
7419 surface_desc
.dwSize
= sizeof(surface_desc
);
7420 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7421 surface_desc
.dwWidth
= 16;
7422 surface_desc
.dwHeight
= 16;
7423 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7424 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7425 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7427 /* Here the offscreen surface appears to use the primary's palette,
7428 * but in all likelihood it is actually the system palette. */
7429 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7430 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7431 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7432 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7433 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7435 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7436 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7437 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7438 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7440 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7442 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7443 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7444 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7446 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7447 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7449 /* On real hardware a change to the primary surface's palette applies immediately,
7450 * even on device contexts from offscreen surfaces that do not have their own
7451 * palette. On the testbot VMs this is not the case. Don't test this until we
7452 * know of an application that depends on this. */
7454 memset(palette_entries
, 0, sizeof(palette_entries
));
7455 palette_entries
[1].peBlue
= 0x40;
7456 palette_entries
[2].peRed
= 0x40;
7457 palette_entries
[3].peGreen
= 0x40;
7458 palette_entries
[4].peRed
= 0x12;
7459 palette_entries
[4].peGreen
= 0x34;
7460 palette_entries
[4].peBlue
= 0x56;
7461 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7462 palette_entries
, &palette2
, NULL
);
7463 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7464 hr
= IDirectDrawSurface_SetPalette(surface
, palette2
);
7465 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7467 /* A palette assigned to the offscreen surface overrides the primary / system
7469 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7470 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7471 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7472 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7473 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
7475 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
7476 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7477 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7478 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
7480 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7482 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7483 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7484 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7486 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7487 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7489 refcount
= IDirectDrawSurface_Release(surface
);
7490 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7492 /* The Windows 8 testbot keeps extra references to the primary and
7493 * backbuffer while in 8 bpp mode. */
7494 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
7495 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7497 refcount
= IDirectDrawSurface_Release(primary
);
7498 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7499 refcount
= IDirectDrawPalette_Release(palette2
);
7500 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7501 refcount
= IDirectDrawPalette_Release(palette
);
7502 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7503 refcount
= IDirectDraw2_Release(ddraw
);
7504 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7505 DestroyWindow(window
);
7508 static void test_palette_alpha(void)
7510 IDirectDrawSurface
*surface1
;
7511 IDirectDrawSurface2
*surface
;
7512 DDSURFACEDESC surface_desc
;
7513 IDirectDraw2
*ddraw
;
7514 IDirectDrawPalette
*palette
;
7518 PALETTEENTRY palette_entries
[256];
7523 BOOL attach_allowed
;
7528 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
7529 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
7530 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
7533 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7534 0, 0, 640, 480, 0, 0, 0, 0);
7535 ddraw
= create_ddraw();
7536 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7537 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7539 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7540 IDirectDraw2_Release(ddraw
);
7541 DestroyWindow(window
);
7544 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7545 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7547 memset(palette_entries
, 0, sizeof(palette_entries
));
7548 palette_entries
[1].peFlags
= 0x42;
7549 palette_entries
[2].peFlags
= 0xff;
7550 palette_entries
[3].peFlags
= 0x80;
7551 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
7552 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7554 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7555 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7556 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7557 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7558 palette_entries
[0].peFlags
);
7559 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7560 palette_entries
[1].peFlags
);
7561 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7562 palette_entries
[2].peFlags
);
7563 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7564 palette_entries
[3].peFlags
);
7566 IDirectDrawPalette_Release(palette
);
7568 memset(palette_entries
, 0, sizeof(palette_entries
));
7569 palette_entries
[1].peFlags
= 0x42;
7570 palette_entries
[1].peRed
= 0xff;
7571 palette_entries
[2].peFlags
= 0xff;
7572 palette_entries
[3].peFlags
= 0x80;
7573 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
7574 palette_entries
, &palette
, NULL
);
7575 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7577 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7578 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7579 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7580 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7581 palette_entries
[0].peFlags
);
7582 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7583 palette_entries
[1].peFlags
);
7584 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7585 palette_entries
[2].peFlags
);
7586 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7587 palette_entries
[3].peFlags
);
7589 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
7591 memset(&surface_desc
, 0, sizeof(surface_desc
));
7592 surface_desc
.dwSize
= sizeof(surface_desc
);
7593 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
7594 surface_desc
.dwWidth
= 128;
7595 surface_desc
.dwHeight
= 128;
7596 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
7597 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7598 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7599 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
7600 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
7601 IDirectDrawSurface_Release(surface1
);
7603 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
7604 if (test_data
[i
].attach_allowed
)
7605 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7607 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7615 hr
= IDirectDrawSurface2_GetDC(surface
, &dc
);
7616 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_CANTCREATEDC
) /* Win2k testbot */,
7617 "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7620 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
7621 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
7622 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
7623 rgbquad
.rgbRed
, test_data
[i
].name
);
7624 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
7625 rgbquad
.rgbGreen
, test_data
[i
].name
);
7626 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
7627 rgbquad
.rgbBlue
, test_data
[i
].name
);
7628 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
7629 rgbquad
.rgbReserved
, test_data
[i
].name
);
7630 hr
= IDirectDrawSurface2_ReleaseDC(surface
, dc
);
7631 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7634 IDirectDrawSurface2_Release(surface
);
7637 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
7638 memset(&surface_desc
, 0, sizeof(surface_desc
));
7639 surface_desc
.dwSize
= sizeof(surface_desc
);
7640 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7641 surface_desc
.dwWidth
= 128;
7642 surface_desc
.dwHeight
= 128;
7643 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7644 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7645 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7646 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7647 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7648 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7649 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7650 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7651 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7652 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
7653 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
7654 IDirectDrawSurface_Release(surface1
);
7656 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
7657 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
7658 IDirectDrawSurface2_Release(surface
);
7660 /* The Windows 8 testbot keeps extra references to the primary
7661 * while in 8 bpp mode. */
7662 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
7663 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7665 refcount
= IDirectDrawPalette_Release(palette
);
7666 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7667 refcount
= IDirectDraw2_Release(ddraw
);
7668 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7669 DestroyWindow(window
);
7672 static void test_lost_device(void)
7674 IDirectDrawSurface
*surface
;
7675 DDSURFACEDESC surface_desc
;
7676 HWND window1
, window2
;
7677 IDirectDraw2
*ddraw
;
7682 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7683 0, 0, 640, 480, 0, 0, 0, 0);
7684 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7685 0, 0, 640, 480, 0, 0, 0, 0);
7686 ddraw
= create_ddraw();
7687 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7688 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7689 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7691 memset(&surface_desc
, 0, sizeof(surface_desc
));
7692 surface_desc
.dwSize
= sizeof(surface_desc
);
7693 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
7694 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
7695 surface_desc
.dwBackBufferCount
= 1;
7696 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7697 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7699 hr
= IDirectDrawSurface_IsLost(surface
);
7700 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7701 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7702 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7704 ret
= SetForegroundWindow(GetDesktopWindow());
7705 ok(ret
, "Failed to set foreground window.\n");
7706 hr
= IDirectDrawSurface_IsLost(surface
);
7707 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7708 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7709 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7711 ret
= SetForegroundWindow(window1
);
7712 ok(ret
, "Failed to set foreground window.\n");
7713 hr
= IDirectDrawSurface_IsLost(surface
);
7714 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7715 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7716 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7718 hr
= restore_surfaces(ddraw
);
7719 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7720 hr
= IDirectDrawSurface_IsLost(surface
);
7721 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7722 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7723 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7725 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
7726 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7727 hr
= IDirectDrawSurface_IsLost(surface
);
7728 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7729 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7730 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7732 /* Trying to restore the primary will crash, probably because flippable
7733 * surfaces can't exist in DDSCL_NORMAL. */
7734 IDirectDrawSurface_Release(surface
);
7735 memset(&surface_desc
, 0, sizeof(surface_desc
));
7736 surface_desc
.dwSize
= sizeof(surface_desc
);
7737 surface_desc
.dwFlags
= DDSD_CAPS
;
7738 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7739 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7740 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7742 hr
= IDirectDrawSurface_IsLost(surface
);
7743 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7745 ret
= SetForegroundWindow(GetDesktopWindow());
7746 ok(ret
, "Failed to set foreground window.\n");
7747 hr
= IDirectDrawSurface_IsLost(surface
);
7748 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7750 ret
= SetForegroundWindow(window1
);
7751 ok(ret
, "Failed to set foreground window.\n");
7752 hr
= IDirectDrawSurface_IsLost(surface
);
7753 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7755 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7756 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7757 hr
= IDirectDrawSurface_IsLost(surface
);
7758 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7760 hr
= restore_surfaces(ddraw
);
7761 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7762 hr
= IDirectDrawSurface_IsLost(surface
);
7763 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7765 IDirectDrawSurface_Release(surface
);
7766 memset(&surface_desc
, 0, sizeof(surface_desc
));
7767 surface_desc
.dwSize
= sizeof(surface_desc
);
7768 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
7769 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
7770 U5(surface_desc
).dwBackBufferCount
= 1;
7771 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7772 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7774 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7775 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7776 hr
= IDirectDrawSurface_IsLost(surface
);
7777 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7778 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7779 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7781 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
7782 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7783 hr
= IDirectDrawSurface_IsLost(surface
);
7784 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7785 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7786 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7788 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
7789 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7790 hr
= IDirectDrawSurface_IsLost(surface
);
7791 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7792 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7793 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7795 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
7796 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7797 hr
= IDirectDrawSurface_IsLost(surface
);
7798 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7799 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7800 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7802 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
7803 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7804 hr
= IDirectDrawSurface_IsLost(surface
);
7805 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7806 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7807 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7809 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7810 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7811 hr
= IDirectDrawSurface_IsLost(surface
);
7812 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7813 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7814 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7816 IDirectDrawSurface_Release(surface
);
7817 refcount
= IDirectDraw2_Release(ddraw
);
7818 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7819 DestroyWindow(window2
);
7820 DestroyWindow(window1
);
7823 static void test_surface_desc_lock(void)
7825 IDirectDrawSurface
*surface
;
7826 DDSURFACEDESC surface_desc
;
7827 IDirectDraw2
*ddraw
;
7832 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7833 0, 0, 640, 480, 0, 0, 0, 0);
7834 ddraw
= create_ddraw();
7835 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7836 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7837 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7839 memset(&surface_desc
, 0, sizeof(surface_desc
));
7840 surface_desc
.dwSize
= sizeof(surface_desc
);
7841 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7842 surface_desc
.dwWidth
= 16;
7843 surface_desc
.dwHeight
= 16;
7844 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7845 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7846 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7848 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7849 surface_desc
.dwSize
= sizeof(surface_desc
);
7850 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7851 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7852 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7854 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7855 surface_desc
.dwSize
= sizeof(surface_desc
);
7856 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7857 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7858 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7859 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7860 surface_desc
.dwSize
= sizeof(surface_desc
);
7861 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7862 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7863 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7864 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
7865 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7867 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7868 surface_desc
.dwSize
= sizeof(surface_desc
);
7869 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7870 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7871 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7873 IDirectDrawSurface_Release(surface
);
7874 refcount
= IDirectDraw2_Release(ddraw
);
7875 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7876 DestroyWindow(window
);
7879 static void test_texturemapblend(void)
7884 static RECT rect
= {0, 0, 64, 128};
7885 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7887 IDirectDrawSurface
*surface
, *rt
;
7888 IDirect3DTexture2
*texture
;
7889 D3DTEXTUREHANDLE texture_handle
;
7891 IDirectDraw2
*ddraw
;
7892 IDirect3DDevice2
*device
;
7893 IDirect3DMaterial2
*material
;
7894 IDirect3DViewport2
*viewport
;
7898 static D3DTLVERTEX test1_quads
[] =
7900 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {0.0f
}},
7901 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {1.0f
}},
7902 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {0.0f
}},
7903 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {1.0f
}},
7904 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {0.0f
}},
7905 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {1.0f
}},
7906 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {0.0f
}},
7907 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {1.0f
}},
7911 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {0.0f
}},
7912 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {1.0f
}},
7913 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {0.0f
}},
7914 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {1.0f
}},
7915 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {0.0f
}},
7916 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {1.0f
}},
7917 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {0.0f
}},
7918 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {1.0f
}},
7921 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7922 0, 0, 640, 480, 0, 0, 0, 0);
7923 ddraw
= create_ddraw();
7924 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7925 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
7927 skip("Failed to create a 3D device, skipping test.\n");
7928 DestroyWindow(window
);
7929 IDirectDraw2_Release(ddraw
);
7933 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
7934 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
7936 material
= create_diffuse_material(device
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
7937 viewport
= create_viewport(device
, 0, 0, 640, 480);
7938 viewport_set_background(device
, viewport
, material
);
7939 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
7940 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
7942 /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel.
7944 * The vertex alpha is completely ignored in this case, so case 1 and 2 combined are not
7945 * a D3DTOP_MODULATE with texture alpha = 0xff in case 2 (no alpha in texture). */
7946 memset(&ddsd
, 0, sizeof(ddsd
));
7947 ddsd
.dwSize
= sizeof(ddsd
);
7948 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
7949 ddsd
.dwHeight
= 128;
7951 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
7952 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
7953 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
7954 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7955 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7956 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7957 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7958 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
7959 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
7960 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7962 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
7963 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
7964 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
7965 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
7966 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
7967 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7969 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7970 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
7972 memset(&fx
, 0, sizeof(fx
));
7973 fx
.dwSize
= sizeof(fx
);
7974 U5(fx
).dwFillColor
= 0xff0000ff;
7975 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7976 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7977 U5(fx
).dwFillColor
= 0x800000ff;
7978 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7979 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7981 /* Note that the ddraw1 version of this test runs tests 1-3 with D3DRENDERSTATE_COLORKEYENABLE
7982 * enabled, whereas this version only runs test 4 with color keying on. Because no color key
7983 * is set on the texture this should not result in different behavior. */
7984 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
7985 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7986 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
7987 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7988 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
7989 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7990 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
7991 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7992 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
7993 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7994 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
);
7995 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
7997 hr
= IDirect3DDevice2_BeginScene(device
);
7998 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7999 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8000 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8001 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8002 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8003 hr
= IDirect3DDevice2_EndScene(device
);
8004 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8006 color
= get_surface_color(rt
, 5, 5);
8007 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8008 color
= get_surface_color(rt
, 400, 5);
8009 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8010 color
= get_surface_color(rt
, 5, 245);
8011 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8012 color
= get_surface_color(rt
, 400, 245);
8013 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8015 IDirect3DTexture2_Release(texture
);
8016 ref
= IDirectDrawSurface_Release(surface
);
8017 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8019 /* Test alpha with texture that has no alpha channel - alpha should be taken from diffuse vertex color. */
8020 memset(&ddsd
, 0, sizeof(ddsd
));
8021 ddsd
.dwSize
= sizeof(ddsd
);
8022 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8023 ddsd
.dwHeight
= 128;
8025 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8026 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8027 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8028 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8029 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8030 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8031 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8033 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8034 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8036 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8037 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8038 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8039 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8040 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8041 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8043 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8044 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8046 U5(fx
).dwFillColor
= 0xff0000ff;
8047 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8048 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8049 U5(fx
).dwFillColor
= 0x800000ff;
8050 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8051 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8053 hr
= IDirect3DDevice2_BeginScene(device
);
8054 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8055 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8056 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8057 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8058 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8059 hr
= IDirect3DDevice2_EndScene(device
);
8060 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8062 color
= get_surface_color(rt
, 5, 5);
8063 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8064 color
= get_surface_color(rt
, 400, 5);
8065 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8066 color
= get_surface_color(rt
, 5, 245);
8067 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8068 color
= get_surface_color(rt
, 400, 245);
8069 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8071 IDirect3DTexture2_Release(texture
);
8072 ref
= IDirectDrawSurface_Release(surface
);
8073 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8075 /* Test RGB - should multiply color components from diffuse vertex color and texture. */
8076 memset(&ddsd
, 0, sizeof(ddsd
));
8077 ddsd
.dwSize
= sizeof(ddsd
);
8078 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8079 ddsd
.dwHeight
= 128;
8081 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8082 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8083 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
8084 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8085 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8086 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8087 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8088 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
8089 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8090 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8092 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8093 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8094 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8095 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8096 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8097 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8099 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8100 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8102 U5(fx
).dwFillColor
= 0x00ffffff;
8103 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8104 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8105 U5(fx
).dwFillColor
= 0x00ffff80;
8106 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8107 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8109 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
8110 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8112 hr
= IDirect3DDevice2_BeginScene(device
);
8113 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8114 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test2_quads
[0], 4, 0);
8115 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8116 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test2_quads
[4], 4, 0);
8117 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8118 hr
= IDirect3DDevice2_EndScene(device
);
8119 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8121 color
= get_surface_color(rt
, 5, 5);
8122 ok(compare_color(color
, 0x00ff0040, 2), "Got unexpected color 0x%08x.\n", color
);
8123 color
= get_surface_color(rt
, 400, 5);
8124 ok(compare_color(color
, 0x00ff0080, 2), "Got unexpected color 0x%08x.\n", color
);
8125 color
= get_surface_color(rt
, 5, 245);
8126 ok(compare_color(color
, 0x00800080, 2), "Got unexpected color 0x%08x.\n", color
);
8127 color
= get_surface_color(rt
, 400, 245);
8128 ok(compare_color(color
, 0x008000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8130 IDirect3DTexture2_Release(texture
);
8131 ref
= IDirectDrawSurface_Release(surface
);
8132 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8134 /* Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere). */
8135 memset(&ddsd
, 0, sizeof(ddsd
));
8136 ddsd
.dwSize
= sizeof(ddsd
);
8137 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8138 ddsd
.dwHeight
= 128;
8140 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8141 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8142 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8143 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 16;
8144 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
8145 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
8146 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
8148 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8149 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8151 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8152 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8153 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8154 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8155 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8156 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8158 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8159 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8161 U5(fx
).dwFillColor
= 0xf800;
8162 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8163 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8164 U5(fx
).dwFillColor
= 0x001f;
8165 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8166 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8168 ckey
.dwColorSpaceLowValue
= 0x001f;
8169 ckey
.dwColorSpaceHighValue
= 0x001f;
8170 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8171 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8173 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
8174 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8175 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
8176 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8178 hr
= IDirect3DDevice2_BeginScene(device
);
8179 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8180 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8181 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8182 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8183 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8184 hr
= IDirect3DDevice2_EndScene(device
);
8185 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8187 color
= get_surface_color(rt
, 5, 5);
8188 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
8189 color
= get_surface_color(rt
, 400, 5);
8190 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
8191 color
= get_surface_color(rt
, 5, 245);
8192 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
8193 color
= get_surface_color(rt
, 400, 245);
8194 ok(compare_color(color
, 0x00800000, 2), "Got unexpected color 0x%08x.\n", color
);
8196 IDirect3DTexture2_Release(texture
);
8197 ref
= IDirectDrawSurface_Release(surface
);
8198 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8200 destroy_viewport(device
, viewport
);
8201 ref
= IDirect3DMaterial2_Release(material
);
8202 ok(ref
== 0, "Material not properly released, refcount %u.\n", ref
);
8203 IDirectDrawSurface_Release(rt
);
8204 IDirect3DDevice2_Release(device
);
8205 ref
= IDirectDraw2_Release(ddraw
);
8206 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
8207 DestroyWindow(window
);
8210 static void test_viewport_clear_rect(void)
8213 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8214 static D3DRECT clear_rect2
= {{90}, {90}, {110}, {110}};
8215 IDirectDrawSurface
*rt
;
8217 IDirectDraw2
*ddraw
;
8218 IDirect3DDevice2
*device
;
8219 IDirect3DMaterial2
*red
, *green
;
8220 IDirect3DViewport2
*viewport
, *viewport2
;
8224 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8225 0, 0, 640, 480, 0, 0, 0, 0);
8226 ddraw
= create_ddraw();
8227 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8228 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8230 skip("Failed to create a 3D device, skipping test.\n");
8231 DestroyWindow(window
);
8232 IDirectDraw2_Release(ddraw
);
8236 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8237 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8239 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
8240 viewport
= create_viewport(device
, 0, 0, 640, 480);
8241 viewport_set_background(device
, viewport
, red
);
8242 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8243 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8245 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
8246 viewport2
= create_viewport(device
, 100, 100, 20, 20);
8247 viewport_set_background(device
, viewport2
, green
);
8248 hr
= IDirect3DViewport2_Clear(viewport2
, 1, &clear_rect2
, D3DCLEAR_TARGET
);
8249 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8251 color
= get_surface_color(rt
, 85, 85); /* Outside both. */
8252 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8253 color
= get_surface_color(rt
, 95, 95); /* Outside vp, inside rect. */
8254 /* AMD GPUs ignore the viewport dimensions and only care about the rectangle. */
8255 ok(compare_color(color
, 0x00ff0000, 1) || broken(compare_color(color
, 0x0000ff00, 1)),
8256 "Got unexpected color 0x%08x.\n", color
);
8257 color
= get_surface_color(rt
, 105, 105); /* Inside both. */
8258 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
8259 color
= get_surface_color(rt
, 115, 115); /* Inside vp, outside rect. */
8260 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8261 color
= get_surface_color(rt
, 125, 125); /* Outside both. */
8262 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8264 destroy_viewport(device
, viewport2
);
8265 destroy_material(green
);
8266 destroy_viewport(device
, viewport
);
8267 destroy_material(red
);
8268 IDirectDrawSurface_Release(rt
);
8269 IDirect3DDevice2_Release(device
);
8270 ref
= IDirectDraw2_Release(ddraw
);
8271 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
8272 DestroyWindow(window
);
8275 static void test_color_fill(void)
8278 IDirect3DDevice2
*device
;
8279 IDirectDraw2
*ddraw
;
8280 IDirectDrawSurface
*surface
, *surface2
;
8281 DDSURFACEDESC surface_desc
;
8286 RECT rect
= {5, 5, 7, 7};
8288 DWORD num_fourcc_codes
, *fourcc_codes
;
8290 BOOL support_uyvy
= FALSE
, support_yuy2
= FALSE
;
8294 HRESULT colorfill_hr
, depthfill_hr
;
8299 DDPIXELFORMAT format
;
8304 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8305 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8307 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8308 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8312 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
8313 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8315 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8316 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8320 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
8321 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
8323 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8324 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8328 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
8329 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
8331 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8332 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8336 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
,
8337 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
8338 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
8341 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
8342 * different afterwards. DX9+ GPUs set one of the two luminance values
8343 * in each block, but AMD and Nvidia GPUs disagree on which luminance
8344 * value they set. r200 (dx8) just sets the entire block to the clear
8346 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8347 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
8349 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8350 {0}, {0}, {0}, {0}, {0}
8354 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8355 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
8357 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8358 {0}, {0}, {0}, {0}, {0}
8362 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
8363 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
8365 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8366 {0}, {0}, {0}, {0}, {0}
8370 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
8371 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
8373 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8374 {0}, {0}, {0}, {0}, {0}
8378 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
8379 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
8381 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8382 {0}, {0}, {0}, {0}, {0}
8386 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
8387 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
8389 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8390 {0}, {0}, {0}, {0}, {0}
8394 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
8395 * surface works, presumably because it is handled by the runtime instead of
8397 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8398 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
8400 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
8401 {8}, {0}, {0}, {0}, {0}
8405 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
8406 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
8408 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
8409 {8}, {0}, {0}, {0}, {0}
8421 {SRCCOPY
, "SRCCOPY", DD_OK
},
8422 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
8423 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
8424 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
8425 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
8426 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
8427 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
8428 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
8429 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
8430 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
8431 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
8432 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
8433 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
8434 {BLACKNESS
, "BLACKNESS", DD_OK
},
8435 {WHITENESS
, "WHITENESS", DD_OK
},
8436 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
8439 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8440 0, 0, 640, 480, 0, 0, 0, 0);
8441 ddraw
= create_ddraw();
8442 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8443 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8445 skip("Failed to create a 3D device, skipping test.\n");
8446 DestroyWindow(window
);
8447 IDirectDraw2_Release(ddraw
);
8451 hr
= IDirectDraw2_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
8452 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
8453 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
8454 num_fourcc_codes
* sizeof(*fourcc_codes
));
8457 hr
= IDirectDraw2_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
8458 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
8459 for (i
= 0; i
< num_fourcc_codes
; i
++)
8461 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
8462 support_yuy2
= TRUE
;
8463 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
8464 support_uyvy
= TRUE
;
8466 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
8468 memset(&hal_caps
, 0, sizeof(hal_caps
));
8469 hal_caps
.dwSize
= sizeof(hal_caps
);
8470 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
8471 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
8473 if ((!support_yuy2
&& !support_uyvy
) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
8474 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
8476 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
8478 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
8479 memset(&fx
, 0, sizeof(fx
));
8480 fx
.dwSize
= sizeof(fx
);
8481 U5(fx
).dwFillColor
= 0xdeadbeef;
8483 memset(&surface_desc
, 0, sizeof(surface_desc
));
8484 surface_desc
.dwSize
= sizeof(surface_desc
);
8485 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8486 surface_desc
.dwWidth
= 64;
8487 surface_desc
.dwHeight
= 64;
8488 surface_desc
.ddpfPixelFormat
= tests
[i
].format
;
8489 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
8491 if (tests
[i
].caps
& DDSCAPS_TEXTURE
)
8493 struct format_support_check check
= {&tests
[i
].format
, FALSE
};
8494 hr
= IDirect3DDevice2_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
8495 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
8496 if (!check
.supported
)
8500 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !support_yuy2
)
8502 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !support_uyvy
)
8504 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
8507 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
8509 surface_desc
.dwFlags
&= ~DDSD_PIXELFORMAT
;
8510 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
8511 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
8514 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8515 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8517 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8518 todo_wine_if (tests
[i
].format
.dwFourCC
)
8519 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8520 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8522 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8523 todo_wine_if (tests
[i
].format
.dwFourCC
)
8524 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8525 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8527 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8529 memset(&surface_desc
, 0, sizeof(surface_desc
));
8530 surface_desc
.dwSize
= sizeof(surface_desc
);
8531 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8532 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8533 color
= surface_desc
.lpSurface
;
8534 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
8535 *color
, tests
[i
].result
, tests
[i
].name
);
8536 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8537 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8540 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8541 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8542 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
8543 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8544 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8545 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
8547 U5(fx
).dwFillColor
= 0xdeadbeef;
8548 fx
.dwROP
= BLACKNESS
;
8549 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8550 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
8551 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
8552 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8553 U5(fx
).dwFillColor
, tests
[i
].name
);
8555 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8557 memset(&surface_desc
, 0, sizeof(surface_desc
));
8558 surface_desc
.dwSize
= sizeof(surface_desc
);
8559 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8560 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8561 color
= surface_desc
.lpSurface
;
8562 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
8563 *color
, tests
[i
].name
);
8564 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8565 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8568 fx
.dwROP
= WHITENESS
;
8569 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8570 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
8571 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
8572 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8573 U5(fx
).dwFillColor
, tests
[i
].name
);
8575 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8577 memset(&surface_desc
, 0, sizeof(surface_desc
));
8578 surface_desc
.dwSize
= sizeof(surface_desc
);
8579 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8580 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8581 color
= surface_desc
.lpSurface
;
8582 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
8583 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
8584 *color
, tests
[i
].name
);
8585 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8586 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8589 IDirectDrawSurface_Release(surface
);
8592 memset(&fx
, 0, sizeof(fx
));
8593 fx
.dwSize
= sizeof(fx
);
8594 U5(fx
).dwFillColor
= 0xdeadbeef;
8595 fx
.dwROP
= WHITENESS
;
8597 memset(&surface_desc
, 0, sizeof(surface_desc
));
8598 surface_desc
.dwSize
= sizeof(surface_desc
);
8599 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8600 surface_desc
.dwWidth
= 64;
8601 surface_desc
.dwHeight
= 64;
8602 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
8603 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8604 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8605 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8606 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8607 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8608 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
8609 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8610 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8611 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
8612 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8615 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
8616 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8617 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
8618 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8620 /* Unused source rectangle. */
8621 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8622 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8623 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8624 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8626 /* Unused source surface. */
8627 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8628 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8629 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8630 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8631 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8632 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8633 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8634 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8636 /* Inverted destination or source rectangle. */
8637 SetRect(&rect
, 5, 7, 7, 5);
8638 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8639 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8640 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8641 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8642 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8643 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8644 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8645 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8646 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8647 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8649 /* Negative rectangle. */
8650 SetRect(&rect
, -1, -1, 5, 5);
8651 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8652 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8653 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8654 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8655 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8656 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8657 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8658 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8659 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8660 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8662 /* Out of bounds rectangle. */
8663 SetRect(&rect
, 0, 0, 65, 65);
8664 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8665 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8666 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8667 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8669 /* Combine multiple flags. */
8670 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8671 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8672 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8673 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8674 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8675 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8677 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
8679 fx
.dwROP
= rops
[i
].rop
;
8680 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8681 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
8684 IDirectDrawSurface_Release(surface2
);
8685 IDirectDrawSurface_Release(surface
);
8687 memset(&surface_desc
, 0, sizeof(surface_desc
));
8688 surface_desc
.dwSize
= sizeof(surface_desc
);
8689 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_ZBUFFERBITDEPTH
;
8690 surface_desc
.dwWidth
= 64;
8691 surface_desc
.dwHeight
= 64;
8692 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
8693 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
8694 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8695 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8696 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
8697 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8700 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
8701 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8703 /* Unused source rectangle. */
8704 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8705 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8707 /* Unused source surface. */
8708 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8709 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8710 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8711 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8713 /* Inverted destination or source rectangle. */
8714 SetRect(&rect
, 5, 7, 7, 5);
8715 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8716 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8717 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8718 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8719 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8720 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8721 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8722 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8724 /* Negative rectangle. */
8725 SetRect(&rect
, -1, -1, 5, 5);
8726 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8727 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8728 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8729 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8730 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8731 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8732 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8733 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8735 /* Out of bounds rectangle. */
8736 SetRect(&rect
, 0, 0, 65, 65);
8737 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8738 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8740 /* Combine multiple flags. */
8741 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8742 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8744 IDirectDrawSurface_Release(surface2
);
8745 IDirectDrawSurface_Release(surface
);
8748 IDirect3DDevice2_Release(device
);
8749 refcount
= IDirectDraw2_Release(ddraw
);
8750 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
8751 DestroyWindow(window
);
8754 static BOOL
ddraw_is_nvidia(IDirectDraw2
*ddraw
)
8756 IDirectDraw4
*ddraw4
;
8757 DDDEVICEIDENTIFIER identifier
;
8760 if (!strcmp(winetest_platform
, "wine"))
8763 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
8764 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
8765 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, &identifier
, 0);
8766 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
8767 IDirectDraw4_Release(ddraw4
);
8768 return identifier
.dwVendorId
== 0x10de;
8771 static void test_colorkey_precision(void)
8773 static D3DLVERTEX quad
[] =
8775 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {0.0f
}, {0.0f
}},
8776 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {0.0f
}, {1.0f
}},
8777 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {1.0f
}, {0.0f
}},
8778 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {1.0f
}, {1.0f
}},
8780 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8781 IDirect3DDevice2
*device
;
8782 IDirectDraw2
*ddraw
;
8783 IDirectDrawSurface
*rt
;
8784 IDirect3DViewport2
*viewport
;
8787 IDirectDrawSurface
*src
, *dst
, *texture
;
8788 D3DTEXTUREHANDLE handle
;
8789 IDirect3DTexture2
*d3d_texture
;
8790 IDirect3DMaterial2
*green
;
8791 DDSURFACEDESC surface_desc
, lock_desc
;
8797 DWORD data
[4] = {0}, color_mask
;
8798 BOOL is_nvidia
, is_warp
;
8801 unsigned int max
, shift
, bpp
, clear
;
8809 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE
,
8811 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8812 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
8817 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE
,
8819 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8820 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
8825 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE
,
8827 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8828 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
8833 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE
,
8835 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8836 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
8841 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8842 0, 0, 640, 480, 0, 0, 0, 0);
8843 ddraw
= create_ddraw();
8844 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8845 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8847 skip("Failed to create a 3D device, skipping test.\n");
8848 DestroyWindow(window
);
8849 IDirectDraw2_Release(ddraw
);
8852 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8853 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8855 is_nvidia
= ddraw_is_nvidia(ddraw
);
8856 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
8857 * (color key doesn't match although the values are equal), and a false
8858 * positive when the color key is 0 and the texture contains the value 1.
8859 * I don't want to mark this broken unconditionally since this would
8860 * essentially disable the test on Windows. Also on random occasions
8861 * 254 == 255 and 255 != 255.*/
8862 is_warp
= ddraw_is_warp(ddraw
);
8864 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
8865 viewport
= create_viewport(device
, 0, 0, 640, 480);
8866 viewport_set_background(device
, viewport
, green
);
8867 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
8868 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
8870 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8871 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
8872 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
8873 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
8874 /* There's no way to ignore the texture color in d3d2, so multiply the texture color
8875 * with a black vertex color. */
8876 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATEALPHA
);
8877 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8879 memset(&fx
, 0, sizeof(fx
));
8880 fx
.dwSize
= sizeof(fx
);
8881 memset(&lock_desc
, 0, sizeof(lock_desc
));
8882 lock_desc
.dwSize
= sizeof(lock_desc
);
8884 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
8886 if (is_nvidia
&& tests
[t
].skip_nv
)
8888 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests
[t
].name
);
8892 memset(&surface_desc
, 0, sizeof(surface_desc
));
8893 surface_desc
.dwSize
= sizeof(surface_desc
);
8894 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8895 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8896 surface_desc
.dwWidth
= 4;
8897 surface_desc
.dwHeight
= 1;
8898 surface_desc
.ddpfPixelFormat
= tests
[t
].fmt
;
8899 /* Windows XP (at least with the r200 driver, other drivers untested) produces
8900 * garbage when doing color keyed texture->texture blits. */
8901 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
8902 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8903 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
8904 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8906 fx
.dwFillColor
= tests
[t
].clear
;
8907 /* On the w8 testbot (WARP driver) the blit result has different values in the
8909 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
8910 | U3(tests
[t
].fmt
).dwGBitMask
8911 | U4(tests
[t
].fmt
).dwBBitMask
;
8913 for (c
= 0; c
<= tests
[t
].max
; ++c
)
8915 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
8916 * texture after it has been set once... */
8917 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
8918 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8919 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
8920 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
8921 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
8922 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8924 hr
= IDirectDrawSurface4_QueryInterface(texture
, &IID_IDirect3DTexture2
, (void **)&d3d_texture
);
8925 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8926 hr
= IDirect3DTexture2_GetHandle(d3d_texture
, device
, &handle
);
8927 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8928 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, handle
);
8929 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
8930 IDirect3DTexture2_Release(d3d_texture
);
8932 hr
= IDirectDrawSurface_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8933 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
8935 hr
= IDirectDrawSurface_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
8936 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8937 switch (tests
[t
].bpp
)
8940 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
8941 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
8942 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
8943 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
8947 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
8948 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
8949 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
8950 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
8953 hr
= IDirectDrawSurface_Unlock(src
, 0);
8954 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8955 hr
= IDirectDrawSurface_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
8956 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
8958 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
8959 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
8960 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
8961 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8963 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
8964 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
8966 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
8967 hr
= IDirectDrawSurface_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
8968 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8969 switch (tests
[t
].bpp
)
8972 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
8973 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
8974 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
8975 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
8979 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
8980 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
8981 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
8982 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
8985 hr
= IDirectDrawSurface_Unlock(dst
, 0);
8986 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8990 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
8991 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
8993 if (data
[3] == tests
[t
].clear
)
8995 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
8996 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
8997 * even when a different surface is used. The blit itself doesn't draw anything,
8998 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
8999 * never be masked out by the key.
9001 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
9002 * test is disabled entirely.
9004 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
9005 * terrible on WARP. */
9006 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
9007 IDirectDrawSurface_Release(texture
);
9008 IDirectDrawSurface_Release(src
);
9009 IDirectDrawSurface_Release(dst
);
9014 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9015 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
9017 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9018 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
9020 if (c
== tests
[t
].max
)
9021 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9022 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
9024 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9025 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
9027 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
9028 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9030 hr
= IDirect3DDevice2_BeginScene(device
);
9031 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9032 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
9033 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9034 hr
= IDirect3DDevice2_EndScene(device
);
9035 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9037 color
= get_surface_color(rt
, 80, 240);
9039 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9040 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9041 color
, tests
[t
].name
, c
);
9043 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
9044 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9045 color
, tests
[t
].name
, c
);
9047 color
= get_surface_color(rt
, 240, 240);
9048 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9049 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9050 color
, tests
[t
].name
, c
);
9052 color
= get_surface_color(rt
, 400, 240);
9053 if (c
== tests
[t
].max
)
9054 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9055 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9056 color
, tests
[t
].name
, c
);
9058 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
9059 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9060 color
, tests
[t
].name
, c
);
9062 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
9063 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
9064 IDirectDrawSurface_Release(texture
);
9066 IDirectDrawSurface_Release(src
);
9067 IDirectDrawSurface_Release(dst
);
9071 destroy_viewport(device
, viewport
);
9072 destroy_material(green
);
9073 IDirectDrawSurface_Release(rt
);
9074 IDirect3DDevice2_Release(device
);
9075 refcount
= IDirectDraw2_Release(ddraw
);
9076 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
9077 DestroyWindow(window
);
9080 static void test_range_colorkey(void)
9082 IDirectDraw2
*ddraw
;
9085 IDirectDrawSurface
*surface
;
9086 DDSURFACEDESC surface_desc
;
9090 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9091 0, 0, 640, 480, 0, 0, 0, 0);
9092 ddraw
= create_ddraw();
9093 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9094 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9095 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9097 memset(&surface_desc
, 0, sizeof(surface_desc
));
9098 surface_desc
.dwSize
= sizeof(surface_desc
);
9099 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
9100 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9101 surface_desc
.dwWidth
= 1;
9102 surface_desc
.dwHeight
= 1;
9103 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9104 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
9105 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9106 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9107 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9108 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
9110 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
9111 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9112 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
9113 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9114 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9116 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
9117 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9118 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9119 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9121 /* Same for DDSCAPS_OFFSCREENPLAIN. */
9122 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9123 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9124 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
9125 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9126 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9128 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
9129 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9130 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9131 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9133 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9134 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9135 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9136 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9138 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
9139 ckey
.dwColorSpaceLowValue
= 0x00000000;
9140 ckey
.dwColorSpaceHighValue
= 0x00000001;
9141 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9142 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9144 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9145 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9146 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9147 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9149 ckey
.dwColorSpaceLowValue
= 0x00000001;
9150 ckey
.dwColorSpaceHighValue
= 0x00000000;
9151 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9152 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9154 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9155 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9156 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9157 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9159 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
9160 ckey
.dwColorSpaceLowValue
= 0x00000000;
9161 ckey
.dwColorSpaceHighValue
= 0x00000000;
9162 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9163 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9165 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
9166 ckey
.dwColorSpaceLowValue
= 0x00000001;
9167 ckey
.dwColorSpaceHighValue
= 0x00000000;
9168 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9169 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9170 ckey
.dwColorSpaceLowValue
= 0x00000000;
9171 ckey
.dwColorSpaceHighValue
= 0x00000001;
9172 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9173 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9174 /* Range destination keys don't work either. */
9175 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
9176 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9178 /* Just to show it's not because of A, R, and G having equal values. */
9179 ckey
.dwColorSpaceLowValue
= 0x00000000;
9180 ckey
.dwColorSpaceHighValue
= 0x01010101;
9181 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9182 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9184 /* None of these operations modified the key. */
9185 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9186 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9187 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9188 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9190 IDirectDrawSurface_Release(surface
),
9191 refcount
= IDirectDraw2_Release(ddraw
);
9192 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
9193 DestroyWindow(window
);
9196 static void test_shademode(void)
9198 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9199 IDirect3DMaterial2
*background
;
9200 IDirect3DViewport2
*viewport
;
9201 IDirect3DDevice2
*device
;
9202 IDirectDrawSurface
*rt
;
9203 DWORD color0
, color1
;
9204 IDirectDraw2
*ddraw
;
9210 static D3DLVERTEX quad_strip
[] =
9212 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
9213 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9214 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9215 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
9219 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
9220 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9221 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9223 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9224 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9225 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
9231 DWORD color0
, color1
;
9235 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
9236 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
9237 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
9238 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
9239 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
9240 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
9243 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9244 0, 0, 640, 480, 0, 0, 0, 0);
9245 ddraw
= create_ddraw();
9246 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9247 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9249 skip("Failed to create a 3D device, skipping test.\n");
9250 IDirectDraw2_Release(ddraw
);
9251 DestroyWindow(window
);
9255 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9256 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9258 background
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
9259 viewport
= create_viewport(device
, 0, 0, 640, 480);
9260 viewport_set_background(device
, viewport
, background
);
9261 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
9262 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
9264 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
9265 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
9267 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
9268 * the color fixups we have to do for FLAT shading will be dependent on that. */
9270 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
9272 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
9273 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
9275 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
9276 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
9278 hr
= IDirect3DDevice2_BeginScene(device
);
9279 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9280 quad
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? quad_strip
: quad_list
;
9281 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
9282 hr
= IDirect3DDevice2_DrawPrimitive(device
, tests
[i
].primtype
, D3DVT_LVERTEX
, quad
, count
, 0);
9283 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9284 hr
= IDirect3DDevice2_EndScene(device
);
9285 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9287 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
9288 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
9290 /* For D3DSHADE_FLAT it should take the color of the first vertex of
9291 * each triangle. This requires EXT_provoking_vertex or similar
9292 * functionality being available. */
9293 /* PHONG should be the same as GOURAUD, since no hardware implements
9295 ok(compare_color(color0
, tests
[i
].color0
, 1), "Test %u shading has color0 %08x, expected %08x.\n",
9296 i
, color0
, tests
[i
].color0
);
9297 ok(compare_color(color1
, tests
[i
].color1
, 1), "Test %u shading has color1 %08x, expected %08x.\n",
9298 i
, color1
, tests
[i
].color1
);
9301 destroy_viewport(device
, viewport
);
9302 destroy_material(background
);
9303 IDirectDrawSurface_Release(rt
);
9304 refcount
= IDirect3DDevice2_Release(device
);
9305 ok(!refcount
, "Device has %u references left.\n", refcount
);
9306 IDirectDraw_Release(ddraw
);
9307 DestroyWindow(window
);
9310 static void test_lockrect_invalid(void)
9313 IDirectDraw2
*ddraw
;
9314 IDirectDrawSurface
*surface1
;
9315 IDirectDrawSurface2
*surface
;
9318 DDSURFACEDESC surface_desc
;
9320 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
9321 static RECT valid
[] =
9329 static RECT invalid
[] =
9331 {68, 60, 60, 68}, /* left > right */
9332 {60, 68, 68, 60}, /* top > bottom */
9333 {-8, 60, 0, 68}, /* left < surface */
9334 {60, -8, 68, 0}, /* top < surface */
9335 {-16, 60, -8, 68}, /* right < surface */
9336 {60, -16, 68, -8}, /* bottom < surface */
9337 {60, 60, 136, 68}, /* right > surface */
9338 {60, 60, 68, 136}, /* bottom > surface */
9339 {136, 60, 144, 68}, /* left > surface */
9340 {60, 136, 68, 144}, /* top > surface */
9350 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, "sysmem offscreenplain", DDERR_INVALIDPARAMS
},
9351 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, "vidmem offscreenplain", DDERR_INVALIDPARAMS
},
9352 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, "sysmem texture", DDERR_INVALIDPARAMS
},
9353 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, "vidmem texture", DDERR_INVALIDPARAMS
},
9356 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9357 0, 0, 640, 480, 0, 0, 0, 0);
9358 ddraw
= create_ddraw();
9359 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9360 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9361 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9363 memset(&hal_caps
, 0, sizeof(hal_caps
));
9364 hal_caps
.dwSize
= sizeof(hal_caps
);
9365 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
9366 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9367 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
9369 skip("Required surface types not supported, skipping test.\n");
9373 for (r
= 0; r
< sizeof(resources
) / sizeof(*resources
); ++r
)
9375 memset(&surface_desc
, 0, sizeof(surface_desc
));
9376 surface_desc
.dwSize
= sizeof(surface_desc
);
9377 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9378 surface_desc
.ddsCaps
.dwCaps
= resources
[r
].caps
;
9379 surface_desc
.dwWidth
= 128;
9380 surface_desc
.dwHeight
= 128;
9381 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
9382 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9383 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
9384 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xff0000;
9385 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x00ff00;
9386 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x0000ff;
9388 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
9389 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9390 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
9391 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface2 interface, hr %#x.\n", hr
);
9392 IDirectDrawSurface_Release(surface1
);
9394 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, NULL
, DDLOCK_WAIT
, NULL
);
9395 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
9397 for (i
= 0; i
< sizeof(valid
) / sizeof(*valid
); ++i
)
9399 RECT
*rect
= &valid
[i
];
9401 memset(&surface_desc
, 0, sizeof(surface_desc
));
9402 surface_desc
.dwSize
= sizeof(surface_desc
);
9404 hr
= IDirectDrawSurface2_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9405 ok(SUCCEEDED(hr
), "Lock failed (%#x) for rect %s, type %s.\n",
9406 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
9408 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9409 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9412 for (i
= 0; i
< sizeof(invalid
) / sizeof(*invalid
); ++i
)
9414 RECT
*rect
= &invalid
[i
];
9416 memset(&surface_desc
, 1, sizeof(surface_desc
));
9417 surface_desc
.dwSize
= sizeof(surface_desc
);
9419 hr
= IDirectDrawSurface2_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9420 ok(hr
== resources
[r
].hr
, "Lock returned %#x for rect %s, type %s.\n",
9421 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
9424 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9425 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9428 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
9431 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9432 ok(SUCCEEDED(hr
), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
9433 hr
, resources
[r
].name
);
9434 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9435 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned %#x, type %s.\n",
9436 hr
, resources
[r
].name
);
9437 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9438 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9440 hr
= IDirectDrawSurface2_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
9441 ok(SUCCEEDED(hr
), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid
[0]), hr
);
9442 hr
= IDirectDrawSurface2_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
9443 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = %s) failed (%#x).\n",
9444 wine_dbgstr_rect(&valid
[0]), hr
);
9446 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
9447 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
9449 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9450 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9452 IDirectDrawSurface2_Release(surface
);
9456 IDirectDraw2_Release(ddraw
);
9457 DestroyWindow(window
);
9460 static void test_yv12_overlay(void)
9462 IDirectDrawSurface
*src_surface
, *dst_surface
;
9463 RECT rect
= {13, 17, 14, 18};
9464 unsigned int offset
, y
;
9465 unsigned char *base
;
9466 IDirectDraw2
*ddraw
;
9471 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9472 0, 0, 640, 480, 0, 0, 0, 0);
9473 ddraw
= create_ddraw();
9474 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9475 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9476 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9478 if (!(src_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
9480 skip("Failed to create a YV12 overlay, skipping test.\n");
9484 memset(&desc
, 0, sizeof(desc
));
9485 desc
.dwSize
= sizeof(desc
);
9486 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
9487 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9489 ok(desc
.dwFlags
== (DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_PITCH
),
9490 "Got unexpected flags %#x.\n", desc
.dwFlags
);
9491 ok(desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_HWCODEC
)
9492 || desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
9493 "Got unexpected caps %#x.\n", desc
.ddsCaps
.dwCaps
);
9494 ok(desc
.dwWidth
== 256, "Got unexpected width %u.\n", desc
.dwWidth
);
9495 ok(desc
.dwHeight
== 256, "Got unexpected height %u.\n", desc
.dwHeight
);
9496 /* The overlay pitch seems to have 256 byte alignment. */
9497 ok(!(U1(desc
).lPitch
& 0xff), "Got unexpected pitch %u.\n", U1(desc
).lPitch
);
9499 /* Fill the surface with some data for the blit test. */
9500 base
= desc
.lpSurface
;
9502 for (y
= 0; y
< desc
.dwHeight
; ++y
)
9504 memset(base
+ U1(desc
).lPitch
* y
, 0x10, desc
.dwWidth
);
9507 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 4; ++y
)
9509 memset(base
+ U1(desc
).lPitch
* y
, 0x20, desc
.dwWidth
);
9512 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 2; ++y
)
9514 memset(base
+ U1(desc
).lPitch
* y
, 0x30, desc
.dwWidth
);
9517 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
9518 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9520 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
9521 * other block-based formats like DXT the entire Y channel is stored in
9522 * one big chunk of memory, followed by the chroma channels. So partial
9523 * locks do not really make sense. Show that they are allowed nevertheless
9524 * and the offset points into the luminance data. */
9525 hr
= IDirectDrawSurface_Lock(src_surface
, &rect
, &desc
, DDLOCK_WAIT
, NULL
);
9526 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9527 offset
= ((const unsigned char *)desc
.lpSurface
- base
);
9528 ok(offset
== rect
.top
* U1(desc
).lPitch
+ rect
.left
, "Got unexpected offset %u, expected %u.\n",
9529 offset
, rect
.top
* U1(desc
).lPitch
+ rect
.left
);
9530 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
9531 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9533 if (!(dst_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
9535 /* Windows XP with a Radeon X1600 GPU refuses to create a second
9536 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
9537 skip("Failed to create a second YV12 surface, skipping blit test.\n");
9538 IDirectDrawSurface_Release(src_surface
);
9542 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, NULL
, DDBLT_WAIT
, NULL
);
9543 /* VMware rejects YV12 blits. This behavior has not been seen on real
9544 * hardware yet, so mark it broken. */
9545 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
), "Failed to blit, hr %#x.\n", hr
);
9549 memset(&desc
, 0, sizeof(desc
));
9550 desc
.dwSize
= sizeof(desc
);
9551 hr
= IDirectDrawSurface_Lock(dst_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
9552 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9554 base
= desc
.lpSurface
;
9555 ok(base
[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base
[0]);
9556 base
+= desc
.dwHeight
* U1(desc
).lPitch
;
9557 todo_wine
ok(base
[0] == 0x20, "Got unexpected V data 0x%02x.\n", base
[0]);
9558 base
+= desc
.dwHeight
/ 4 * U1(desc
).lPitch
;
9559 todo_wine
ok(base
[0] == 0x30, "Got unexpected U data 0x%02x.\n", base
[0]);
9561 hr
= IDirectDrawSurface_Unlock(dst_surface
, NULL
);
9562 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9565 IDirectDrawSurface_Release(dst_surface
);
9566 IDirectDrawSurface_Release(src_surface
);
9568 IDirectDraw2_Release(ddraw
);
9569 DestroyWindow(window
);
9572 static BOOL
dwm_enabled(void)
9576 if (!strcmp(winetest_platform
, "wine"))
9578 if (!pDwmIsCompositionEnabled
)
9580 if (FAILED(pDwmIsCompositionEnabled(&ret
)))
9585 static void test_offscreen_overlay(void)
9587 IDirectDrawSurface
*overlay
, *offscreen
, *primary
;
9588 DDSURFACEDESC surface_desc
;
9589 IDirectDraw2
*ddraw
;
9594 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9595 0, 0, 640, 480, 0, 0, 0, 0);
9596 ddraw
= create_ddraw();
9597 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9598 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9599 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9601 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
9603 skip("Failed to create a UYVY overlay, skipping test.\n");
9607 memset(&surface_desc
, 0, sizeof(surface_desc
));
9608 surface_desc
.dwSize
= sizeof(surface_desc
);
9609 surface_desc
.dwFlags
= DDSD_CAPS
;
9610 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
9611 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
9612 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9614 /* On Windows 7, and probably Vista, UpdateOverlay() will return
9615 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
9616 * surface prevents this by disabling the dwm. */
9617 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
9618 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
9619 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
9620 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
9622 /* Try to overlay a NULL surface. */
9623 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_SHOW
, NULL
);
9624 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9625 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_HIDE
, NULL
);
9626 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9628 /* Try to overlay an offscreen surface. */
9629 memset(&surface_desc
, 0, sizeof(surface_desc
));
9630 surface_desc
.dwSize
= sizeof(surface_desc
);
9631 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
9632 surface_desc
.dwWidth
= 64;
9633 surface_desc
.dwHeight
= 64;
9634 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9635 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
9636 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9637 surface_desc
.ddpfPixelFormat
.dwFourCC
= 0;
9638 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
9639 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
9640 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
9641 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
9642 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
9643 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9645 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, offscreen
, NULL
, DDOVER_SHOW
, NULL
);
9646 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_OUTOFCAPS
&& dwm_enabled()),
9647 "Failed to update overlay, hr %#x.\n", hr
);
9649 /* Try to overlay the primary with a non-overlay surface. */
9650 hr
= IDirectDrawSurface_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
9651 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
9652 hr
= IDirectDrawSurface_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
9653 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
9655 IDirectDrawSurface_Release(offscreen
);
9656 IDirectDrawSurface_Release(primary
);
9657 IDirectDrawSurface_Release(overlay
);
9659 IDirectDraw2_Release(ddraw
);
9660 DestroyWindow(window
);
9663 static void test_overlay_rect(void)
9665 IDirectDrawSurface
*overlay
, *primary
= NULL
;
9666 DDSURFACEDESC surface_desc
;
9667 RECT rect
= {0, 0, 64, 64};
9668 IDirectDraw2
*ddraw
;
9674 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9675 0, 0, 640, 480, 0, 0, 0, 0);
9676 ddraw
= create_ddraw();
9677 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9678 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9679 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9681 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
9683 skip("Failed to create a UYVY overlay, skipping test.\n");
9687 memset(&surface_desc
, 0, sizeof(surface_desc
));
9688 surface_desc
.dwSize
= sizeof(surface_desc
);
9689 surface_desc
.dwFlags
= DDSD_CAPS
;
9690 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
9691 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
9692 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9694 /* On Windows 7, and probably Vista, UpdateOverlay() will return
9695 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
9696 * surface prevents this by disabling the dwm. */
9697 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
9698 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
9699 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
9700 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
9702 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
9705 win_skip("Cannot disable DWM, skipping overlay test.\n");
9709 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
9710 * used. This is not true in Windows Vista and earlier, but changed in
9712 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
9713 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9714 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
9715 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9716 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
9717 ok(hr
== DD_OK
|| hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9719 /* Show that the overlay position is the (top, left) coordinate of the
9720 * destination rectangle. */
9721 OffsetRect(&rect
, 32, 16);
9722 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
9723 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9724 pos_x
= -1; pos_y
= -1;
9725 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9726 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
9727 ok(pos_x
== rect
.left
, "Got unexpected pos_x %d, expected %d.\n", pos_x
, rect
.left
);
9728 ok(pos_y
== rect
.top
, "Got unexpected pos_y %d, expected %d.\n", pos_y
, rect
.top
);
9730 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
9731 * seen that the overlay overlays the whole primary(==screen). */
9732 hr2
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, 0, NULL
);
9733 ok(hr2
== DD_OK
|| hr2
== DDERR_INVALIDPARAMS
|| hr2
== DDERR_OUTOFCAPS
, "Got unexpected hr %#x.\n", hr2
);
9734 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9735 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
9738 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
9739 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
9743 ok(pos_x
== 32, "Got unexpected pos_x %d.\n", pos_x
);
9744 ok(pos_y
== 16, "Got unexpected pos_y %d.\n", pos_y
);
9747 /* The position cannot be retrieved when the overlay is not shown. */
9748 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_HIDE
, NULL
);
9749 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9750 pos_x
= -1; pos_y
= -1;
9751 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9752 ok(hr
== DDERR_OVERLAYNOTVISIBLE
, "Got unexpected hr %#x.\n", hr
);
9753 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
9754 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
9756 IDirectDrawSurface_Release(overlay
);
9759 IDirectDrawSurface_Release(primary
);
9760 IDirectDraw2_Release(ddraw
);
9761 DestroyWindow(window
);
9764 static void test_blt(void)
9766 IDirectDrawSurface
*surface
, *rt
;
9767 DDSURFACEDESC surface_desc
;
9768 IDirect3DDevice2
*device
;
9769 IDirectDraw2
*ddraw
;
9783 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit. */
9784 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, flipped source. */
9785 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, mirrored source. */
9786 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched x. */
9787 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched y. */
9788 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK
}, /* Full surface blit. */
9789 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT
}, /* Full surface, flipped destination. */
9790 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored destination. */
9791 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, flipped source. */
9792 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored source. */
9795 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9796 0, 0, 640, 480, 0, 0, 0, 0);
9797 ddraw
= create_ddraw();
9798 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9799 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9801 skip("Failed to create a 3D device, skipping test.\n");
9802 IDirectDraw2_Release(ddraw
);
9803 DestroyWindow(window
);
9807 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9808 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9810 memset(&surface_desc
, 0, sizeof(surface_desc
));
9811 surface_desc
.dwSize
= sizeof(surface_desc
);
9812 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
9813 surface_desc
.dwWidth
= 640;
9814 surface_desc
.dwHeight
= 480;
9815 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9816 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9817 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9819 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface
, NULL
, 0, NULL
);
9820 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9822 hr
= IDirectDrawSurface_Blt(surface
, NULL
, rt
, NULL
, 0, NULL
);
9823 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9825 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
9827 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
9828 surface
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
9829 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
9831 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
9832 rt
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
9833 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
9836 IDirectDrawSurface_Release(surface
);
9837 IDirectDrawSurface_Release(rt
);
9838 refcount
= IDirect3DDevice2_Release(device
);
9839 ok(!refcount
, "Device has %u references left.\n", refcount
);
9840 IDirectDraw2_Release(ddraw
);
9841 DestroyWindow(window
);
9844 static void test_getdc(void)
9846 IDirectDrawSurface
*surface
, *surface2
, *tmp
;
9847 DDSURFACEDESC surface_desc
, map_desc
;
9848 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
9849 IDirectDraw2
*ddraw
;
9858 DDPIXELFORMAT format
;
9859 BOOL getdc_supported
;
9864 {"D3DFMT_A8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
9865 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE
},
9866 {"D3DFMT_X8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
9867 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE
},
9868 {"D3DFMT_R5G6B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
9869 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE
},
9870 {"D3DFMT_X1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
9871 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE
},
9872 {"D3DFMT_A1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
9873 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE
},
9874 {"D3DFMT_A4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
9875 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
9876 {"D3DFMT_X4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
9877 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
9878 {"D3DFMT_A2R10G10B10", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
9879 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE
},
9880 {"D3DFMT_A8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
9881 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
9882 {"D3DFMT_X8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
9883 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
9884 {"D3DFMT_R3G3B2", {sizeof(test_data
->format
), DDPF_RGB
, 0, {8},
9885 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE
},
9886 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
9887 * This is not implemented in wine yet, so disable the test for now.
9888 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
9889 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
9890 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
9892 {"D3DFMT_L8", {sizeof(test_data
->format
), DDPF_LUMINANCE
, 0, {8},
9893 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
9894 {"D3DFMT_A8L8", {sizeof(test_data
->format
), DDPF_ALPHAPIXELS
| DDPF_LUMINANCE
, 0, {16},
9895 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE
},
9896 {"D3DFMT_DXT1", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','1'), {0},
9897 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
9898 {"D3DFMT_DXT2", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','2'), {0},
9899 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
9900 {"D3DFMT_DXT3", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','3'), {0},
9901 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
9902 {"D3DFMT_DXT4", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','4'), {0},
9903 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
9904 {"D3DFMT_DXT5", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','5'), {0},
9905 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
9908 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9909 0, 0, 640, 480, 0, 0, 0, 0);
9910 ddraw
= create_ddraw();
9911 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9912 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9913 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9915 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
9917 memset(&surface_desc
, 0, sizeof(surface_desc
));
9918 surface_desc
.dwSize
= sizeof(surface_desc
);
9919 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9920 surface_desc
.dwWidth
= 64;
9921 surface_desc
.dwHeight
= 64;
9922 U4(surface_desc
).ddpfPixelFormat
= test_data
[i
].format
;
9923 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9925 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
9927 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9928 if (FAILED(hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
9930 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data
[i
].name
, hr
);
9935 dc
= (void *)0x1234;
9936 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
9937 if (test_data
[i
].getdc_supported
)
9938 ok(SUCCEEDED(hr
) || (test_data
[i
].alt_result
&& hr
== test_data
[i
].alt_result
),
9939 "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
9941 ok(FAILED(hr
), "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
9945 unsigned int width_bytes
;
9951 type
= GetObjectType(dc
);
9952 ok(type
== OBJ_MEMDC
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
9953 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
9954 type
= GetObjectType(bitmap
);
9955 ok(type
== OBJ_BITMAP
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
9957 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
9958 ok(size
== sizeof(dib
), "Got unexpected size %d for format %s.\n", size
, test_data
[i
].name
);
9959 ok(!dib
.dsBm
.bmType
, "Got unexpected type %#x for format %s.\n",
9960 dib
.dsBm
.bmType
, test_data
[i
].name
);
9961 ok(dib
.dsBm
.bmWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
9962 dib
.dsBm
.bmWidth
, test_data
[i
].name
);
9963 ok(dib
.dsBm
.bmHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
9964 dib
.dsBm
.bmHeight
, test_data
[i
].name
);
9965 width_bytes
= ((dib
.dsBm
.bmWidth
* U1(test_data
[i
].format
).dwRGBBitCount
+ 31) >> 3) & ~3;
9966 ok(dib
.dsBm
.bmWidthBytes
== width_bytes
, "Got unexpected width bytes %d for format %s.\n",
9967 dib
.dsBm
.bmWidthBytes
, test_data
[i
].name
);
9968 ok(dib
.dsBm
.bmPlanes
== 1, "Got unexpected plane count %d for format %s.\n",
9969 dib
.dsBm
.bmPlanes
, test_data
[i
].name
);
9970 ok(dib
.dsBm
.bmBitsPixel
== U1(test_data
[i
].format
).dwRGBBitCount
,
9971 "Got unexpected bit count %d for format %s.\n",
9972 dib
.dsBm
.bmBitsPixel
, test_data
[i
].name
);
9973 ok(!!dib
.dsBm
.bmBits
, "Got unexpected bits %p for format %s.\n",
9974 dib
.dsBm
.bmBits
, test_data
[i
].name
);
9976 ok(dib
.dsBmih
.biSize
== sizeof(dib
.dsBmih
), "Got unexpected size %u for format %s.\n",
9977 dib
.dsBmih
.biSize
, test_data
[i
].name
);
9978 ok(dib
.dsBmih
.biWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
9979 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
9980 ok(dib
.dsBmih
.biHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
9981 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
9982 ok(dib
.dsBmih
.biPlanes
== 1, "Got unexpected plane count %u for format %s.\n",
9983 dib
.dsBmih
.biPlanes
, test_data
[i
].name
);
9984 ok(dib
.dsBmih
.biBitCount
== U1(test_data
[i
].format
).dwRGBBitCount
,
9985 "Got unexpected bit count %u for format %s.\n",
9986 dib
.dsBmih
.biBitCount
, test_data
[i
].name
);
9987 ok(dib
.dsBmih
.biCompression
== (U1(test_data
[i
].format
).dwRGBBitCount
== 16 ? BI_BITFIELDS
: BI_RGB
)
9988 || broken(U2(test_data
[i
].format
).dwRGBBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_BITFIELDS
),
9989 "Got unexpected compression %#x for format %s.\n",
9990 dib
.dsBmih
.biCompression
, test_data
[i
].name
);
9991 ok(!dib
.dsBmih
.biSizeImage
, "Got unexpected image size %u for format %s.\n",
9992 dib
.dsBmih
.biSizeImage
, test_data
[i
].name
);
9993 ok(!dib
.dsBmih
.biXPelsPerMeter
, "Got unexpected horizontal resolution %d for format %s.\n",
9994 dib
.dsBmih
.biXPelsPerMeter
, test_data
[i
].name
);
9995 ok(!dib
.dsBmih
.biYPelsPerMeter
, "Got unexpected vertical resolution %d for format %s.\n",
9996 dib
.dsBmih
.biYPelsPerMeter
, test_data
[i
].name
);
9997 ok(!dib
.dsBmih
.biClrUsed
, "Got unexpected used colour count %u for format %s.\n",
9998 dib
.dsBmih
.biClrUsed
, test_data
[i
].name
);
9999 ok(!dib
.dsBmih
.biClrImportant
, "Got unexpected important colour count %u for format %s.\n",
10000 dib
.dsBmih
.biClrImportant
, test_data
[i
].name
);
10002 if (dib
.dsBmih
.biCompression
== BI_BITFIELDS
)
10004 ok((dib
.dsBitfields
[0] == U2(test_data
[i
].format
).dwRBitMask
10005 && dib
.dsBitfields
[1] == U3(test_data
[i
].format
).dwGBitMask
10006 && dib
.dsBitfields
[2] == U4(test_data
[i
].format
).dwBBitMask
)
10007 || broken(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2]),
10008 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
10009 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
10013 ok(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2],
10014 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
10015 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
10017 ok(!dib
.dshSection
, "Got unexpected section %p for format %s.\n", dib
.dshSection
, test_data
[i
].name
);
10018 ok(!dib
.dsOffset
, "Got unexpected offset %u for format %s.\n", dib
.dsOffset
, test_data
[i
].name
);
10020 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10021 ok(hr
== DD_OK
, "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10025 ok(!dc
, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
10028 IDirectDrawSurface_Release(surface
);
10033 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
10034 if (FAILED(hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
10036 skip("Failed to create mip-mapped texture for format %s (hr %#x), skipping tests.\n",
10037 test_data
[i
].name
, hr
);
10041 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
10042 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10043 hr
= IDirectDrawSurface_GetAttachedSurface(tmp
, &caps
, &surface2
);
10044 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10045 IDirectDrawSurface_Release(tmp
);
10047 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10048 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10049 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10050 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10051 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10052 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10053 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10054 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10056 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10057 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10058 dc2
= (void *)0x1234;
10059 hr
= IDirectDrawSurface_GetDC(surface
, &dc2
);
10060 ok(hr
== DDERR_DCALREADYCREATED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10061 ok(dc2
== (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
10062 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10063 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10064 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10065 ok(hr
== DDERR_NODC
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10067 map_desc
.dwSize
= sizeof(map_desc
);
10068 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10069 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10070 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10071 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10072 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10073 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10074 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10075 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10077 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10078 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10079 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10080 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10081 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10082 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10084 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10085 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10086 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10087 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10088 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10089 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10090 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10091 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10093 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10094 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10095 hr
= IDirectDrawSurface_GetDC(surface2
, &dc2
);
10096 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10097 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc2
);
10098 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10099 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10100 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10102 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10103 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10104 hr
= IDirectDrawSurface_GetDC(surface
, &dc2
);
10105 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10106 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc2
);
10107 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10108 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10109 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10111 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10112 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10113 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10114 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10115 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10116 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10117 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10118 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10120 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10121 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10122 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10123 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10124 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10125 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10126 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10127 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10129 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10130 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10131 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10132 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10133 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10134 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10135 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10136 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10138 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10139 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10140 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10141 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10142 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10143 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10144 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10145 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10147 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10148 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10149 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10150 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10151 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10152 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10153 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10154 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10156 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10157 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10158 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10159 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10160 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10161 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10162 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10163 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10164 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10165 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10167 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10168 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10169 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10170 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10171 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10172 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10173 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10174 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10175 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10176 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10178 IDirectDrawSurface_Release(surface2
);
10179 IDirectDrawSurface_Release(surface
);
10182 IDirectDraw2_Release(ddraw
);
10183 DestroyWindow(window
);
10186 static void test_draw_primitive(void)
10188 static WORD indices
[] = {0, 1, 2, 3};
10189 static D3DVERTEX quad
[] =
10191 {{-1.0f
}, {-1.0f
}, {0.0f
}},
10192 {{-1.0f
}, { 1.0f
}, {0.0f
}},
10193 {{ 1.0f
}, {-1.0f
}, {0.0f
}},
10194 {{ 1.0f
}, { 1.0f
}, {0.0f
}},
10196 IDirect3DViewport2
*viewport
;
10197 IDirect3DDevice2
*device
;
10198 IDirectDraw2
*ddraw
;
10204 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10205 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
10206 ddraw
= create_ddraw();
10207 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10208 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10210 skip("Failed to create a 3D device, skipping test.\n");
10211 IDirectDraw2_Release(ddraw
);
10212 DestroyWindow(window
);
10216 viewport
= create_viewport(device
, 0, 0, 640, 480);
10217 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
10218 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10220 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
10221 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
10223 IDirect3D2_Release(d3d
);
10225 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, NULL
, 0, 0);
10226 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10227 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, 0);
10228 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10230 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, indices
, 4, 0);
10231 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10233 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, NULL
, 0, 0);
10234 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10235 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, 0);
10236 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10237 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, indices
, 4, 0);
10238 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10240 destroy_viewport(device
, viewport
);
10241 refcount
= IDirect3DDevice2_Release(device
);
10242 ok(!refcount
, "Device has %u references left.\n", refcount
);
10243 IDirectDraw2_Release(ddraw
);
10244 DestroyWindow(window
);
10247 static void test_edge_antialiasing_blending(void)
10249 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10250 IDirect3DMaterial2
*green_background
;
10251 IDirect3DMaterial2
*red_background
;
10252 IDirectDrawSurface
*offscreen
, *ds
;
10253 D3DDEVICEDESC hal_desc
, hel_desc
;
10254 IDirect3DViewport2
*viewport
;
10255 DDSURFACEDESC surface_desc
;
10256 IDirect3DDevice2
*device
;
10257 IDirectDraw2
*ddraw
;
10263 static D3DMATRIX mat
=
10265 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10266 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10267 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10268 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10270 static D3DLVERTEX green_quad
[] =
10272 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10273 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10274 {{ 1.0f
}, {-1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10275 {{ 1.0f
}, { 1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10277 static D3DLVERTEX red_quad
[] =
10279 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xccff0000}},
10280 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xccff0000}},
10281 {{ 1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xccff0000}},
10282 {{ 1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xccff0000}},
10285 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10286 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
10287 ddraw
= create_ddraw();
10288 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10289 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10291 skip("Failed to create a 3D device.\n");
10292 DestroyWindow(window
);
10296 memset(&hal_desc
, 0, sizeof(hal_desc
));
10297 hal_desc
.dwSize
= sizeof(hal_desc
);
10298 memset(&hel_desc
, 0, sizeof(hel_desc
));
10299 hel_desc
.dwSize
= sizeof(hel_desc
);
10300 hr
= IDirect3DDevice2_GetCaps(device
, &hal_desc
, &hel_desc
);
10301 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
10302 trace("HAL line edge antialiasing support: %#x.\n",
10303 hal_desc
.dpcLineCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10304 trace("HAL triangle edge antialiasing support: %#x.\n",
10305 hal_desc
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10306 trace("HEL line edge antialiasing support: %#x.\n",
10307 hel_desc
.dpcLineCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10308 trace("HEL triangle edge antialiasing support: %#x.\n",
10309 hel_desc
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10311 memset(&surface_desc
, 0, sizeof(surface_desc
));
10312 surface_desc
.dwSize
= sizeof(surface_desc
);
10313 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
10314 surface_desc
.dwWidth
= 640;
10315 surface_desc
.dwHeight
= 480;
10316 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
10317 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
10318 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
10319 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10320 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10321 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10322 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10323 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
10324 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
10325 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr %#x.\n", hr
);
10327 ds
= get_depth_stencil(device
);
10328 hr
= IDirectDrawSurface_AddAttachedSurface(offscreen
, ds
);
10329 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
10330 IDirectDrawSurface_Release(ds
);
10332 hr
= IDirect3DDevice2_SetRenderTarget(device
, offscreen
, 0);
10333 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
10335 red_background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 0.8f
);
10336 green_background
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.5f
);
10338 viewport
= create_viewport(device
, 0, 0, 640, 480);
10339 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
10340 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10342 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
10343 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
10344 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
10345 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
10346 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
10347 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
10348 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
10349 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
10350 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
10351 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
10352 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10353 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10354 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
10355 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
10356 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
10357 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
10358 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10359 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
10361 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
10362 ok(SUCCEEDED(hr
), "Failed to enable blending, hr %#x.\n", hr
);
10363 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
10364 ok(SUCCEEDED(hr
), "Failed to set src blend, hr %#x.\n", hr
);
10365 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_DESTALPHA
);
10366 ok(SUCCEEDED(hr
), "Failed to set dest blend, hr %#x.\n", hr
);
10368 viewport_set_background(device
, viewport
, red_background
);
10369 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10370 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10371 hr
= IDirect3DDevice2_BeginScene(device
);
10372 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10373 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10374 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10375 hr
= IDirect3DDevice2_EndScene(device
);
10376 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10377 color
= get_surface_color(offscreen
, 320, 240);
10378 ok(compare_color(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
10380 viewport_set_background(device
, viewport
, green_background
);
10381 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10382 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10383 hr
= IDirect3DDevice2_BeginScene(device
);
10384 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10385 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, red_quad
, 4, 0);
10386 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10387 hr
= IDirect3DDevice2_EndScene(device
);
10388 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10389 color
= get_surface_color(offscreen
, 320, 240);
10390 ok(compare_color(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
10392 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
10393 ok(SUCCEEDED(hr
), "Failed to disable blending, hr %#x.\n", hr
);
10395 viewport_set_background(device
, viewport
, red_background
);
10396 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10397 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10398 hr
= IDirect3DDevice2_BeginScene(device
);
10399 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10400 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10401 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10402 hr
= IDirect3DDevice2_EndScene(device
);
10403 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10404 color
= get_surface_color(offscreen
, 320, 240);
10405 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
10407 viewport_set_background(device
, viewport
, green_background
);
10408 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10409 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10410 hr
= IDirect3DDevice2_BeginScene(device
);
10411 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10412 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, red_quad
, 4, 0);
10413 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10414 hr
= IDirect3DDevice2_EndScene(device
);
10415 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10416 color
= get_surface_color(offscreen
, 320, 240);
10417 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
10419 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_EDGEANTIALIAS
, TRUE
);
10420 ok(SUCCEEDED(hr
), "Failed to enable edge antialiasing, hr %#x.\n", hr
);
10422 viewport_set_background(device
, viewport
, red_background
);
10423 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10424 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10425 hr
= IDirect3DDevice2_BeginScene(device
);
10426 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10427 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10428 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10429 hr
= IDirect3DDevice2_EndScene(device
);
10430 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10431 color
= get_surface_color(offscreen
, 320, 240);
10432 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
10434 viewport_set_background(device
, viewport
, green_background
);
10435 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10436 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10437 hr
= IDirect3DDevice2_BeginScene(device
);
10438 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10439 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, red_quad
, 4, 0);
10440 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10441 hr
= IDirect3DDevice2_EndScene(device
);
10442 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10443 color
= get_surface_color(offscreen
, 320, 240);
10444 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
10446 IDirectDrawSurface_Release(offscreen
);
10447 destroy_viewport(device
, viewport
);
10448 destroy_material(red_background
);
10449 destroy_material(green_background
);
10450 refcount
= IDirect3DDevice2_Release(device
);
10451 ok(!refcount
, "Device has %u references left.\n", refcount
);
10452 IDirectDraw2_Release(ddraw
);
10453 DestroyWindow(window
);
10458 IDirectDraw2
*ddraw
;
10459 DEVMODEW current_mode
;
10462 if (!(ddraw
= create_ddraw()))
10464 skip("Failed to create a ddraw object, skipping tests.\n");
10467 IDirectDraw2_Release(ddraw
);
10469 memset(¤t_mode
, 0, sizeof(current_mode
));
10470 current_mode
.dmSize
= sizeof(current_mode
);
10471 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
10472 registry_mode
.dmSize
= sizeof(registry_mode
);
10473 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
10474 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
10475 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
10477 skip("Current mode does not match registry mode, skipping test.\n");
10481 if ((dwmapi
= LoadLibraryA("dwmapi.dll")))
10482 pDwmIsCompositionEnabled
= (void *)GetProcAddress(dwmapi
, "DwmIsCompositionEnabled");
10484 test_coop_level_create_device_window();
10485 test_clipper_blt();
10486 test_coop_level_d3d_state();
10487 test_surface_interface_mismatch();
10488 test_coop_level_threaded();
10490 test_texture_load_ckey();
10499 test_window_style();
10500 test_redundant_mode_set();
10501 test_coop_level_mode_set();
10502 test_coop_level_mode_set_multi();
10504 test_coop_level_surf_create();
10505 test_coop_level_multi_window();
10506 test_clear_rect_count();
10507 test_coop_level_versions();
10508 test_lighting_interface_versions();
10509 test_coop_level_activateapp();
10510 test_unsupported_formats();
10512 test_primary_caps();
10513 test_surface_lock();
10514 test_surface_discard();
10516 test_set_surface_desc();
10517 test_user_memory_getdc();
10518 test_sysmem_overlay();
10519 test_primary_palette();
10520 test_surface_attachment();
10521 test_pixel_format();
10522 test_create_surface_pitch();
10524 test_palette_complex();
10528 test_specular_lighting();
10529 test_palette_gdi();
10530 test_palette_alpha();
10531 test_lost_device();
10532 test_surface_desc_lock();
10533 test_texturemapblend();
10534 test_viewport_clear_rect();
10536 test_colorkey_precision();
10537 test_range_colorkey();
10539 test_lockrect_invalid();
10540 test_yv12_overlay();
10541 test_offscreen_overlay();
10542 test_overlay_rect();
10545 test_draw_primitive();
10546 test_edge_antialiasing_blending();