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"
29 static BOOL is_ddraw64
= sizeof(DWORD
) != sizeof(DWORD
*);
30 static DEVMODEW registry_mode
;
32 static HRESULT (WINAPI
*pDwmIsCompositionEnabled
)(BOOL
*);
35 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
43 struct create_window_thread_param
46 HANDLE window_created
;
47 HANDLE destroy_window
;
51 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
53 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
55 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
57 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
59 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
63 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
73 if (abs(x
- y
) > ulps
)
79 static BOOL
compare_vec4(const struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
81 return compare_float(vec
->x
, x
, ulps
)
82 && compare_float(vec
->y
, y
, ulps
)
83 && compare_float(vec
->z
, z
, ulps
)
84 && compare_float(vec
->w
, w
, ulps
);
87 static BOOL
ddraw_is_warp(IDirectDraw2
*ddraw
)
90 DDDEVICEIDENTIFIER identifier
;
93 if (!strcmp(winetest_platform
, "wine"))
96 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
97 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
98 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, &identifier
, 0);
99 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
100 IDirectDraw4_Release(ddraw4
);
102 return !!strstr(identifier
.szDriver
, "warp");
105 static BOOL
ddraw_is_nvidia(IDirectDraw2
*ddraw
)
107 IDirectDraw4
*ddraw4
;
108 DDDEVICEIDENTIFIER identifier
;
111 if (!strcmp(winetest_platform
, "wine"))
114 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
115 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
116 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, &identifier
, 0);
117 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
118 IDirectDraw4_Release(ddraw4
);
120 return identifier
.dwVendorId
== 0x10de;
123 static BOOL
ddraw_is_intel(IDirectDraw2
*ddraw
)
125 IDirectDraw4
*ddraw4
;
126 DDDEVICEIDENTIFIER identifier
;
129 if (!strcmp(winetest_platform
, "wine"))
132 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
133 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
134 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, &identifier
, 0);
135 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
136 IDirectDraw4_Release(ddraw4
);
138 return identifier
.dwVendorId
== 0x8086;
141 static IDirectDrawSurface
*create_overlay(IDirectDraw2
*ddraw
,
142 unsigned int width
, unsigned int height
, DWORD format
)
144 IDirectDrawSurface
*surface
;
147 memset(&desc
, 0, sizeof(desc
));
148 desc
.dwSize
= sizeof(desc
);
149 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
150 desc
.dwWidth
= width
;
151 desc
.dwHeight
= height
;
152 desc
.ddsCaps
.dwCaps
= DDSCAPS_OVERLAY
;
153 desc
.ddpfPixelFormat
.dwSize
= sizeof(desc
.ddpfPixelFormat
);
154 desc
.ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
155 desc
.ddpfPixelFormat
.dwFourCC
= format
;
157 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &desc
, &surface
, NULL
)))
162 static DWORD WINAPI
create_window_thread_proc(void *param
)
164 struct create_window_thread_param
*p
= param
;
168 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
169 0, 0, 640, 480, 0, 0, 0, 0);
170 ret
= SetEvent(p
->window_created
);
171 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
177 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
178 DispatchMessageA(&msg
);
179 res
= WaitForSingleObject(p
->destroy_window
, 100);
180 if (res
== WAIT_OBJECT_0
)
182 if (res
!= WAIT_TIMEOUT
)
184 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
189 DestroyWindow(p
->window
);
194 static void create_window_thread(struct create_window_thread_param
*p
)
198 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
199 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
200 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
201 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
202 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
203 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
204 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
205 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
208 static void destroy_window_thread(struct create_window_thread_param
*p
)
210 SetEvent(p
->destroy_window
);
211 WaitForSingleObject(p
->thread
, INFINITE
);
212 CloseHandle(p
->destroy_window
);
213 CloseHandle(p
->window_created
);
214 CloseHandle(p
->thread
);
217 static IDirectDrawSurface
*get_depth_stencil(IDirect3DDevice2
*device
)
219 IDirectDrawSurface
*rt
, *ret
;
220 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
223 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
224 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
225 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ret
);
226 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
227 IDirectDrawSurface_Release(rt
);
231 static HRESULT
set_display_mode(IDirectDraw2
*ddraw
, DWORD width
, DWORD height
)
233 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
235 return IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
238 static D3DCOLOR
get_surface_color(IDirectDrawSurface
*surface
, UINT x
, UINT y
)
240 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
241 DDSURFACEDESC surface_desc
;
245 memset(&surface_desc
, 0, sizeof(surface_desc
));
246 surface_desc
.dwSize
= sizeof(surface_desc
);
248 hr
= IDirectDrawSurface_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
249 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
253 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
255 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
256 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
261 static DWORD
get_device_z_depth(IDirect3DDevice2
*device
)
263 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
264 IDirectDrawSurface
*ds
, *rt
;
268 if (FAILED(IDirect3DDevice2_GetRenderTarget(device
, &rt
)))
271 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ds
);
272 IDirectDrawSurface_Release(rt
);
276 desc
.dwSize
= sizeof(desc
);
277 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
278 IDirectDrawSurface_Release(ds
);
282 return U2(desc
).dwZBufferBitDepth
;
285 static IDirectDraw2
*create_ddraw(void)
287 IDirectDraw2
*ddraw2
;
291 if (FAILED(DirectDrawCreate(NULL
, &ddraw1
, NULL
)))
294 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw2
, (void **)&ddraw2
);
295 IDirectDraw_Release(ddraw1
);
302 static IDirect3DDevice2
*create_device(IDirectDraw2
*ddraw
, HWND window
, DWORD coop_level
)
304 static const DWORD z_depths
[] = {32, 24, 16};
305 IDirectDrawSurface
*surface
, *ds
;
306 IDirect3DDevice2
*device
= NULL
;
307 DDSURFACEDESC surface_desc
;
312 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, coop_level
);
313 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
315 memset(&surface_desc
, 0, sizeof(surface_desc
));
316 surface_desc
.dwSize
= sizeof(surface_desc
);
317 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
318 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
319 surface_desc
.dwWidth
= 640;
320 surface_desc
.dwHeight
= 480;
322 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
323 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
325 if (coop_level
& DDSCL_NORMAL
)
327 IDirectDrawClipper
*clipper
;
329 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
330 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
331 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
332 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
333 hr
= IDirectDrawSurface_SetClipper(surface
, clipper
);
334 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
335 IDirectDrawClipper_Release(clipper
);
338 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
341 IDirectDrawSurface_Release(surface
);
345 /* We used to use EnumDevices() for this, but it seems
346 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
347 * relationship with reality. */
348 for (i
= 0; i
< sizeof(z_depths
) / sizeof(*z_depths
); ++i
)
350 memset(&surface_desc
, 0, sizeof(surface_desc
));
351 surface_desc
.dwSize
= sizeof(surface_desc
);
352 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
353 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
354 U2(surface_desc
).dwZBufferBitDepth
= z_depths
[i
];
355 surface_desc
.dwWidth
= 640;
356 surface_desc
.dwHeight
= 480;
357 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
)))
360 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
361 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
362 IDirectDrawSurface_Release(ds
);
366 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
)))
369 IDirectDrawSurface_DeleteAttachedSurface(surface
, 0, ds
);
372 IDirect3D2_Release(d3d
);
373 IDirectDrawSurface_Release(surface
);
377 static IDirect3DViewport2
*create_viewport(IDirect3DDevice2
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
379 IDirect3DViewport2
*viewport
;
384 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
385 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
386 hr
= IDirect3D2_CreateViewport(d3d
, &viewport
, NULL
);
387 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
388 hr
= IDirect3DDevice2_AddViewport(device
, viewport
);
389 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
390 memset(&vp
, 0, sizeof(vp
));
391 vp
.dwSize
= sizeof(vp
);
398 vp
.dvClipWidth
= 2.0f
;
399 vp
.dvClipHeight
= 2.0f
;
402 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp
);
403 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
404 IDirect3D2_Release(d3d
);
409 static void viewport_set_background(IDirect3DDevice2
*device
, IDirect3DViewport2
*viewport
,
410 IDirect3DMaterial2
*material
)
412 D3DMATERIALHANDLE material_handle
;
415 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &material_handle
);
416 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
417 hr
= IDirect3DViewport2_SetBackground(viewport
, material_handle
);
418 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
421 static void destroy_viewport(IDirect3DDevice2
*device
, IDirect3DViewport2
*viewport
)
425 hr
= IDirect3DDevice2_DeleteViewport(device
, viewport
);
426 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
427 IDirect3DViewport2_Release(viewport
);
430 static IDirect3DMaterial2
*create_material(IDirect3DDevice2
*device
, D3DMATERIAL
*mat
)
432 IDirect3DMaterial2
*material
;
436 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
437 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
438 hr
= IDirect3D2_CreateMaterial(d3d
, &material
, NULL
);
439 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
440 hr
= IDirect3DMaterial2_SetMaterial(material
, mat
);
441 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
442 IDirect3D2_Release(d3d
);
447 static IDirect3DMaterial2
*create_diffuse_material(IDirect3DDevice2
*device
, float r
, float g
, float b
, float a
)
451 memset(&mat
, 0, sizeof(mat
));
452 mat
.dwSize
= sizeof(mat
);
453 U1(U(mat
).diffuse
).r
= r
;
454 U2(U(mat
).diffuse
).g
= g
;
455 U3(U(mat
).diffuse
).b
= b
;
456 U4(U(mat
).diffuse
).a
= a
;
458 return create_material(device
, &mat
);
461 static IDirect3DMaterial2
*create_specular_material(IDirect3DDevice2
*device
,
462 float r
, float g
, float b
, float a
, float power
)
466 memset(&mat
, 0, sizeof(mat
));
467 mat
.dwSize
= sizeof(mat
);
468 U1(U2(mat
).specular
).r
= r
;
469 U2(U2(mat
).specular
).g
= g
;
470 U3(U2(mat
).specular
).b
= b
;
471 U4(U2(mat
).specular
).a
= a
;
472 U4(mat
).power
= power
;
474 return create_material(device
, &mat
);
477 static IDirect3DMaterial2
*create_emissive_material(IDirect3DDevice2
*device
, float r
, float g
, float b
, float a
)
481 memset(&mat
, 0, sizeof(mat
));
482 mat
.dwSize
= sizeof(mat
);
483 U1(U3(mat
).emissive
).r
= r
;
484 U2(U3(mat
).emissive
).g
= g
;
485 U3(U3(mat
).emissive
).b
= b
;
486 U4(U3(mat
).emissive
).a
= a
;
488 return create_material(device
, &mat
);
491 static void destroy_material(IDirect3DMaterial2
*material
)
493 IDirect3DMaterial2_Release(material
);
500 WPARAM expect_wparam
;
503 static const struct message
*expect_messages
;
505 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
507 if (expect_messages
&& message
== expect_messages
->message
)
509 if (expect_messages
->check_wparam
)
510 ok (wparam
== expect_messages
->expect_wparam
,
511 "Got unexpected wparam %lx for message %x, expected %lx.\n",
512 wparam
, message
, expect_messages
->expect_wparam
);
517 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
520 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
521 * interface. This prevents subsequent SetCooperativeLevel() calls on a
522 * different window from failing with DDERR_HWNDALREADYSET. */
523 static void fix_wndproc(HWND window
, LONG_PTR proc
)
528 if (!(ddraw
= create_ddraw()))
531 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
532 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
533 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
534 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
535 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
537 IDirectDraw2_Release(ddraw
);
540 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
542 HRESULT hr
= IDirectDrawSurface_Restore(surface
);
543 ok(SUCCEEDED(hr
) || hr
== DDERR_IMPLICITLYCREATED
, "Failed to restore surface, hr %#x.\n", hr
);
544 IDirectDrawSurface_Release(surface
);
549 static HRESULT
restore_surfaces(IDirectDraw2
*ddraw
)
551 return IDirectDraw2_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
552 NULL
, NULL
, restore_callback
);
555 static void test_coop_level_create_device_window(void)
557 HWND focus_window
, device_window
;
561 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
562 0, 0, 640, 480, 0, 0, 0, 0);
563 ddraw
= create_ddraw();
564 ok(!!ddraw
, "Failed to create a ddraw object.\n");
566 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
567 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
568 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
569 ok(!device_window
, "Unexpected device window found.\n");
570 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
571 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
572 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
573 ok(!device_window
, "Unexpected device window found.\n");
574 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
575 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
576 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
577 ok(!device_window
, "Unexpected device window found.\n");
578 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
579 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
580 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
581 ok(!device_window
, "Unexpected device window found.\n");
582 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
583 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
584 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
585 ok(!device_window
, "Unexpected device window found.\n");
587 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
588 if (broken(hr
== DDERR_INVALIDPARAMS
))
590 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
591 IDirectDraw2_Release(ddraw
);
592 DestroyWindow(focus_window
);
596 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
597 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
598 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
599 ok(!device_window
, "Unexpected device window found.\n");
600 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
601 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
602 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
603 ok(!device_window
, "Unexpected device window found.\n");
605 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
606 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
607 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
608 ok(!device_window
, "Unexpected device window found.\n");
609 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
610 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
611 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
612 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
613 ok(!!device_window
, "Device window not found.\n");
615 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
616 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
617 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
618 ok(!device_window
, "Unexpected device window found.\n");
619 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
620 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
621 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
622 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
623 ok(!!device_window
, "Device window not found.\n");
625 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
626 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
627 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
628 ok(!device_window
, "Unexpected device window found.\n");
629 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
630 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
631 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
632 ok(!device_window
, "Unexpected device window found.\n");
633 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
634 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
635 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
636 ok(!device_window
, "Unexpected device window found.\n");
637 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
638 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
639 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
640 ok(!!device_window
, "Device window not found.\n");
642 IDirectDraw2_Release(ddraw
);
643 DestroyWindow(focus_window
);
646 static void test_clipper_blt(void)
648 IDirectDrawSurface
*src_surface
, *dst_surface
;
649 RECT client_rect
, src_rect
;
650 IDirectDrawClipper
*clipper
;
651 DDSURFACEDESC surface_desc
;
652 unsigned int i
, j
, x
, y
;
664 static const DWORD src_data
[] =
666 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
667 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
668 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
670 static const D3DCOLOR expected1
[] =
672 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
673 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
674 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
675 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
677 /* Nvidia on Windows seems to have an off-by-one error
678 * when processing source rectangles. Our left = 1 and
679 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
680 * read as well, but only for the edge pixels on the
681 * output image. The bug happens on the y axis as well,
682 * but we only read one row there, and all source rows
683 * contain the same data. This bug is not dependent on
684 * the presence of a clipper. */
685 static const D3DCOLOR expected1_broken
[] =
687 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
688 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
689 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
690 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
692 static const D3DCOLOR expected2
[] =
694 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
695 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
696 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
697 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
700 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
701 10, 10, 640, 480, 0, 0, 0, 0);
702 ShowWindow(window
, SW_SHOW
);
703 ddraw
= create_ddraw();
704 ok(!!ddraw
, "Failed to create a ddraw object.\n");
706 ret
= GetClientRect(window
, &client_rect
);
707 ok(ret
, "Failed to get client rect.\n");
708 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
709 ok(ret
, "Failed to map client rect.\n");
711 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
712 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
714 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
715 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
716 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
717 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
718 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
719 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
720 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
721 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
722 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
723 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
724 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
725 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
726 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
727 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
728 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
729 "Got unexpected bounding rect %s, expected %s.\n",
730 wine_dbgstr_rect(&rgn_data
->rdh
.rcBound
), wine_dbgstr_rect(&client_rect
));
731 HeapFree(GetProcessHeap(), 0, rgn_data
);
733 r1
= CreateRectRgn(0, 0, 320, 240);
734 ok(!!r1
, "Failed to create region.\n");
735 r2
= CreateRectRgn(320, 240, 640, 480);
736 ok(!!r2
, "Failed to create region.\n");
737 CombineRgn(r1
, r1
, r2
, RGN_OR
);
738 ret
= GetRegionData(r1
, 0, NULL
);
739 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
740 ret
= GetRegionData(r1
, ret
, rgn_data
);
741 ok(!!ret
, "Failed to get region data.\n");
746 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
747 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
748 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
749 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
750 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
751 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
753 HeapFree(GetProcessHeap(), 0, rgn_data
);
755 memset(&surface_desc
, 0, sizeof(surface_desc
));
756 surface_desc
.dwSize
= sizeof(surface_desc
);
757 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
758 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
759 surface_desc
.dwWidth
= 640;
760 surface_desc
.dwHeight
= 480;
761 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
762 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
763 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
764 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
765 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
766 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
768 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
769 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
770 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
771 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
773 memset(&fx
, 0, sizeof(fx
));
774 fx
.dwSize
= sizeof(fx
);
775 hr
= IDirectDrawSurface_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
776 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
777 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
778 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
780 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
781 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
782 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
783 ptr
= surface_desc
.lpSurface
;
784 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
785 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
786 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
787 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
788 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
790 hr
= IDirectDrawSurface_SetClipper(dst_surface
, clipper
);
791 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
793 SetRect(&src_rect
, 1, 1, 5, 2);
794 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
795 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
796 for (i
= 0; i
< 4; ++i
)
798 for (j
= 0; j
< 4; ++j
)
800 x
= 80 * ((2 * j
) + 1);
801 y
= 60 * ((2 * i
) + 1);
802 color
= get_surface_color(dst_surface
, x
, y
);
803 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
804 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
805 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
809 U5(fx
).dwFillColor
= 0xff0000ff;
810 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
811 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
812 for (i
= 0; i
< 4; ++i
)
814 for (j
= 0; j
< 4; ++j
)
816 x
= 80 * ((2 * j
) + 1);
817 y
= 60 * ((2 * i
) + 1);
818 color
= get_surface_color(dst_surface
, x
, y
);
819 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
820 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
824 hr
= IDirectDrawSurface_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
825 ok(hr
== DDERR_BLTFASTCANTCLIP
|| broken(hr
== E_NOTIMPL
/* NT4 */), "Got unexpected hr %#x.\n", hr
);
827 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
828 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
829 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
830 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
831 DestroyWindow(window
);
832 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
833 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
834 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
835 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
836 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
837 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
838 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
839 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
840 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
841 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
842 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
843 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
845 IDirectDrawSurface_Release(dst_surface
);
846 IDirectDrawSurface_Release(src_surface
);
847 refcount
= IDirectDrawClipper_Release(clipper
);
848 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
849 IDirectDraw2_Release(ddraw
);
852 static void test_coop_level_d3d_state(void)
854 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
855 IDirectDrawSurface
*rt
, *surface
;
856 IDirect3DMaterial2
*background
;
857 IDirect3DViewport2
*viewport
;
858 IDirect3DDevice2
*device
;
859 D3DMATERIAL material
;
866 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
867 0, 0, 640, 480, 0, 0, 0, 0);
868 ddraw
= create_ddraw();
869 ok(!!ddraw
, "Failed to create a ddraw object.\n");
870 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
872 skip("Failed to create a 3D device, skipping test.\n");
873 IDirectDraw2_Release(ddraw
);
874 DestroyWindow(window
);
878 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
879 viewport
= create_viewport(device
, 0, 0, 640, 480);
880 viewport_set_background(device
, viewport
, background
);
882 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
883 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
884 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
885 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
886 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
887 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
888 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
889 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
890 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
891 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
892 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
893 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
894 color
= get_surface_color(rt
, 320, 240);
895 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
897 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
898 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
899 hr
= IDirectDrawSurface_IsLost(rt
);
900 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
901 hr
= restore_surfaces(ddraw
);
902 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
904 memset(&material
, 0, sizeof(material
));
905 material
.dwSize
= sizeof(material
);
906 U1(U(material
).diffuse
).r
= 0.0f
;
907 U2(U(material
).diffuse
).g
= 1.0f
;
908 U3(U(material
).diffuse
).b
= 0.0f
;
909 U4(U(material
).diffuse
).a
= 1.0f
;
910 hr
= IDirect3DMaterial2_SetMaterial(background
, &material
);
911 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
913 hr
= IDirect3DDevice2_GetRenderTarget(device
, &surface
);
914 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
915 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
916 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
917 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
918 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
919 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
920 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
921 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
922 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
923 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
924 color
= get_surface_color(rt
, 320, 240);
925 ok(compare_color(color
, 0x0000ff00, 1) || broken(compare_color(color
, 0x00000000, 1)),
926 "Got unexpected color 0x%08x.\n", color
);
928 destroy_viewport(device
, viewport
);
929 destroy_material(background
);
930 IDirectDrawSurface_Release(surface
);
931 IDirectDrawSurface_Release(rt
);
932 IDirect3DDevice2_Release(device
);
933 IDirectDraw2_Release(ddraw
);
934 DestroyWindow(window
);
937 static void test_surface_interface_mismatch(void)
939 IDirectDraw2
*ddraw
= NULL
;
940 IDirect3D2
*d3d
= NULL
;
941 IDirectDrawSurface
*surface
= NULL
, *ds
;
942 IDirectDrawSurface3
*surface3
= NULL
;
943 IDirect3DDevice2
*device
= NULL
;
944 IDirect3DViewport2
*viewport
= NULL
;
945 IDirect3DMaterial2
*background
= NULL
;
946 DDSURFACEDESC surface_desc
;
952 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
954 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
955 0, 0, 640, 480, 0, 0, 0, 0);
956 ddraw
= create_ddraw();
957 ok(!!ddraw
, "Failed to create a ddraw object.\n");
958 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
960 skip("Failed to create a 3D device, skipping test.\n");
961 IDirectDraw2_Release(ddraw
);
962 DestroyWindow(window
);
965 z_depth
= get_device_z_depth(device
);
966 ok(!!z_depth
, "Failed to get device z depth.\n");
967 IDirect3DDevice2_Release(device
);
970 memset(&surface_desc
, 0, sizeof(surface_desc
));
971 surface_desc
.dwSize
= sizeof(surface_desc
);
972 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
973 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
974 surface_desc
.dwWidth
= 640;
975 surface_desc
.dwHeight
= 480;
977 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
978 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
980 hr
= IDirectDrawSurface2_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
983 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
987 if (FAILED(IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
)))
989 skip("D3D interface is not available, skipping test.\n");
993 memset(&surface_desc
, 0, sizeof(surface_desc
));
994 surface_desc
.dwSize
= sizeof(surface_desc
);
995 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
996 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
997 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
998 surface_desc
.dwWidth
= 640;
999 surface_desc
.dwHeight
= 480;
1000 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
1001 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
1005 /* Using a different surface interface version still works */
1006 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
1007 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
1008 refcount
= IDirectDrawSurface_Release(ds
);
1009 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1014 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface
*)surface3
, &device
);
1015 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
1019 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1020 viewport
= create_viewport(device
, 0, 0, 640, 480);
1021 viewport_set_background(device
, viewport
, background
);
1023 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1024 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1025 color
= get_surface_color(surface
, 320, 240);
1026 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
1030 destroy_viewport(device
, viewport
);
1032 destroy_material(background
);
1033 if (surface3
) IDirectDrawSurface3_Release(surface3
);
1034 if (surface
) IDirectDrawSurface_Release(surface
);
1035 if (device
) IDirect3DDevice2_Release(device
);
1036 if (d3d
) IDirect3D2_Release(d3d
);
1037 if (ddraw
) IDirectDraw2_Release(ddraw
);
1038 DestroyWindow(window
);
1041 static void test_coop_level_threaded(void)
1043 struct create_window_thread_param p
;
1044 IDirectDraw2
*ddraw
;
1047 ddraw
= create_ddraw();
1048 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1049 create_window_thread(&p
);
1051 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1052 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1054 IDirectDraw2_Release(ddraw
);
1055 destroy_window_thread(&p
);
1058 static void test_depth_blit(void)
1060 static D3DLVERTEX quad1
[] =
1062 {{-1.0}, { 1.0}, {0.50f
}, 0, {0xff00ff00}},
1063 {{ 1.0}, { 1.0}, {0.50f
}, 0, {0xff00ff00}},
1064 {{-1.0}, {-1.0}, {0.50f
}, 0, {0xff00ff00}},
1065 {{ 1.0}, {-1.0}, {0.50f
}, 0, {0xff00ff00}},
1067 static const D3DCOLOR expected_colors
[4][4] =
1069 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1070 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1071 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1072 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1074 DDSURFACEDESC ddsd_new
, ddsd_existing
;
1076 IDirect3DDevice2
*device
;
1077 IDirectDrawSurface
*ds1
, *ds2
, *ds3
, *rt
;
1078 IDirect3DViewport2
*viewport
;
1079 RECT src_rect
, dst_rect
;
1083 IDirectDraw2
*ddraw
;
1087 IDirect3DMaterial2
*background
;
1089 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1090 0, 0, 640, 480, 0, 0, 0, 0);
1091 ddraw
= create_ddraw();
1092 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1093 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1095 skip("Failed to create a 3D device, skipping test.\n");
1096 IDirectDraw2_Release(ddraw
);
1097 DestroyWindow(window
);
1101 ds1
= get_depth_stencil(device
);
1103 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1104 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1105 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1106 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1107 hr
= IDirectDrawSurface_GetSurfaceDesc(ds1
, &ddsd_existing
);
1108 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
1109 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1110 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1111 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1112 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1113 ddsd_new
.ddpfPixelFormat
= ddsd_existing
.ddpfPixelFormat
;
1114 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1115 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1116 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1117 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1119 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1120 viewport
= create_viewport(device
, 0, 0, ddsd_existing
.dwWidth
, ddsd_existing
.dwHeight
);
1121 viewport_set_background(device
, viewport
, background
);
1122 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1123 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
1125 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1126 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1127 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1128 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1130 U1(d3drect
).x1
= U2(d3drect
).y1
= 0;
1131 U3(d3drect
).x2
= ddsd_existing
.dwWidth
; U4(d3drect
).y2
= ddsd_existing
.dwHeight
;
1132 hr
= IDirect3DViewport2_Clear(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
);
1133 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1136 SetRect(&src_rect
, 0, 0, 320, 240);
1137 SetRect(&dst_rect
, 0, 0, 320, 240);
1138 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1139 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1140 /* Different locations. */
1141 SetRect(&src_rect
, 0, 0, 320, 240);
1142 SetRect(&dst_rect
, 320, 240, 640, 480);
1143 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1144 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1146 SetRect(&src_rect
, 0, 0, 320, 240);
1147 SetRect(&dst_rect
, 0, 0, 640, 480);
1148 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1149 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1151 SetRect(&src_rect
, 0, 480, 640, 0);
1152 SetRect(&dst_rect
, 0, 0, 640, 480);
1153 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1154 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1155 SetRect(&src_rect
, 0, 0, 640, 480);
1156 SetRect(&dst_rect
, 0, 480, 640, 0);
1157 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1158 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1159 /* Full, explicit. */
1160 SetRect(&src_rect
, 0, 0, 640, 480);
1161 SetRect(&dst_rect
, 0, 0, 640, 480);
1162 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1163 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1164 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1166 /* Depth blit inside a BeginScene / EndScene pair */
1167 hr
= IDirect3DDevice2_BeginScene(device
);
1168 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1169 /* From the current depth stencil */
1170 hr
= IDirectDrawSurface_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1171 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1172 /* To the current depth stencil */
1173 hr
= IDirectDrawSurface_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1174 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1175 /* Between unbound surfaces */
1176 hr
= IDirectDrawSurface_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1177 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1178 hr
= IDirect3DDevice2_EndScene(device
);
1179 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1181 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1182 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1183 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1184 * a reliable result(z = 0.0) */
1185 memset(&fx
, 0, sizeof(fx
));
1186 fx
.dwSize
= sizeof(fx
);
1187 U5(fx
).dwFillDepth
= 0;
1188 hr
= IDirectDrawSurface_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1189 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1191 /* This clears the Z buffer with 1.0 */
1192 hr
= IDirect3DViewport2_Clear(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
);
1193 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1195 SetRect(&dst_rect
, 0, 0, 320, 240);
1196 hr
= IDirectDrawSurface_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1197 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1198 IDirectDrawSurface_Release(ds3
);
1199 IDirectDrawSurface_Release(ds2
);
1200 IDirectDrawSurface_Release(ds1
);
1202 hr
= IDirect3DDevice2_BeginScene(device
);
1203 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1204 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad1
, 4, 0);
1205 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1206 hr
= IDirect3DDevice2_EndScene(device
);
1207 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1209 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1210 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1211 for (i
= 0; i
< 4; ++i
)
1213 for (j
= 0; j
< 4; ++j
)
1215 unsigned int x
= 80 * ((2 * j
) + 1);
1216 unsigned int y
= 60 * ((2 * i
) + 1);
1217 color
= get_surface_color(rt
, x
, y
);
1218 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1219 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1222 IDirectDrawSurface_Release(rt
);
1224 destroy_viewport(device
, viewport
);
1225 destroy_material(background
);
1226 IDirect3DDevice2_Release(device
);
1227 IDirectDraw2_Release(ddraw
);
1228 DestroyWindow(window
);
1231 static void test_texture_load_ckey(void)
1233 IDirectDraw2
*ddraw
= NULL
;
1234 IDirectDrawSurface
*src
= NULL
;
1235 IDirectDrawSurface
*dst
= NULL
;
1236 IDirect3DTexture
*src_tex
= NULL
;
1237 IDirect3DTexture
*dst_tex
= NULL
;
1242 ddraw
= create_ddraw();
1243 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1244 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
1245 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1247 memset(&ddsd
, 0, sizeof(ddsd
));
1248 ddsd
.dwSize
= sizeof(ddsd
);
1249 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1250 ddsd
.dwHeight
= 128;
1252 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1253 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1254 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1255 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1256 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1257 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1259 hr
= IDirectDrawSurface_QueryInterface(src
, &IID_IDirect3DTexture
, (void **)&src_tex
);
1260 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get Direct3DTexture interface, hr %#x.\n", hr
);
1263 /* 64 bit ddraw does not support d3d */
1264 skip("Could not get Direct3DTexture interface, skipping texture::Load color keying tests.\n");
1267 hr
= IDirectDrawSurface_QueryInterface(dst
, &IID_IDirect3DTexture
, (void **)&dst_tex
);
1268 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture interface, hr %#x.\n", hr
);
1270 /* No surface has a color key */
1271 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1272 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDCAPS
), "Got unexpected hr %#x.\n", hr
);
1275 /* Testbot Windows NT VMs */
1276 skip("IDirect3DTexture::Load does not work, skipping color keying tests.\n");
1280 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1281 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1282 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1283 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1284 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1286 /* Source surface has a color key */
1287 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1288 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1289 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1290 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1291 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1292 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1293 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1294 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1295 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1297 /* Both surfaces have a color key: Dest ckey is overwritten */
1298 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1299 hr
= IDirectDrawSurface_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1300 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1301 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1302 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1303 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1304 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1305 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1306 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1308 /* Only the destination has a color key: It is not deleted */
1309 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1310 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1311 hr
= IDirectDrawSurface_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1312 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1313 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1314 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1315 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1316 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1317 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1318 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1321 if (dst_tex
) IDirect3DTexture_Release(dst_tex
);
1322 if (src_tex
) IDirect3DTexture_Release(src_tex
);
1323 if (dst
) IDirectDrawSurface_Release(dst
);
1324 if (src
) IDirectDrawSurface_Release(src
);
1325 if (ddraw
) IDirectDraw2_Release(ddraw
);
1328 static ULONG
get_refcount(IUnknown
*test_iface
)
1330 IUnknown_AddRef(test_iface
);
1331 return IUnknown_Release(test_iface
);
1334 static void test_viewport(void)
1336 IDirectDraw2
*ddraw
;
1339 ULONG ref
, old_d3d_ref
;
1340 IDirect3DViewport
*viewport
;
1341 IDirect3DViewport2
*viewport2
, *another_vp
, *test_vp
;
1342 IDirect3DViewport3
*viewport3
;
1343 IDirectDrawGammaControl
*gamma
;
1345 IDirect3DDevice2
*device
;
1348 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1349 0, 0, 640, 480, 0, 0, 0, 0);
1350 ddraw
= create_ddraw();
1351 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1352 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1354 skip("Failed to create a 3D device, skipping test.\n");
1355 IDirectDraw_Release(ddraw
);
1356 DestroyWindow(window
);
1360 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
1361 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get d3d interface, hr %#x.\n", hr
);
1364 skip("D3D interface is not available, skipping test.\n");
1365 IDirectDraw2_Release(ddraw
);
1368 old_d3d_ref
= get_refcount((IUnknown
*)d3d
);
1370 hr
= IDirect3D2_CreateViewport(d3d
, &viewport2
, NULL
);
1371 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1372 ref
= get_refcount((IUnknown
*)viewport2
);
1373 ok(ref
== 1, "Initial IDirect3DViewport2 refcount is %u\n", ref
);
1374 ref
= get_refcount((IUnknown
*)d3d
);
1375 ok(ref
== old_d3d_ref
, "IDirect3D2 refcount is %u\n", ref
);
1377 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1378 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1379 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
1380 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1381 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1382 /* NULL iid: Segfaults */
1384 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirect3DViewport
, (void **)&viewport
);
1385 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport, hr %#x.\n", hr
);
1388 ref
= get_refcount((IUnknown
*)viewport
);
1389 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1390 ref
= get_refcount((IUnknown
*)viewport2
);
1391 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1392 IDirect3DViewport_Release(viewport
);
1396 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirect3DViewport3
, (void **)&viewport3
);
1397 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1400 ref
= get_refcount((IUnknown
*)viewport2
);
1401 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1402 ref
= get_refcount((IUnknown
*)viewport3
);
1403 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1404 IDirect3DViewport3_Release(viewport3
);
1407 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IUnknown
, (void **)&unknown
);
1408 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1411 ref
= get_refcount((IUnknown
*)viewport2
);
1412 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1413 ref
= get_refcount(unknown
);
1414 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1415 IUnknown_Release(unknown
);
1418 /* AddViewport(NULL): Segfault */
1419 hr
= IDirect3DDevice2_DeleteViewport(device
, NULL
);
1420 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1421 hr
= IDirect3DDevice2_GetCurrentViewport(device
, NULL
);
1422 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1424 hr
= IDirect3D2_CreateViewport(d3d
, &another_vp
, NULL
);
1425 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1427 /* Setting a viewport not in the viewport list fails */
1428 hr
= IDirect3DDevice2_SetCurrentViewport(device
, another_vp
);
1429 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1431 hr
= IDirect3DDevice2_AddViewport(device
, viewport2
);
1432 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1433 ref
= get_refcount((IUnknown
*) viewport2
);
1434 ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1435 hr
= IDirect3DDevice2_AddViewport(device
, another_vp
);
1436 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1437 ref
= get_refcount((IUnknown
*) another_vp
);
1438 ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1440 test_vp
= (IDirect3DViewport2
*) 0xbaadc0de;
1441 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1442 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1443 ok(test_vp
== (IDirect3DViewport2
*) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp
);
1445 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
1446 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1447 ref
= get_refcount((IUnknown
*) viewport2
);
1448 ok(ref
== 3, "viewport2 refcount is %d\n", ref
);
1449 ref
= get_refcount((IUnknown
*) device
);
1450 ok(ref
== 1, "device refcount is %d\n", ref
);
1453 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1454 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1455 ok(test_vp
== viewport2
, "Got unexpected viewport %p\n", test_vp
);
1456 ref
= get_refcount((IUnknown
*) viewport2
);
1457 ok(ref
== 4, "viewport2 refcount is %d\n", ref
);
1458 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1460 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1462 /* Cannot set the viewport to NULL */
1463 hr
= IDirect3DDevice2_SetCurrentViewport(device
, NULL
);
1464 ok(hr
== DDERR_INVALIDPARAMS
, "Failed to set viewport to NULL, hr %#x.\n", hr
);
1466 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1467 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1468 ok(test_vp
== viewport2
, "Got unexpected viewport %p\n", test_vp
);
1469 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1471 /* SetCurrentViewport properly releases the old viewport's reference */
1472 hr
= IDirect3DDevice2_SetCurrentViewport(device
, another_vp
);
1473 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1474 ref
= get_refcount((IUnknown
*) viewport2
);
1475 ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1476 ref
= get_refcount((IUnknown
*) another_vp
);
1477 ok(ref
== 3, "another_vp refcount is %d\n", ref
);
1479 /* Deleting the viewport removes the reference added by AddViewport, but not
1480 * the one added by SetCurrentViewport. */
1481 hr
= IDirect3DDevice2_DeleteViewport(device
, another_vp
);
1482 ok(SUCCEEDED(hr
), "Failed to delete viewport from device, hr %#x.\n", hr
);
1483 ref
= get_refcount((IUnknown
*) another_vp
);
1484 todo_wine
ok(ref
== 2, "IDirect3DViewport2 refcount is %d\n", ref
);
1486 /* GetCurrentViewport fails though */
1488 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1489 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1490 ok(test_vp
== NULL
, "Got unexpected viewport %p\n", test_vp
);
1491 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1493 /* Setting a different viewport does not free the leaked reference. How
1494 * do I get rid of it? Leak the viewport for now. */
1495 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
1496 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1497 ref
= get_refcount((IUnknown
*) viewport2
);
1498 ok(ref
== 3, "viewport2 refcount is %d\n", ref
);
1499 ref
= get_refcount((IUnknown
*) another_vp
);
1500 todo_wine
ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1502 /* Destroying the device removes the viewport, but does not free the reference
1503 * added by SetCurrentViewport. */
1504 IDirect3DDevice2_Release(device
);
1505 ref
= get_refcount((IUnknown
*) viewport2
);
1506 todo_wine
ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1508 IDirect3DViewport2_Release(another_vp
);
1509 IDirect3DViewport2_Release(viewport2
);
1510 IDirect3D2_Release(d3d
);
1511 DestroyWindow(window
);
1512 IDirectDraw2_Release(ddraw
);
1515 static void test_zenable(void)
1517 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1518 static D3DTLVERTEX tquad
[] =
1520 {{ 0.0f
}, {480.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1521 {{ 0.0f
}, { 0.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1522 {{640.0f
}, {480.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1523 {{640.0f
}, { 0.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1525 IDirect3DMaterial2
*background
;
1526 IDirect3DViewport2
*viewport
;
1527 IDirect3DDevice2
*device
;
1528 IDirectDrawSurface
*rt
;
1529 IDirectDraw2
*ddraw
;
1536 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1537 0, 0, 640, 480, 0, 0, 0, 0);
1538 ddraw
= create_ddraw();
1539 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1540 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1542 skip("Failed to create a 3D device, skipping test.\n");
1543 IDirectDraw2_Release(ddraw
);
1544 DestroyWindow(window
);
1548 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1549 viewport
= create_viewport(device
, 0, 0, 640, 480);
1550 viewport_set_background(device
, viewport
, background
);
1551 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1552 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1554 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1555 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1557 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1558 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1559 hr
= IDirect3DDevice2_BeginScene(device
);
1560 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1561 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, tquad
, 4, 0);
1562 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1563 hr
= IDirect3DDevice2_EndScene(device
);
1564 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1566 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1567 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1568 for (i
= 0; i
< 4; ++i
)
1570 for (j
= 0; j
< 4; ++j
)
1572 x
= 80 * ((2 * j
) + 1);
1573 y
= 60 * ((2 * i
) + 1);
1574 color
= get_surface_color(rt
, x
, y
);
1575 ok(compare_color(color
, 0x0000ff00, 1),
1576 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1579 IDirectDrawSurface_Release(rt
);
1581 destroy_viewport(device
, viewport
);
1582 destroy_material(background
);
1583 IDirect3DDevice2_Release(device
);
1584 IDirectDraw2_Release(ddraw
);
1585 DestroyWindow(window
);
1588 static void test_ck_rgba(void)
1590 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1591 static D3DTLVERTEX tquad
[] =
1593 {{ 0.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1594 {{ 0.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1595 {{640.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1596 {{640.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1597 {{ 0.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1598 {{ 0.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1599 {{640.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1600 {{640.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1604 D3DCOLOR fill_color
;
1607 D3DCOLOR result1
, result1_broken
;
1608 D3DCOLOR result2
, result2_broken
;
1612 /* r200 on Windows doesn't check the alpha component when applying the color
1613 * key, so the key matches on every texel. */
1614 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1615 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1616 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1617 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1618 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1619 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1620 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1621 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1624 D3DTEXTUREHANDLE texture_handle
;
1625 IDirect3DMaterial2
*background
;
1626 IDirectDrawSurface
*surface
;
1627 IDirect3DViewport2
*viewport
;
1628 IDirect3DTexture2
*texture
;
1629 DDSURFACEDESC surface_desc
;
1630 IDirect3DDevice2
*device
;
1631 IDirectDrawSurface
*rt
;
1632 IDirectDraw2
*ddraw
;
1639 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1640 0, 0, 640, 480, 0, 0, 0, 0);
1641 ddraw
= create_ddraw();
1642 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1643 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1645 skip("Failed to create a 3D device, skipping test.\n");
1646 IDirectDraw2_Release(ddraw
);
1647 DestroyWindow(window
);
1651 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1652 viewport
= create_viewport(device
, 0, 0, 640, 480);
1653 viewport_set_background(device
, viewport
, background
);
1654 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1655 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1657 memset(&surface_desc
, 0, sizeof(surface_desc
));
1658 surface_desc
.dwSize
= sizeof(surface_desc
);
1659 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1660 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1661 surface_desc
.dwWidth
= 256;
1662 surface_desc
.dwHeight
= 256;
1663 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1664 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1665 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1666 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1667 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1668 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1669 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1670 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1671 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1672 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1673 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1674 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1675 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1676 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
1677 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1678 IDirect3DTexture2_Release(texture
);
1680 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1681 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1682 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1683 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1684 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1685 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1687 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1688 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1690 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1692 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1693 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1694 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1695 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1697 memset(&fx
, 0, sizeof(fx
));
1698 fx
.dwSize
= sizeof(fx
);
1699 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1700 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1701 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1703 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
1704 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1705 hr
= IDirect3DDevice2_BeginScene(device
);
1706 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1707 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1708 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1709 hr
= IDirect3DDevice2_EndScene(device
);
1710 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1712 color
= get_surface_color(rt
, 320, 240);
1713 ok(compare_color(color
, tests
[i
].result1
, 1) || compare_color(color
, tests
[i
].result1_broken
, 1),
1714 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1715 tests
[i
].result1
, i
, color
);
1717 U5(fx
).dwFillColor
= 0xff0000ff;
1718 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1719 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1721 hr
= IDirect3DDevice2_BeginScene(device
);
1722 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1723 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[4], 4, 0);
1724 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1725 hr
= IDirect3DDevice2_EndScene(device
);
1726 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1728 /* This tests that fragments that are masked out by the color key are
1729 * discarded, instead of just fully transparent. */
1730 color
= get_surface_color(rt
, 320, 240);
1731 ok(compare_color(color
, tests
[i
].result2
, 1) || compare_color(color
, tests
[i
].result2_broken
, 1),
1732 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1733 tests
[i
].result2
, i
, color
);
1736 IDirectDrawSurface_Release(rt
);
1737 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1738 ok(SUCCEEDED(hr
), "Failed to unset texture, hr %#x.\n", hr
);
1739 IDirectDrawSurface_Release(surface
);
1740 destroy_viewport(device
, viewport
);
1741 destroy_material(background
);
1742 IDirect3DDevice2_Release(device
);
1743 IDirectDraw2_Release(ddraw
);
1744 DestroyWindow(window
);
1747 static void test_ck_default(void)
1749 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1750 static D3DTLVERTEX tquad
[] =
1752 {{ 0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1753 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1754 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1755 {{640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1757 IDirectDrawSurface
*surface
, *rt
;
1758 D3DTEXTUREHANDLE texture_handle
;
1759 IDirect3DMaterial2
*background
;
1760 IDirect3DViewport2
*viewport
;
1761 DDSURFACEDESC surface_desc
;
1762 IDirect3DTexture2
*texture
;
1763 IDirect3DDevice2
*device
;
1764 IDirectDraw2
*ddraw
;
1771 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1772 0, 0, 640, 480, 0, 0, 0, 0);
1773 ddraw
= create_ddraw();
1774 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1775 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1777 skip("Failed to create a 3D device, skipping test.\n");
1778 IDirectDraw2_Release(ddraw
);
1779 DestroyWindow(window
);
1783 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1784 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1786 background
= create_diffuse_material(device
, 0.0, 1.0f
, 0.0f
, 1.0f
);
1787 viewport
= create_viewport(device
, 0, 0, 640, 480);
1788 viewport_set_background(device
, viewport
, background
);
1789 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1790 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1792 memset(&surface_desc
, 0, sizeof(surface_desc
));
1793 surface_desc
.dwSize
= sizeof(surface_desc
);
1794 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1795 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1796 surface_desc
.dwWidth
= 256;
1797 surface_desc
.dwHeight
= 256;
1798 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1799 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1800 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1801 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1802 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1803 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1804 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1805 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1806 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1807 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1808 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1809 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1810 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
1811 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1812 IDirect3DTexture_Release(texture
);
1814 memset(&fx
, 0, sizeof(fx
));
1815 fx
.dwSize
= sizeof(fx
);
1816 U5(fx
).dwFillColor
= 0x000000ff;
1817 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1818 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1820 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1821 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1822 hr
= IDirect3DDevice2_BeginScene(device
);
1823 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1824 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1825 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
1826 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1827 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1828 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1829 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1830 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1831 hr
= IDirect3DDevice2_EndScene(device
);
1832 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1833 color
= get_surface_color(rt
, 320, 240);
1834 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1836 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1837 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1838 hr
= IDirect3DDevice2_BeginScene(device
);
1839 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1840 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1841 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1842 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1843 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1844 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1845 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1846 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1847 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1848 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
1849 hr
= IDirect3DDevice2_EndScene(device
);
1850 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1851 color
= get_surface_color(rt
, 320, 240);
1852 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1854 IDirectDrawSurface_Release(surface
);
1855 destroy_viewport(device
, viewport
);
1856 destroy_material(background
);
1857 IDirectDrawSurface_Release(rt
);
1858 IDirect3DDevice2_Release(device
);
1859 IDirectDraw2_Release(ddraw
);
1860 DestroyWindow(window
);
1863 static void test_ck_complex(void)
1865 IDirectDrawSurface
*surface
, *mipmap
, *tmp
;
1866 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
1867 DDSURFACEDESC surface_desc
;
1868 IDirect3DDevice2
*device
;
1869 DDCOLORKEY color_key
;
1870 IDirectDraw2
*ddraw
;
1876 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1877 0, 0, 640, 480, 0, 0, 0, 0);
1878 ddraw
= create_ddraw();
1879 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1880 if (!(device
= create_device(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1882 skip("Failed to create a 3D device, skipping test.\n");
1883 DestroyWindow(window
);
1884 IDirectDraw2_Release(ddraw
);
1887 IDirect3DDevice2_Release(device
);
1889 memset(&surface_desc
, 0, sizeof(surface_desc
));
1890 surface_desc
.dwSize
= sizeof(surface_desc
);
1891 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1892 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1893 surface_desc
.dwWidth
= 128;
1894 surface_desc
.dwHeight
= 128;
1895 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1896 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1898 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1899 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1900 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1901 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1902 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1903 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1904 memset(&color_key
, 0, sizeof(color_key
));
1905 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1906 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1907 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1908 color_key
.dwColorSpaceLowValue
);
1909 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1910 color_key
.dwColorSpaceHighValue
);
1913 IDirectDrawSurface_AddRef(mipmap
);
1914 for (i
= 0; i
< 7; ++i
)
1916 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1917 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1919 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1920 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1921 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1922 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1923 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1924 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x, i %u.\n", hr
, i
);
1925 memset(&color_key
, 0, sizeof(color_key
));
1926 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1927 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x, i %u.\n", hr
, i
);
1928 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1929 color_key
.dwColorSpaceLowValue
, i
);
1930 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1931 color_key
.dwColorSpaceHighValue
, i
);
1933 IDirectDrawSurface_Release(mipmap
);
1937 memset(&color_key
, 0, sizeof(color_key
));
1938 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1939 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1940 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1941 color_key
.dwColorSpaceLowValue
);
1942 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1943 color_key
.dwColorSpaceHighValue
);
1945 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1946 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1947 IDirectDrawSurface_Release(mipmap
);
1948 refcount
= IDirectDrawSurface_Release(surface
);
1949 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1951 memset(&surface_desc
, 0, sizeof(surface_desc
));
1952 surface_desc
.dwSize
= sizeof(surface_desc
);
1953 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1954 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1955 surface_desc
.dwBackBufferCount
= 1;
1956 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1957 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1959 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1960 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1961 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1962 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1963 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1964 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1965 memset(&color_key
, 0, sizeof(color_key
));
1966 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1967 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1968 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1969 color_key
.dwColorSpaceLowValue
);
1970 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1971 color_key
.dwColorSpaceHighValue
);
1973 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
1974 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
1976 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1977 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1978 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1979 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1980 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1981 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1982 memset(&color_key
, 0, sizeof(color_key
));
1983 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1984 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1985 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1986 color_key
.dwColorSpaceLowValue
);
1987 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1988 color_key
.dwColorSpaceHighValue
);
1990 IDirectDrawSurface_Release(tmp
);
1992 refcount
= IDirectDrawSurface_Release(surface
);
1993 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1994 refcount
= IDirectDraw2_Release(ddraw
);
1995 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1996 DestroyWindow(window
);
2002 REFIID refcount_iid
;
2006 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
2007 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
2009 ULONG refcount
, expected_refcount
;
2010 IUnknown
*iface1
, *iface2
;
2014 for (i
= 0; i
< entry_count
; ++i
)
2016 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
2017 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
2020 for (j
= 0; j
< entry_count
; ++j
)
2022 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
2023 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
2026 expected_refcount
= 0;
2027 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
2028 ++expected_refcount
;
2029 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
2030 ++expected_refcount
;
2031 refcount
= IUnknown_Release(iface2
);
2032 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2033 refcount
, test_name
, i
, j
, expected_refcount
);
2037 expected_refcount
= 0;
2038 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
2039 ++expected_refcount
;
2040 refcount
= IUnknown_Release(iface1
);
2041 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2042 refcount
, test_name
, i
, expected_refcount
);
2047 static void test_surface_qi(void)
2049 static const struct qi_test tests
[] =
2051 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface
, S_OK
},
2052 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface
, S_OK
},
2053 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
2054 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2055 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
2056 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
2057 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
2058 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
2059 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
2060 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
2061 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
2062 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
2063 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
2064 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
2065 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
2066 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
2067 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
2068 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
2069 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
2070 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
2071 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
2072 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
2073 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
2074 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
2075 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
2076 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
2077 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
2078 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
2079 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
2080 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
2081 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
2082 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
2083 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
2084 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
2085 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
2088 IDirectDrawSurface
*surface
;
2089 DDSURFACEDESC surface_desc
;
2090 IDirect3DDevice2
*device
;
2091 IDirectDraw2
*ddraw
;
2095 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2097 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2101 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2102 0, 0, 640, 480, 0, 0, 0, 0);
2103 ddraw
= create_ddraw();
2104 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2105 /* Try to create a D3D device to see if the ddraw implementation supports
2106 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2107 * doesn't support e.g. the IDirect3DTexture interfaces. */
2108 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
2110 skip("Failed to create a 3D device, skipping test.\n");
2111 IDirectDraw2_Release(ddraw
);
2112 DestroyWindow(window
);
2115 IDirect3DDevice_Release(device
);
2117 memset(&surface_desc
, 0, sizeof(surface_desc
));
2118 surface_desc
.dwSize
= sizeof(surface_desc
);
2119 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2120 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2121 surface_desc
.dwWidth
= 512;
2122 surface_desc
.dwHeight
= 512;
2123 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, (IDirectDrawSurface
**)0xdeadbeef, NULL
);
2124 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
2125 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2126 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2128 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface
, tests
, sizeof(tests
) / sizeof(*tests
));
2130 IDirectDrawSurface_Release(surface
);
2131 IDirectDraw2_Release(ddraw
);
2132 DestroyWindow(window
);
2135 static void test_device_qi(void)
2137 static const struct qi_test tests
[] =
2139 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
2140 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
2141 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
2142 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2143 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
2144 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
2145 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
2146 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
2147 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
2148 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
2149 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
2150 {&IID_IDirect3DDevice2
, &IID_IDirect3DDevice2
, S_OK
},
2151 {&IID_IDirect3DDevice
, &IID_IDirect3DDevice2
, S_OK
},
2152 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
2153 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
2154 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
2155 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
2156 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
2157 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
2158 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
2159 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
2160 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
2161 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
2162 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
2163 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
2164 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
2165 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
2166 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
2167 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
2168 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
2169 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
2170 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
2171 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
2172 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
2173 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
2174 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
2175 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
2176 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
2177 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
2178 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
2179 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
2180 {&IID_IUnknown
, &IID_IDirect3DDevice2
, S_OK
},
2183 IDirect3DDevice2
*device
;
2184 IDirectDraw2
*ddraw
;
2187 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2188 0, 0, 640, 480, 0, 0, 0, 0);
2189 ddraw
= create_ddraw();
2190 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2191 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
2193 skip("Failed to create a 3D device, skipping test.\n");
2194 IDirectDraw2_Release(ddraw
);
2195 DestroyWindow(window
);
2199 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice2
, tests
, sizeof(tests
) / sizeof(*tests
));
2201 IDirect3DDevice2_Release(device
);
2202 IDirectDraw2_Release(ddraw
);
2203 DestroyWindow(window
);
2206 static void test_wndproc(void)
2208 LONG_PTR proc
, ddraw_proc
;
2209 IDirectDraw2
*ddraw
;
2215 static struct message messages
[] =
2217 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2218 {WM_MOVE
, FALSE
, 0},
2219 {WM_SIZE
, FALSE
, 0},
2220 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2221 {WM_ACTIVATE
, FALSE
, 0},
2222 {WM_SETFOCUS
, FALSE
, 0},
2226 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2227 ddraw
= create_ddraw();
2228 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2230 wc
.lpfnWndProc
= test_proc
;
2231 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2232 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2234 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2235 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2237 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2238 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2239 (LONG_PTR
)test_proc
, proc
);
2240 expect_messages
= messages
;
2241 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2242 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2243 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2244 expect_messages
= NULL
;
2245 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2246 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2247 (LONG_PTR
)test_proc
, proc
);
2248 ref
= IDirectDraw2_Release(ddraw
);
2249 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2250 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2251 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2252 (LONG_PTR
)test_proc
, proc
);
2254 /* DDSCL_NORMAL doesn't. */
2255 ddraw
= create_ddraw();
2256 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2257 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2258 (LONG_PTR
)test_proc
, proc
);
2259 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2260 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2261 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2262 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2263 (LONG_PTR
)test_proc
, proc
);
2264 ref
= IDirectDraw2_Release(ddraw
);
2265 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2266 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2267 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2268 (LONG_PTR
)test_proc
, proc
);
2270 /* The original window proc is only restored by ddraw if the current
2271 * window proc matches the one ddraw set. This also affects switching
2272 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2273 ddraw
= create_ddraw();
2274 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2275 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2276 (LONG_PTR
)test_proc
, proc
);
2277 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2278 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2279 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2280 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2281 (LONG_PTR
)test_proc
, proc
);
2283 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2284 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2285 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2286 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2287 (LONG_PTR
)test_proc
, proc
);
2288 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2289 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2290 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2291 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2292 (LONG_PTR
)test_proc
, proc
);
2293 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2294 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2295 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2296 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2297 (LONG_PTR
)DefWindowProcA
, proc
);
2298 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2299 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2300 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2301 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2302 (LONG_PTR
)DefWindowProcA
, proc
);
2303 ref
= IDirectDraw2_Release(ddraw
);
2304 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2305 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2306 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2307 (LONG_PTR
)test_proc
, proc
);
2309 ddraw
= create_ddraw();
2310 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2311 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2312 (LONG_PTR
)test_proc
, proc
);
2313 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2314 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2315 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2316 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2317 (LONG_PTR
)test_proc
, proc
);
2318 ref
= IDirectDraw2_Release(ddraw
);
2319 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2320 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2321 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2322 (LONG_PTR
)DefWindowProcA
, proc
);
2324 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2325 expect_messages
= NULL
;
2326 DestroyWindow(window
);
2327 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2330 static void test_window_style(void)
2332 LONG style
, exstyle
, tmp
, expected_style
;
2333 RECT fullscreen_rect
, r
;
2334 IDirectDraw2
*ddraw
;
2340 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2341 0, 0, 100, 100, 0, 0, 0, 0);
2342 ddraw
= create_ddraw();
2343 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2345 style
= GetWindowLongA(window
, GWL_STYLE
);
2346 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2347 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2349 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2350 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2352 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2353 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2354 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2355 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2357 GetWindowRect(window
, &r
);
2358 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
2359 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
2360 GetClientRect(window
, &r
);
2361 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2363 ret
= SetForegroundWindow(GetDesktopWindow());
2364 ok(ret
, "Failed to set foreground window.\n");
2366 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2367 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2368 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2369 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2371 ret
= SetForegroundWindow(window
);
2372 ok(ret
, "Failed to set foreground window.\n");
2373 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2374 * the next tests expect this. */
2375 ShowWindow(window
, SW_HIDE
);
2377 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2378 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2380 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2381 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2382 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2383 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2385 ShowWindow(window
, SW_SHOW
);
2386 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2387 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2389 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2390 expected_style
= style
| WS_VISIBLE
;
2391 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2392 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2393 expected_style
= exstyle
| WS_EX_TOPMOST
;
2394 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2396 ret
= SetForegroundWindow(GetDesktopWindow());
2397 ok(ret
, "Failed to set foreground window.\n");
2398 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2399 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2400 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2401 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2402 expected_style
= exstyle
| WS_EX_TOPMOST
;
2403 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2405 ref
= IDirectDraw2_Release(ddraw
);
2406 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2408 DestroyWindow(window
);
2411 static void test_redundant_mode_set(void)
2413 DDSURFACEDESC surface_desc
= {0};
2414 IDirectDraw2
*ddraw
;
2420 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2421 0, 0, 100, 100, 0, 0, 0, 0);
2422 ddraw
= create_ddraw();
2423 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2425 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2426 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2428 surface_desc
.dwSize
= sizeof(surface_desc
);
2429 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
2430 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
2432 hr
= IDirectDraw2_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2433 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2434 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2436 GetWindowRect(window
, &r
);
2439 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2440 GetWindowRect(window
, &s
);
2441 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2443 hr
= IDirectDraw2_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2444 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2445 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2447 GetWindowRect(window
, &s
);
2448 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2450 ref
= IDirectDraw2_Release(ddraw
);
2451 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2453 DestroyWindow(window
);
2456 static SIZE screen_size
, screen_size2
;
2458 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2460 if (message
== WM_SIZE
)
2462 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2463 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2466 return test_proc(hwnd
, message
, wparam
, lparam
);
2469 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2471 if (message
== WM_SIZE
)
2473 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2474 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2477 return test_proc(hwnd
, message
, wparam
, lparam
);
2480 struct test_coop_level_mode_set_enum_param
2482 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2485 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC
*surface_desc
, void *context
)
2487 struct test_coop_level_mode_set_enum_param
*param
= context
;
2489 if (U1(surface_desc
->ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2490 return DDENUMRET_OK
;
2491 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2492 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2493 return DDENUMRET_OK
;
2495 if (!param
->ddraw_width
)
2497 param
->ddraw_width
= surface_desc
->dwWidth
;
2498 param
->ddraw_height
= surface_desc
->dwHeight
;
2499 return DDENUMRET_OK
;
2501 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2502 return DDENUMRET_OK
;
2504 param
->user32_width
= surface_desc
->dwWidth
;
2505 param
->user32_height
= surface_desc
->dwHeight
;
2506 return DDENUMRET_CANCEL
;
2509 static void test_coop_level_mode_set(void)
2511 IDirectDrawSurface
*primary
;
2512 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2513 IDirectDraw2
*ddraw
;
2516 HWND window
, window2
;
2520 struct test_coop_level_mode_set_enum_param param
;
2525 static const struct message exclusive_messages
[] =
2527 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2528 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2529 {WM_SIZE
, FALSE
, 0},
2530 {WM_DISPLAYCHANGE
, FALSE
, 0},
2533 static const struct message exclusive_focus_loss_messages
[] =
2535 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2536 {WM_DISPLAYCHANGE
, FALSE
, 0},
2537 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2538 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2539 * SW_MINIMIZED, causing a recursive window activation that does not
2540 * produce the same result in Wine yet. Ignore the difference for now.
2541 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2542 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2543 {WM_MOVE
, FALSE
, 0},
2544 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2545 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2548 static const struct message exclusive_focus_restore_messages
[] =
2550 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2551 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2552 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2553 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2554 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2555 /* Native redundantly sets the window size here. */
2556 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2557 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2558 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2559 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2562 static const struct message sc_restore_messages
[] =
2564 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2565 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2566 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2567 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2570 static const struct message sc_minimize_messages
[] =
2572 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2573 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2574 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2575 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2578 static const struct message sc_maximize_messages
[] =
2580 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2581 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2582 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2583 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2587 static const struct message normal_messages
[] =
2589 {WM_DISPLAYCHANGE
, FALSE
, 0},
2593 ddraw
= create_ddraw();
2594 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2596 memset(¶m
, 0, sizeof(param
));
2597 hr
= IDirectDraw2_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2598 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2599 ref
= IDirectDraw2_Release(ddraw
);
2600 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2602 if (!param
.user32_height
)
2604 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2608 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2609 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2610 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2612 memset(&devmode
, 0, sizeof(devmode
));
2613 devmode
.dmSize
= sizeof(devmode
);
2614 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2615 devmode
.dmPelsWidth
= param
.user32_width
;
2616 devmode
.dmPelsHeight
= param
.user32_height
;
2617 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2618 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2620 ddraw
= create_ddraw();
2621 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2623 wc
.lpfnWndProc
= mode_set_proc
;
2624 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2625 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2626 wc
.lpfnWndProc
= mode_set_proc2
;
2627 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2628 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2630 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2631 0, 0, 100, 100, 0, 0, 0, 0);
2632 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2633 0, 0, 100, 100, 0, 0, 0, 0);
2635 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2636 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2638 GetWindowRect(window
, &r
);
2639 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2640 wine_dbgstr_rect(&r
));
2642 memset(&ddsd
, 0, sizeof(ddsd
));
2643 ddsd
.dwSize
= sizeof(ddsd
);
2644 ddsd
.dwFlags
= DDSD_CAPS
;
2645 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2647 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2648 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2649 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2650 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2651 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2652 param
.user32_width
, ddsd
.dwWidth
);
2653 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2654 param
.user32_height
, ddsd
.dwHeight
);
2656 GetWindowRect(window
, &r
);
2657 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2658 wine_dbgstr_rect(&r
));
2660 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2661 expect_messages
= exclusive_messages
;
2665 hr
= IDirectDrawSurface_IsLost(primary
);
2666 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2667 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2668 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2669 hr
= IDirectDrawSurface_IsLost(primary
);
2670 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2672 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2673 expect_messages
= NULL
;
2674 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2675 "Expected screen size %ux%u, got %ux%u.\n",
2676 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2678 GetWindowRect(window
, &r
);
2679 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2680 wine_dbgstr_rect(&r
));
2682 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2683 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2684 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2685 param
.user32_width
, ddsd
.dwWidth
);
2686 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2687 param
.user32_height
, ddsd
.dwHeight
);
2688 IDirectDrawSurface_Release(primary
);
2690 memset(&ddsd
, 0, sizeof(ddsd
));
2691 ddsd
.dwSize
= sizeof(ddsd
);
2692 ddsd
.dwFlags
= DDSD_CAPS
;
2693 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2695 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2696 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2697 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2698 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2699 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2700 param
.ddraw_width
, ddsd
.dwWidth
);
2701 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2702 param
.ddraw_height
, ddsd
.dwHeight
);
2704 GetWindowRect(window
, &r
);
2705 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2706 wine_dbgstr_rect(&r
));
2708 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2709 expect_messages
= exclusive_messages
;
2713 hr
= IDirectDrawSurface_IsLost(primary
);
2714 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2715 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2716 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2717 hr
= IDirectDrawSurface_IsLost(primary
);
2718 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2720 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2721 expect_messages
= NULL
;
2722 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2723 "Expected screen size %ux%u, got %ux%u.\n",
2724 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2726 GetWindowRect(window
, &r
);
2727 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2728 wine_dbgstr_rect(&r
));
2730 expect_messages
= exclusive_focus_loss_messages
;
2731 ret
= SetForegroundWindow(GetDesktopWindow());
2732 ok(ret
, "Failed to set foreground window.\n");
2733 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2734 memset(&devmode
, 0, sizeof(devmode
));
2735 devmode
.dmSize
= sizeof(devmode
);
2736 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2737 ok(ret
, "Failed to get display mode.\n");
2738 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2739 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2740 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2742 expect_messages
= exclusive_focus_restore_messages
;
2743 ShowWindow(window
, SW_RESTORE
);
2744 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2746 GetWindowRect(window
, &r
);
2747 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2748 wine_dbgstr_rect(&r
));
2749 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2750 ok(ret
, "Failed to get display mode.\n");
2751 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2752 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2753 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2755 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2756 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2757 /* Normally the primary should be restored here. Unfortunately this causes the
2758 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2759 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2760 * the point of the GetSurfaceDesc call. */
2762 expect_messages
= sc_minimize_messages
;
2763 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2764 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2765 expect_messages
= NULL
;
2767 expect_messages
= sc_restore_messages
;
2768 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2769 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2770 expect_messages
= NULL
;
2772 expect_messages
= sc_maximize_messages
;
2773 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2774 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2775 expect_messages
= NULL
;
2777 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2778 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2780 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2781 expect_messages
= exclusive_messages
;
2785 hr
= IDirectDrawSurface_IsLost(primary
);
2786 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2787 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
2788 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2789 hr
= IDirectDrawSurface_IsLost(primary
);
2790 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2792 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2793 expect_messages
= NULL
;
2794 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2795 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2796 "Expected screen size %ux%u, got %ux%u.\n",
2797 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2799 GetWindowRect(window
, &r
);
2800 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2801 wine_dbgstr_rect(&r
));
2803 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2804 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2805 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2806 param
.ddraw_width
, ddsd
.dwWidth
);
2807 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2808 param
.ddraw_height
, ddsd
.dwHeight
);
2809 IDirectDrawSurface_Release(primary
);
2812 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2813 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2815 memset(&ddsd
, 0, sizeof(ddsd
));
2816 ddsd
.dwSize
= sizeof(ddsd
);
2817 ddsd
.dwFlags
= DDSD_CAPS
;
2818 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2820 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2821 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2822 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2823 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2824 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2825 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2826 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2827 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2829 GetWindowRect(window
, &r
);
2830 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2831 wine_dbgstr_rect(&r
));
2833 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2834 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2836 GetWindowRect(window
, &r
);
2837 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2838 wine_dbgstr_rect(&r
));
2840 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2841 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2842 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2843 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2844 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2845 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2846 IDirectDrawSurface_Release(primary
);
2848 memset(&ddsd
, 0, sizeof(ddsd
));
2849 ddsd
.dwSize
= sizeof(ddsd
);
2850 ddsd
.dwFlags
= DDSD_CAPS
;
2851 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2853 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2854 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2855 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2856 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2857 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2858 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2859 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2860 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2862 GetWindowRect(window
, &r
);
2863 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2864 wine_dbgstr_rect(&r
));
2866 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2867 expect_messages
= normal_messages
;
2871 hr
= IDirectDrawSurface_IsLost(primary
);
2872 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2873 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2874 devmode
.dmPelsWidth
= param
.user32_width
;
2875 devmode
.dmPelsHeight
= param
.user32_height
;
2876 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2877 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2878 hr
= IDirectDrawSurface_IsLost(primary
);
2879 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2881 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2882 expect_messages
= NULL
;
2883 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2885 GetWindowRect(window
, &r
);
2886 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2887 wine_dbgstr_rect(&r
));
2889 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2890 expect_messages
= normal_messages
;
2894 hr
= IDirectDrawSurface_Restore(primary
);
2895 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2896 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2897 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
2899 win_skip("Broken SetDisplayMode(), skipping remaining tests.\n");
2900 IDirectDrawSurface_Release(primary
);
2901 IDirectDraw2_Release(ddraw
);
2904 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2905 hr
= IDirectDrawSurface_Restore(primary
);
2906 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2907 hr
= IDirectDrawSurface_IsLost(primary
);
2908 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2910 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2911 expect_messages
= NULL
;
2912 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2914 GetWindowRect(window
, &r
);
2915 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2916 wine_dbgstr_rect(&r
));
2918 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2919 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2920 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2921 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2922 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2923 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2924 IDirectDrawSurface_Release(primary
);
2926 memset(&ddsd
, 0, sizeof(ddsd
));
2927 ddsd
.dwSize
= sizeof(ddsd
);
2928 ddsd
.dwFlags
= DDSD_CAPS
;
2929 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2931 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2932 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2933 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2934 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2935 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2936 param
.ddraw_width
, ddsd
.dwWidth
);
2937 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2938 param
.ddraw_height
, ddsd
.dwHeight
);
2940 GetWindowRect(window
, &r
);
2941 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2942 wine_dbgstr_rect(&r
));
2944 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2945 expect_messages
= normal_messages
;
2949 hr
= IDirectDrawSurface_IsLost(primary
);
2950 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2951 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2952 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2953 hr
= IDirectDrawSurface_IsLost(primary
);
2954 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2956 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2957 expect_messages
= NULL
;
2958 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2960 GetWindowRect(window
, &r
);
2961 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2962 wine_dbgstr_rect(&r
));
2964 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2965 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2966 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2967 param
.ddraw_width
, ddsd
.dwWidth
);
2968 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2969 param
.ddraw_height
, ddsd
.dwHeight
);
2970 IDirectDrawSurface_Release(primary
);
2972 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2973 ok(ret
, "Failed to get display mode.\n");
2974 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2975 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2976 "Expected resolution %ux%u, got %ux%u.\n",
2977 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2978 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2979 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2980 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2982 memset(&ddsd
, 0, sizeof(ddsd
));
2983 ddsd
.dwSize
= sizeof(ddsd
);
2984 ddsd
.dwFlags
= DDSD_CAPS
;
2985 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2987 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2988 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2989 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2990 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2991 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2992 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2993 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2994 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2996 GetWindowRect(window
, &r
);
2997 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2998 wine_dbgstr_rect(&r
));
3000 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
3001 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
3002 * not DDSCL_FULLSCREEN. */
3003 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3004 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3006 GetWindowRect(window
, &r
);
3007 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3008 wine_dbgstr_rect(&r
));
3010 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3011 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3012 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3013 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3014 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3015 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3016 IDirectDrawSurface_Release(primary
);
3018 memset(&ddsd
, 0, sizeof(ddsd
));
3019 ddsd
.dwSize
= sizeof(ddsd
);
3020 ddsd
.dwFlags
= DDSD_CAPS
;
3021 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3023 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3024 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3025 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3026 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3027 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3028 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3029 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3030 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
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 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3037 expect_messages
= normal_messages
;
3041 hr
= IDirectDrawSurface_IsLost(primary
);
3042 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3043 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
3044 devmode
.dmPelsWidth
= param
.user32_width
;
3045 devmode
.dmPelsHeight
= param
.user32_height
;
3046 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3047 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3048 hr
= IDirectDrawSurface_IsLost(primary
);
3049 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3051 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3052 expect_messages
= NULL
;
3053 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3055 GetWindowRect(window
, &r
);
3056 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3057 wine_dbgstr_rect(&r
));
3059 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3060 expect_messages
= normal_messages
;
3064 hr
= IDirectDrawSurface_Restore(primary
);
3065 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
3066 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3067 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3068 hr
= IDirectDrawSurface_Restore(primary
);
3069 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
3070 hr
= IDirectDrawSurface_IsLost(primary
);
3071 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3073 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3074 expect_messages
= NULL
;
3075 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3077 GetWindowRect(window
, &r
);
3078 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3079 wine_dbgstr_rect(&r
));
3081 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3082 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3083 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3084 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3085 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3086 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3087 IDirectDrawSurface_Release(primary
);
3089 memset(&ddsd
, 0, sizeof(ddsd
));
3090 ddsd
.dwSize
= sizeof(ddsd
);
3091 ddsd
.dwFlags
= DDSD_CAPS
;
3092 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3094 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3095 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3096 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3097 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3098 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3099 param
.ddraw_width
, ddsd
.dwWidth
);
3100 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3101 param
.ddraw_height
, ddsd
.dwHeight
);
3103 GetWindowRect(window
, &r
);
3104 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3105 wine_dbgstr_rect(&r
));
3107 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3108 expect_messages
= normal_messages
;
3112 hr
= IDirectDrawSurface_IsLost(primary
);
3113 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3114 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3115 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3116 hr
= IDirectDrawSurface_IsLost(primary
);
3117 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3119 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3120 expect_messages
= NULL
;
3121 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3123 GetWindowRect(window
, &r
);
3124 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3125 wine_dbgstr_rect(&r
));
3127 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3128 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3129 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3130 param
.ddraw_width
, ddsd
.dwWidth
);
3131 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3132 param
.ddraw_height
, ddsd
.dwHeight
);
3133 IDirectDrawSurface_Release(primary
);
3135 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3136 ok(ret
, "Failed to get display mode.\n");
3137 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3138 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3139 "Expected resolution %ux%u, got %ux%u.\n",
3140 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3141 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3142 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3143 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3145 memset(&ddsd
, 0, sizeof(ddsd
));
3146 ddsd
.dwSize
= sizeof(ddsd
);
3147 ddsd
.dwFlags
= DDSD_CAPS
;
3148 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3150 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3151 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3152 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3153 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3154 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3155 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3156 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3157 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3158 IDirectDrawSurface_Release(primary
);
3160 GetWindowRect(window
, &r
);
3161 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3162 wine_dbgstr_rect(&r
));
3164 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3165 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3166 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3167 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3168 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3170 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3171 expect_messages
= exclusive_messages
;
3175 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3176 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3178 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3179 expect_messages
= NULL
;
3180 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
3181 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
3182 "Expected screen size %ux%u, got %ux%u.\n",
3183 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3184 screen_size
.cx
, screen_size
.cy
);
3186 GetWindowRect(window
, &r
);
3187 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3188 wine_dbgstr_rect(&r
));
3190 memset(&ddsd
, 0, sizeof(ddsd
));
3191 ddsd
.dwSize
= sizeof(ddsd
);
3192 ddsd
.dwFlags
= DDSD_CAPS
;
3193 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3195 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3196 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3197 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3198 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3199 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3200 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3201 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3202 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3203 IDirectDrawSurface_Release(primary
);
3205 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3206 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3207 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3208 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3209 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3211 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3212 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3214 memset(&ddsd
, 0, sizeof(ddsd
));
3215 ddsd
.dwSize
= sizeof(ddsd
);
3216 ddsd
.dwFlags
= DDSD_CAPS
;
3217 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3219 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3220 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3221 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3222 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3223 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3224 param
.ddraw_width
, ddsd
.dwWidth
);
3225 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3226 param
.ddraw_height
, ddsd
.dwHeight
);
3227 IDirectDrawSurface_Release(primary
);
3229 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3230 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3232 /* If the window is changed at the same time, messages are sent to the new window. */
3233 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3234 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3235 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3236 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3238 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3239 expect_messages
= exclusive_messages
;
3242 screen_size2
.cx
= 0;
3243 screen_size2
.cy
= 0;
3245 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3246 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3248 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3249 expect_messages
= NULL
;
3250 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
3251 screen_size
.cx
, screen_size
.cy
);
3252 ok(screen_size2
.cx
== registry_mode
.dmPelsWidth
&& screen_size2
.cy
== registry_mode
.dmPelsHeight
,
3253 "Expected screen size 2 %ux%u, got %ux%u.\n",
3254 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size2
.cx
, screen_size2
.cy
);
3256 GetWindowRect(window
, &r
);
3257 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
3258 wine_dbgstr_rect(&r
));
3259 GetWindowRect(window2
, &r
);
3260 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3261 wine_dbgstr_rect(&r
));
3263 memset(&ddsd
, 0, sizeof(ddsd
));
3264 ddsd
.dwSize
= sizeof(ddsd
);
3265 ddsd
.dwFlags
= DDSD_CAPS
;
3266 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3268 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3269 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3270 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3271 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3272 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3273 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3274 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3275 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3276 IDirectDrawSurface_Release(primary
);
3278 ref
= IDirectDraw2_Release(ddraw
);
3279 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3281 GetWindowRect(window
, &r
);
3282 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
3283 wine_dbgstr_rect(&r
));
3286 expect_messages
= NULL
;
3287 DestroyWindow(window
);
3288 DestroyWindow(window2
);
3289 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3290 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3293 static void test_coop_level_mode_set_multi(void)
3295 IDirectDraw2
*ddraw1
, *ddraw2
;
3301 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3302 0, 0, 100, 100, 0, 0, 0, 0);
3303 ddraw1
= create_ddraw();
3304 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3306 /* With just a single ddraw object, the display mode is restored on
3308 hr
= set_display_mode(ddraw1
, 800, 600);
3309 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
3311 win_skip("Broken SetDisplayMode(), skipping test.\n");
3312 IDirectDraw2_Release(ddraw1
);
3313 DestroyWindow(window
);
3316 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3317 w
= GetSystemMetrics(SM_CXSCREEN
);
3318 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3319 h
= GetSystemMetrics(SM_CYSCREEN
);
3320 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3322 ref
= IDirectDraw2_Release(ddraw1
);
3323 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3324 w
= GetSystemMetrics(SM_CXSCREEN
);
3325 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3326 h
= GetSystemMetrics(SM_CYSCREEN
);
3327 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3329 /* When there are multiple ddraw objects, the display mode is restored to
3330 * the initial mode, before the first SetDisplayMode() call. */
3331 ddraw1
= create_ddraw();
3332 hr
= set_display_mode(ddraw1
, 800, 600);
3333 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3334 w
= GetSystemMetrics(SM_CXSCREEN
);
3335 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3336 h
= GetSystemMetrics(SM_CYSCREEN
);
3337 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3339 ddraw2
= create_ddraw();
3340 hr
= set_display_mode(ddraw2
, 640, 480);
3341 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3342 w
= GetSystemMetrics(SM_CXSCREEN
);
3343 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3344 h
= GetSystemMetrics(SM_CYSCREEN
);
3345 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3347 ref
= IDirectDraw2_Release(ddraw2
);
3348 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3349 w
= GetSystemMetrics(SM_CXSCREEN
);
3350 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3351 h
= GetSystemMetrics(SM_CYSCREEN
);
3352 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3354 ref
= IDirectDraw2_Release(ddraw1
);
3355 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3356 w
= GetSystemMetrics(SM_CXSCREEN
);
3357 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3358 h
= GetSystemMetrics(SM_CYSCREEN
);
3359 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3361 /* Regardless of release ordering. */
3362 ddraw1
= create_ddraw();
3363 hr
= set_display_mode(ddraw1
, 800, 600);
3364 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3365 w
= GetSystemMetrics(SM_CXSCREEN
);
3366 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3367 h
= GetSystemMetrics(SM_CYSCREEN
);
3368 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3370 ddraw2
= create_ddraw();
3371 hr
= set_display_mode(ddraw2
, 640, 480);
3372 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3373 w
= GetSystemMetrics(SM_CXSCREEN
);
3374 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3375 h
= GetSystemMetrics(SM_CYSCREEN
);
3376 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3378 ref
= IDirectDraw2_Release(ddraw1
);
3379 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3380 w
= GetSystemMetrics(SM_CXSCREEN
);
3381 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3382 h
= GetSystemMetrics(SM_CYSCREEN
);
3383 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3385 ref
= IDirectDraw2_Release(ddraw2
);
3386 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3387 w
= GetSystemMetrics(SM_CXSCREEN
);
3388 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3389 h
= GetSystemMetrics(SM_CYSCREEN
);
3390 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3392 /* But only for ddraw objects that called SetDisplayMode(). */
3393 ddraw1
= create_ddraw();
3394 ddraw2
= create_ddraw();
3395 hr
= set_display_mode(ddraw2
, 640, 480);
3396 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3397 w
= GetSystemMetrics(SM_CXSCREEN
);
3398 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3399 h
= GetSystemMetrics(SM_CYSCREEN
);
3400 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3402 ref
= IDirectDraw2_Release(ddraw1
);
3403 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3404 w
= GetSystemMetrics(SM_CXSCREEN
);
3405 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3406 h
= GetSystemMetrics(SM_CYSCREEN
);
3407 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3409 ref
= IDirectDraw2_Release(ddraw2
);
3410 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3411 w
= GetSystemMetrics(SM_CXSCREEN
);
3412 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3413 h
= GetSystemMetrics(SM_CYSCREEN
);
3414 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3416 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3417 * restoring the display mode. */
3418 ddraw1
= create_ddraw();
3419 hr
= set_display_mode(ddraw1
, 800, 600);
3420 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3421 w
= GetSystemMetrics(SM_CXSCREEN
);
3422 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3423 h
= GetSystemMetrics(SM_CYSCREEN
);
3424 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3426 ddraw2
= create_ddraw();
3427 hr
= set_display_mode(ddraw2
, 640, 480);
3428 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3429 w
= GetSystemMetrics(SM_CXSCREEN
);
3430 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3431 h
= GetSystemMetrics(SM_CYSCREEN
);
3432 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3434 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3435 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3437 ref
= IDirectDraw2_Release(ddraw1
);
3438 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3439 w
= GetSystemMetrics(SM_CXSCREEN
);
3440 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3441 h
= GetSystemMetrics(SM_CYSCREEN
);
3442 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3444 ref
= IDirectDraw2_Release(ddraw2
);
3445 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3446 w
= GetSystemMetrics(SM_CXSCREEN
);
3447 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3448 h
= GetSystemMetrics(SM_CYSCREEN
);
3449 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3451 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3452 ddraw1
= create_ddraw();
3453 hr
= set_display_mode(ddraw1
, 800, 600);
3454 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3455 w
= GetSystemMetrics(SM_CXSCREEN
);
3456 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3457 h
= GetSystemMetrics(SM_CYSCREEN
);
3458 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3460 hr
= IDirectDraw2_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3461 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3463 ddraw2
= create_ddraw();
3464 hr
= set_display_mode(ddraw2
, 640, 480);
3465 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3467 ref
= IDirectDraw2_Release(ddraw1
);
3468 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3469 w
= GetSystemMetrics(SM_CXSCREEN
);
3470 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3471 h
= GetSystemMetrics(SM_CYSCREEN
);
3472 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3474 ref
= IDirectDraw2_Release(ddraw2
);
3475 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3476 w
= GetSystemMetrics(SM_CXSCREEN
);
3477 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3478 h
= GetSystemMetrics(SM_CYSCREEN
);
3479 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3481 DestroyWindow(window
);
3484 static void test_initialize(void)
3486 IDirectDraw2
*ddraw
;
3489 ddraw
= create_ddraw();
3490 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3492 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3493 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3494 IDirectDraw2_Release(ddraw
);
3497 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw2
, (void **)&ddraw
);
3498 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw2 instance, hr %#x.\n", hr
);
3499 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3500 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3501 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3502 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3503 IDirectDraw2_Release(ddraw
);
3507 static void test_coop_level_surf_create(void)
3509 IDirectDrawSurface
*surface
;
3510 IDirectDraw2
*ddraw
;
3514 ddraw
= create_ddraw();
3515 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3517 memset(&ddsd
, 0, sizeof(ddsd
));
3518 ddsd
.dwSize
= sizeof(ddsd
);
3519 ddsd
.dwFlags
= DDSD_CAPS
;
3520 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3521 surface
= (void *)0xdeadbeef;
3522 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3523 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3524 ok(surface
== (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface
);
3526 IDirectDraw2_Release(ddraw
);
3529 static void test_coop_level_multi_window(void)
3531 HWND window1
, window2
;
3532 IDirectDraw2
*ddraw
;
3535 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3536 0, 0, 640, 480, 0, 0, 0, 0);
3537 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3538 0, 0, 640, 480, 0, 0, 0, 0);
3539 ddraw
= create_ddraw();
3540 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3542 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3543 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3544 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3545 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3546 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3547 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3549 IDirectDraw2_Release(ddraw
);
3550 DestroyWindow(window2
);
3551 DestroyWindow(window1
);
3554 static void test_clear_rect_count(void)
3556 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3557 IDirect3DMaterial2
*white
, *red
, *green
, *blue
;
3558 IDirect3DViewport2
*viewport
;
3559 IDirect3DDevice2
*device
;
3560 IDirectDrawSurface
*rt
;
3561 IDirectDraw2
*ddraw
;
3566 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3567 0, 0, 640, 480, 0, 0, 0, 0);
3568 ddraw
= create_ddraw();
3569 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3570 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3572 skip("Failed to create a 3D device, skipping test.\n");
3573 IDirectDraw2_Release(ddraw
);
3574 DestroyWindow(window
);
3578 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
3579 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3581 white
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
3582 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
3583 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
3584 blue
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
3586 viewport
= create_viewport(device
, 0, 0, 640, 480);
3587 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
3588 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3590 viewport_set_background(device
, viewport
, white
);
3591 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3592 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3593 viewport_set_background(device
, viewport
, red
);
3594 hr
= IDirect3DViewport2_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3595 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3596 viewport_set_background(device
, viewport
, green
);
3597 hr
= IDirect3DViewport2_Clear(viewport
, 0, NULL
, D3DCLEAR_TARGET
);
3598 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3599 viewport_set_background(device
, viewport
, blue
);
3600 hr
= IDirect3DViewport2_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3601 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3603 color
= get_surface_color(rt
, 320, 240);
3604 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x000000ff, 1)),
3605 "Got unexpected color 0x%08x.\n", color
);
3607 IDirectDrawSurface_Release(rt
);
3608 destroy_viewport(device
, viewport
);
3609 destroy_material(white
);
3610 destroy_material(red
);
3611 destroy_material(green
);
3612 destroy_material(blue
);
3613 IDirect3DDevice2_Release(device
);
3614 IDirectDraw2_Release(ddraw
);
3615 DestroyWindow(window
);
3618 static BOOL
test_mode_restored(IDirectDraw2
*ddraw
, HWND window
)
3620 DDSURFACEDESC ddsd1
, ddsd2
;
3623 memset(&ddsd1
, 0, sizeof(ddsd1
));
3624 ddsd1
.dwSize
= sizeof(ddsd1
);
3625 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &ddsd1
);
3626 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3628 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3629 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3630 hr
= set_display_mode(ddraw
, 640, 480);
3631 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3632 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3633 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3635 memset(&ddsd2
, 0, sizeof(ddsd2
));
3636 ddsd2
.dwSize
= sizeof(ddsd2
);
3637 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &ddsd2
);
3638 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3639 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3640 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3642 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
3645 static void test_coop_level_versions(void)
3651 IDirectDrawSurface
*surface
;
3652 IDirectDraw2
*ddraw2
;
3655 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3656 0, 0, 640, 480, 0, 0, 0, 0);
3658 ddraw2
= create_ddraw();
3659 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3660 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3661 restored
= test_mode_restored(ddraw2
, window
);
3662 ok(restored
, "Display mode not restored in new ddraw object\n");
3664 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3665 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3666 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3668 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3669 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3670 restored
= test_mode_restored(ddraw2
, window
);
3671 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3673 /* A successful one does */
3674 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3675 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3676 restored
= test_mode_restored(ddraw2
, window
);
3677 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3679 IDirectDraw_Release(ddraw
);
3680 IDirectDraw2_Release(ddraw2
);
3682 ddraw2
= create_ddraw();
3683 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3684 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3685 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3687 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
3688 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3689 restored
= test_mode_restored(ddraw2
, window
);
3690 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3692 IDirectDraw_Release(ddraw
);
3693 IDirectDraw2_Release(ddraw2
);
3695 /* A failing call does not restore the ddraw2+ behavior */
3696 ddraw2
= create_ddraw();
3697 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3698 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3699 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3701 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3702 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3703 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3704 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3705 restored
= test_mode_restored(ddraw2
, window
);
3706 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3708 IDirectDraw_Release(ddraw
);
3709 IDirectDraw2_Release(ddraw2
);
3711 /* Neither does a sequence of successful calls with the new interface */
3712 ddraw2
= create_ddraw();
3713 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3714 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3715 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3717 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3718 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3719 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3720 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3721 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_NORMAL
);
3722 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3724 restored
= test_mode_restored(ddraw2
, window
);
3725 ok(!restored
, "Display mode restored after ddraw1-ddraw2 SetCooperativeLevel() call sequence\n");
3726 IDirectDraw_Release(ddraw
);
3727 IDirectDraw2_Release(ddraw2
);
3729 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3730 ddraw2
= create_ddraw();
3731 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3732 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3733 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3735 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_NORMAL
);
3736 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3738 memset(&ddsd
, 0, sizeof(ddsd
));
3739 ddsd
.dwSize
= sizeof(ddsd
);
3740 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
3741 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
3742 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
3743 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3744 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
3745 IDirectDrawSurface_Release(surface
);
3746 restored
= test_mode_restored(ddraw2
, window
);
3747 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
3749 IDirectDraw_Release(ddraw
);
3750 IDirectDraw2_Release(ddraw2
);
3751 DestroyWindow(window
);
3754 static void test_lighting_interface_versions(void)
3756 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3757 IDirect3DMaterial2
*emissive
, *background
;
3758 IDirect3DViewport2
*viewport
;
3759 IDirect3DDevice2
*device
;
3760 IDirectDrawSurface
*rt
;
3761 IDirectDraw2
*ddraw
;
3765 D3DMATERIALHANDLE mat_handle
;
3769 static D3DVERTEX quad
[] =
3771 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3772 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3773 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3774 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3776 static D3DLVERTEX lquad
[] =
3778 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3779 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3780 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3781 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3783 static D3DTLVERTEX tlquad
[] =
3785 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3786 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3787 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3788 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3792 D3DVERTEXTYPE vertextype
;
3794 DWORD d3drs_lighting
, d3drs_specular
;
3800 /* Lighting is enabled when D3DVT_VERTEX is used and D3DDP_DONOTLIGHT is not
3801 * set. D3DVT_VERTEX has diffuse = 0xffffffff and specular = 0x00000000, as
3802 * in later d3d versions */
3803 { D3DVT_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x0000ff00},
3804 { D3DVT_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
3805 { D3DVT_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3806 { D3DVT_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3807 { D3DVT_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x0000ff00},
3808 { D3DVT_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
3809 { D3DVT_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3810 { D3DVT_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3812 { D3DVT_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
3813 { D3DVT_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x00ff0000},
3814 { D3DVT_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3815 { D3DVT_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3816 { D3DVT_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
3817 { D3DVT_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x00ff8080},
3818 { D3DVT_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3819 { D3DVT_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3821 { D3DVT_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
3822 { D3DVT_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
3823 { D3DVT_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3824 { D3DVT_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3825 { D3DVT_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
3826 { D3DVT_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
3827 { D3DVT_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3828 { D3DVT_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3831 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3832 0, 0, 640, 480, 0, 0, 0, 0);
3833 ddraw
= create_ddraw();
3834 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3835 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3837 skip("Failed to create a 3D device, skipping test.\n");
3838 IDirectDraw2_Release(ddraw
);
3839 DestroyWindow(window
);
3843 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
3844 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3846 viewport
= create_viewport(device
, 0, 0, 640, 480);
3847 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
3848 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3850 emissive
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
3851 hr
= IDirect3DMaterial2_GetHandle(emissive
, device
, &mat_handle
);
3852 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
3853 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
3854 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
3855 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
3856 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
3858 background
= create_diffuse_material(device
, 0.1f
, 0.1f
, 0.1f
, 0.1f
);
3859 viewport_set_background(device
, viewport
, background
);
3861 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
3862 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
3863 ok(rs
== TRUE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected TRUE.\n", rs
);
3865 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
3867 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3868 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3870 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
3871 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
3872 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
3873 tests
[i
].d3drs_specular
);
3874 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
3876 hr
= IDirect3DDevice2_BeginScene(device
);
3877 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3878 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
3879 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
3880 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3881 hr
= IDirect3DDevice2_EndScene(device
);
3882 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3884 color
= get_surface_color(rt
, 320, 240);
3885 ok(compare_color(color
, tests
[i
].color
, 1),
3886 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3887 color
, tests
[i
].color
, i
);
3890 destroy_material(background
);
3891 destroy_material(emissive
);
3892 IDirectDrawSurface_Release(rt
);
3893 IDirect3DDevice2_Release(device
);
3894 ref
= IDirectDraw2_Release(ddraw
);
3895 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
3896 DestroyWindow(window
);
3902 IDirectDraw2
*ddraw
;
3905 } activateapp_testdata
;
3907 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
3909 if (message
== WM_ACTIVATEAPP
)
3911 if (activateapp_testdata
.ddraw
)
3914 activateapp_testdata
.received
= FALSE
;
3915 hr
= IDirectDraw2_SetCooperativeLevel(activateapp_testdata
.ddraw
,
3916 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
3917 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
3918 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3920 activateapp_testdata
.received
= TRUE
;
3923 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
3926 static void test_coop_level_activateapp(void)
3928 IDirectDraw2
*ddraw
;
3933 IDirectDrawSurface
*surface
;
3935 ddraw
= create_ddraw();
3936 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3938 wc
.lpfnWndProc
= activateapp_test_proc
;
3939 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
3940 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3942 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3943 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3945 /* Exclusive with window already active. */
3946 SetForegroundWindow(window
);
3947 activateapp_testdata
.received
= FALSE
;
3948 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3949 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3950 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
3951 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3952 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3954 /* Exclusive with window not active. */
3955 SetForegroundWindow(GetDesktopWindow());
3956 activateapp_testdata
.received
= FALSE
;
3957 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3958 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3959 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3960 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3961 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3963 /* Normal with window not active, then exclusive with the same window. */
3964 SetForegroundWindow(GetDesktopWindow());
3965 activateapp_testdata
.received
= FALSE
;
3966 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3967 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3968 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3969 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3970 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3971 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3972 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3973 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3975 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3976 SetForegroundWindow(GetDesktopWindow());
3977 activateapp_testdata
.received
= FALSE
;
3978 activateapp_testdata
.ddraw
= ddraw
;
3979 activateapp_testdata
.window
= window
;
3980 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
3981 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3982 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3983 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3984 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3985 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3987 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3988 * succeeding. Another switch to exclusive and back to normal is needed to release the
3989 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3990 * WM_ACTIVATEAPP messages. */
3991 activateapp_testdata
.ddraw
= NULL
;
3992 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3993 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3994 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3995 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3997 /* Setting DDSCL_NORMAL with recursive invocation. */
3998 SetForegroundWindow(GetDesktopWindow());
3999 activateapp_testdata
.received
= FALSE
;
4000 activateapp_testdata
.ddraw
= ddraw
;
4001 activateapp_testdata
.window
= window
;
4002 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
4003 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4004 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4005 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4007 /* DDraw is in exclusive mode now. */
4008 memset(&ddsd
, 0, sizeof(ddsd
));
4009 ddsd
.dwSize
= sizeof(ddsd
);
4010 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4011 ddsd
.dwBackBufferCount
= 1;
4012 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4013 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4014 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4015 IDirectDrawSurface_Release(surface
);
4017 /* Recover again, just to be sure. */
4018 activateapp_testdata
.ddraw
= NULL
;
4019 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4020 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4021 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4022 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4024 DestroyWindow(window
);
4025 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
4026 IDirectDraw2_Release(ddraw
);
4029 struct format_support_check
4031 const DDPIXELFORMAT
*format
;
4035 static HRESULT WINAPI
test_unsupported_formats_cb(DDSURFACEDESC
*desc
, void *ctx
)
4037 struct format_support_check
*format
= ctx
;
4039 if (!memcmp(format
->format
, &desc
->ddpfPixelFormat
, sizeof(*format
->format
)))
4041 format
->supported
= TRUE
;
4042 return DDENUMRET_CANCEL
;
4045 return DDENUMRET_OK
;
4048 static void test_unsupported_formats(void)
4051 BOOL expect_success
;
4053 IDirectDraw2
*ddraw
;
4054 IDirect3DDevice2
*device
;
4055 IDirectDrawSurface
*surface
;
4058 DWORD expected_caps
;
4069 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
4070 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
4076 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4077 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
4081 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
4083 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4084 0, 0, 640, 480, 0, 0, 0, 0);
4085 ddraw
= create_ddraw();
4086 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4087 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4089 skip("Failed to create a 3D device, skipping test.\n");
4090 IDirectDraw2_Release(ddraw
);
4091 DestroyWindow(window
);
4095 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
4097 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
4098 hr
= IDirect3DDevice2_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
4099 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4101 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
4103 memset(&ddsd
, 0, sizeof(ddsd
));
4104 ddsd
.dwSize
= sizeof(ddsd
);
4105 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
4106 ddsd
.ddpfPixelFormat
= formats
[i
].fmt
;
4109 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
4111 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
4112 expect_success
= FALSE
;
4114 expect_success
= TRUE
;
4116 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4117 ok(SUCCEEDED(hr
) == expect_success
,
4118 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4119 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
4123 memset(&ddsd
, 0, sizeof(ddsd
));
4124 ddsd
.dwSize
= sizeof(ddsd
);
4125 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &ddsd
);
4126 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4128 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
4129 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4130 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
4131 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4132 else if (check
.supported
)
4133 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4135 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4137 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
4138 "Expected capability %#x, format %s, input cap %#x.\n",
4139 expected_caps
, formats
[i
].name
, caps
[j
]);
4141 IDirectDrawSurface_Release(surface
);
4145 IDirect3DDevice2_Release(device
);
4146 IDirectDraw2_Release(ddraw
);
4147 DestroyWindow(window
);
4150 static void test_rt_caps(void)
4152 PALETTEENTRY palette_entries
[256];
4153 IDirectDrawPalette
*palette
;
4154 IDirect3DDevice2
*device
;
4155 IDirectDraw2
*ddraw
;
4163 static const DDPIXELFORMAT p8_fmt
=
4165 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4166 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4171 const DDPIXELFORMAT
*pf
;
4174 HRESULT create_device_hr
;
4176 HRESULT alternative_set_rt_hr
;
4177 BOOL create_may_fail
;
4183 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4184 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4192 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4193 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4201 DDSCAPS_OFFSCREENPLAIN
,
4202 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4210 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4211 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4212 D3DERR_SURFACENOTINVIDMEM
,
4219 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4220 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4228 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4229 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4238 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4247 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4255 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4256 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4257 D3DERR_SURFACENOTINVIDMEM
,
4264 DDSCAPS_SYSTEMMEMORY
,
4265 DDSCAPS_SYSTEMMEMORY
,
4274 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4282 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4284 DDERR_NOPALETTEATTACHED
,
4291 DDSCAPS_OFFSCREENPLAIN
,
4292 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4300 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4301 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4302 DDERR_NOPALETTEATTACHED
,
4309 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4310 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4318 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
4319 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4321 DDERR_INVALIDPIXELFORMAT
,
4323 TRUE
/* AMD Evergreen */,
4327 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4328 ~0U /* AMD Evergreen */,
4330 DDERR_INVALIDPIXELFORMAT
,
4337 ~0U /* AMD Evergreen */,
4345 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4346 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4348 DDERR_INVALIDPIXELFORMAT
,
4349 DDERR_INVALIDPIXELFORMAT
,
4350 TRUE
/* Nvidia Kepler */,
4354 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4355 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4359 TRUE
/* Nvidia Kepler */,
4363 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4364 0, 0, 640, 480, 0, 0, 0, 0);
4365 ddraw
= create_ddraw();
4366 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4367 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4369 skip("Failed to create a 3D device, skipping test.\n");
4370 IDirectDraw2_Release(ddraw
);
4371 DestroyWindow(window
);
4374 z_depth
= get_device_z_depth(device
);
4375 ok(!!z_depth
, "Failed to get device z depth.\n");
4376 IDirect3DDevice2_Release(device
);
4378 if (FAILED(IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
)))
4380 skip("D3D interface is not available, skipping test.\n");
4384 memset(palette_entries
, 0, sizeof(palette_entries
));
4385 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
4386 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
4388 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4390 IDirectDrawSurface
*surface
, *rt
, *expected_rt
, *tmp
;
4391 DDSURFACEDESC surface_desc
;
4392 IDirect3DDevice2
*device
;
4394 memset(&surface_desc
, 0, sizeof(surface_desc
));
4395 surface_desc
.dwSize
= sizeof(surface_desc
);
4396 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4397 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4398 if (test_data
[i
].pf
)
4400 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4401 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
4403 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
4405 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4406 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
4408 surface_desc
.dwWidth
= 640;
4409 surface_desc
.dwHeight
= 480;
4410 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4411 ok(SUCCEEDED(hr
) || broken(test_data
[i
].create_may_fail
),
4412 "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4413 i
, test_data
[i
].caps_in
, hr
);
4417 memset(&surface_desc
, 0, sizeof(surface_desc
));
4418 surface_desc
.dwSize
= sizeof(surface_desc
);
4419 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4420 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4421 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
4422 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4423 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4425 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4426 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4427 i
, hr
, test_data
[i
].create_device_hr
);
4430 if (hr
== DDERR_NOPALETTEATTACHED
)
4432 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
4433 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
4434 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4435 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
4436 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4438 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4440 IDirectDrawSurface_Release(surface
);
4442 memset(&surface_desc
, 0, sizeof(surface_desc
));
4443 surface_desc
.dwSize
= sizeof(surface_desc
);
4444 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4445 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
4446 surface_desc
.dwWidth
= 640;
4447 surface_desc
.dwHeight
= 480;
4448 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4449 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
4451 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4452 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
4455 memset(&surface_desc
, 0, sizeof(surface_desc
));
4456 surface_desc
.dwSize
= sizeof(surface_desc
);
4457 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4458 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4459 if (test_data
[i
].pf
)
4461 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4462 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
4464 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
4466 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4467 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
4469 surface_desc
.dwWidth
= 640;
4470 surface_desc
.dwHeight
= 480;
4471 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
4472 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4473 i
, test_data
[i
].caps_in
, hr
);
4475 hr
= IDirect3DDevice2_SetRenderTarget(device
, rt
, 0);
4476 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
4477 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4478 i
, hr
, test_data
[i
].set_rt_hr
);
4479 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
4482 expected_rt
= surface
;
4484 /* It appears the surface is set as render target in this case, but no
4485 * reference is taken. */
4486 if (hr
== DDERR_INVALIDPIXELFORMAT
)
4488 refcount
= IDirectDrawSurface_AddRef(rt
);
4489 ok(refcount
== 2, "Test %u: Got unexpected refcount %u.\n", i
, refcount
);
4492 hr
= IDirect3DDevice2_GetRenderTarget(device
, &tmp
);
4493 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
4494 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
4496 IDirectDrawSurface_Release(tmp
);
4497 IDirectDrawSurface_Release(rt
);
4498 refcount
= IDirect3DDevice2_Release(device
);
4499 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
4500 refcount
= IDirectDrawSurface_Release(surface
);
4501 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
4504 IDirectDrawPalette_Release(palette
);
4505 IDirect3D2_Release(d3d
);
4508 refcount
= IDirectDraw2_Release(ddraw
);
4509 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4510 DestroyWindow(window
);
4513 static void test_primary_caps(void)
4515 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4516 IDirectDrawSurface
*surface
;
4517 DDSURFACEDESC surface_desc
;
4518 IDirectDraw2
*ddraw
;
4528 DWORD back_buffer_count
;
4536 DDSCAPS_PRIMARYSURFACE
,
4539 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
4543 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
4550 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
4557 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
4564 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
4571 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
4578 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4585 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4592 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4594 DDERR_NOEXCLUSIVEMODE
,
4598 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4599 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4605 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4606 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4609 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
4612 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4613 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
4619 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4620 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
4627 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4628 0, 0, 640, 480, 0, 0, 0, 0);
4629 ddraw
= create_ddraw();
4630 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4632 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4634 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
4635 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4637 memset(&surface_desc
, 0, sizeof(surface_desc
));
4638 surface_desc
.dwSize
= sizeof(surface_desc
);
4639 surface_desc
.dwFlags
= DDSD_CAPS
;
4640 if (test_data
[i
].back_buffer_count
!= ~0u)
4641 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4642 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4643 surface_desc
.dwBackBufferCount
= test_data
[i
].back_buffer_count
;
4644 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4645 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
4649 memset(&surface_desc
, 0, sizeof(surface_desc
));
4650 surface_desc
.dwSize
= sizeof(surface_desc
);
4651 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4652 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4653 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
4654 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4655 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4657 IDirectDrawSurface_Release(surface
);
4660 refcount
= IDirectDraw2_Release(ddraw
);
4661 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4662 DestroyWindow(window
);
4665 static void test_surface_lock(void)
4667 IDirectDraw2
*ddraw
;
4668 IDirectDrawSurface
*surface
;
4669 IDirect3DDevice2
*device
;
4684 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
4685 "videomemory offscreenplain"
4688 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4689 "systemmemory offscreenplain"
4692 DDSCAPS_PRIMARYSURFACE
,
4696 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
4697 "videomemory texture"
4700 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
4701 "systemmemory texture"
4704 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4713 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4714 0, 0, 640, 480, 0, 0, 0, 0);
4715 ddraw
= create_ddraw();
4716 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4717 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4719 skip("Failed to create a 3D device, skipping test.\n");
4720 IDirectDraw2_Release(ddraw
);
4721 DestroyWindow(window
);
4724 z_depth
= get_device_z_depth(device
);
4725 ok(!!z_depth
, "Failed to get device z depth.\n");
4726 IDirect3DDevice2_Release(device
);
4728 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4730 memset(&ddsd
, 0, sizeof(ddsd
));
4731 ddsd
.dwSize
= sizeof(ddsd
);
4732 ddsd
.dwFlags
= DDSD_CAPS
;
4733 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4735 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4739 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
4741 ddsd
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4742 U2(ddsd
).dwZBufferBitDepth
= z_depth
;
4744 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4746 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4747 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4749 memset(&ddsd
, 0, sizeof(ddsd
));
4750 ddsd
.dwSize
= sizeof(ddsd
);
4751 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4752 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4755 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4756 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4759 memset(&ddsd
, 0, sizeof(ddsd
));
4760 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4761 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, tests
[i
].name
);
4763 IDirectDrawSurface_Release(surface
);
4766 refcount
= IDirectDraw2_Release(ddraw
);
4767 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4768 DestroyWindow(window
);
4771 static void test_surface_discard(void)
4773 IDirectDraw2
*ddraw
;
4774 IDirect3DDevice2
*device
;
4778 IDirectDrawSurface
*surface
, *target
;
4787 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4788 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4789 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4790 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4794 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4795 0, 0, 640, 480, 0, 0, 0, 0);
4796 ddraw
= create_ddraw();
4797 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4798 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4800 skip("Failed to create a 3D device, skipping test.\n");
4801 DestroyWindow(window
);
4802 IDirectDraw2_Release(ddraw
);
4806 hr
= IDirect3DDevice2_GetRenderTarget(device
, &target
);
4807 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4809 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4813 memset(&ddsd
, 0, sizeof(ddsd
));
4814 ddsd
.dwSize
= sizeof(ddsd
);
4815 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4816 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4819 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4822 skip("Failed to create surface, skipping.\n");
4826 memset(&ddsd
, 0, sizeof(ddsd
));
4827 ddsd
.dwSize
= sizeof(ddsd
);
4828 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4829 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4830 addr
= ddsd
.lpSurface
;
4831 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4832 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4834 memset(&ddsd
, 0, sizeof(ddsd
));
4835 ddsd
.dwSize
= sizeof(ddsd
);
4836 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4837 ok(SUCCEEDED(hr
) , "Failed to lock surface, hr %#x.\n", hr
);
4838 discarded
= ddsd
.lpSurface
!= addr
;
4839 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4840 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4842 hr
= IDirectDrawSurface_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
4843 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
4845 memset(&ddsd
, 0, sizeof(ddsd
));
4846 ddsd
.dwSize
= sizeof(ddsd
);
4847 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4848 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4849 discarded
|= ddsd
.lpSurface
!= addr
;
4850 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4851 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4853 IDirectDrawSurface_Release(surface
);
4855 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4856 * AMD r500, evergreen). Windows XP, at least on AMD r200, never changes the pointer. */
4857 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
4860 IDirectDrawSurface_Release(target
);
4861 IDirect3DDevice2_Release(device
);
4862 IDirectDraw2_Release(ddraw
);
4863 DestroyWindow(window
);
4866 static void test_flip(void)
4868 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4869 IDirectDrawSurface
*frontbuffer
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
4870 DDSCAPS caps
= {DDSCAPS_FLIP
};
4871 DDSURFACEDESC surface_desc
;
4872 BOOL sysmem_primary
;
4873 IDirectDraw2
*ddraw
;
4874 DWORD expected_caps
;
4889 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE
},
4890 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN
},
4891 {"TEXTURE", DDSCAPS_TEXTURE
},
4894 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4895 0, 0, 640, 480, 0, 0, 0, 0);
4896 ddraw
= create_ddraw();
4897 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4899 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4900 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4902 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4904 /* Creating a flippable texture induces a BSoD on some versions of the
4905 * Intel graphics driver. At least Intel GMA 950 with driver version
4906 * 6.14.10.4926 on Windows XP SP3 is affected. */
4907 if ((test_data
[i
].caps
& DDSCAPS_TEXTURE
) && ddraw_is_intel(ddraw
))
4909 win_skip("Skipping flippable texture test.\n");
4913 memset(&surface_desc
, 0, sizeof(surface_desc
));
4914 surface_desc
.dwSize
= sizeof(surface_desc
);
4915 surface_desc
.dwFlags
= DDSD_CAPS
;
4916 if (!(test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4917 surface_desc
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4918 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
4919 surface_desc
.dwWidth
= 512;
4920 surface_desc
.dwHeight
= 512;
4921 surface_desc
.dwBackBufferCount
= 3;
4922 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4923 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4925 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_FLIP
;
4926 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4927 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4928 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4930 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_COMPLEX
;
4931 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_FLIP
;
4932 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4933 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4935 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_COMPLEX
;
4936 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4937 todo_wine_if(test_data
[i
].caps
& DDSCAPS_TEXTURE
)
4938 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
4942 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
4943 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
4944 hr
= IDirectDrawSurface_IsLost(frontbuffer
);
4945 ok(hr
== DD_OK
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4946 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4947 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
4948 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4950 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4951 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4952 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
4953 hr
= IDirectDrawSurface_IsLost(frontbuffer
);
4954 todo_wine
ok(hr
== DDERR_SURFACELOST
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4955 hr
= restore_surfaces(ddraw
);
4956 ok(SUCCEEDED(hr
), "%s: Failed to restore surfaces, hr %#x.\n", test_data
[i
].name
, hr
);
4958 memset(&surface_desc
, 0, sizeof(surface_desc
));
4959 surface_desc
.dwSize
= sizeof(surface_desc
);
4960 hr
= IDirectDrawSurface_GetSurfaceDesc(frontbuffer
, &surface_desc
);
4961 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4962 expected_caps
= DDSCAPS_FRONTBUFFER
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
4963 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
4964 expected_caps
|= DDSCAPS_VISIBLE
;
4965 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4966 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4967 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
4969 hr
= IDirectDrawSurface_GetAttachedSurface(frontbuffer
, &caps
, &backbuffer1
);
4970 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4971 memset(&surface_desc
, 0, sizeof(surface_desc
));
4972 surface_desc
.dwSize
= sizeof(surface_desc
);
4973 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer1
, &surface_desc
);
4974 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4975 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4976 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4977 expected_caps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
);
4978 expected_caps
|= DDSCAPS_BACKBUFFER
;
4979 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4980 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4982 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
4983 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4984 memset(&surface_desc
, 0, sizeof(surface_desc
));
4985 surface_desc
.dwSize
= sizeof(surface_desc
);
4986 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer2
, &surface_desc
);
4987 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4988 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4989 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4990 expected_caps
&= ~DDSCAPS_BACKBUFFER
;
4991 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4992 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4994 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
4995 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4996 memset(&surface_desc
, 0, sizeof(surface_desc
));
4997 surface_desc
.dwSize
= sizeof(surface_desc
);
4998 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer3
, &surface_desc
);
4999 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
5000 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
5001 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
5002 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
5003 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
5005 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
5006 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
5007 ok(surface
== frontbuffer
, "%s: Got unexpected surface %p, expected %p.\n",
5008 test_data
[i
].name
, surface
, frontbuffer
);
5009 IDirectDrawSurface_Release(surface
);
5011 memset(&surface_desc
, 0, sizeof(surface_desc
));
5012 surface_desc
.dwSize
= sizeof(surface_desc
);
5013 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5014 surface_desc
.ddsCaps
.dwCaps
= 0;
5015 surface_desc
.dwWidth
= 640;
5016 surface_desc
.dwHeight
= 480;
5017 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5018 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
5019 hr
= IDirectDrawSurface_Flip(frontbuffer
, surface
, DDFLIP_WAIT
);
5020 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5021 IDirectDrawSurface_Release(surface
);
5023 hr
= IDirectDrawSurface_Flip(frontbuffer
, frontbuffer
, DDFLIP_WAIT
);
5024 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5025 hr
= IDirectDrawSurface_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
5026 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5027 hr
= IDirectDrawSurface_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
5028 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5029 hr
= IDirectDrawSurface_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
5030 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5032 memset(&fx
, 0, sizeof(fx
));
5033 fx
.dwSize
= sizeof(fx
);
5034 U5(fx
).dwFillColor
= 0xffff0000;
5035 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5036 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5037 U5(fx
).dwFillColor
= 0xff00ff00;
5038 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5039 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5040 U5(fx
).dwFillColor
= 0xff0000ff;
5041 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5042 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5044 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
5045 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5046 color
= get_surface_color(backbuffer1
, 320, 240);
5047 /* The testbot seems to just copy the contents of one surface to all the
5048 * others, instead of properly flipping. */
5049 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
5050 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5051 color
= get_surface_color(backbuffer2
, 320, 240);
5052 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5053 U5(fx
).dwFillColor
= 0xffff0000;
5054 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5055 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5057 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
5058 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5059 color
= get_surface_color(backbuffer1
, 320, 240);
5060 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
5061 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5062 color
= get_surface_color(backbuffer2
, 320, 240);
5063 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5064 U5(fx
).dwFillColor
= 0xff00ff00;
5065 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5066 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5068 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
5069 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5070 color
= get_surface_color(backbuffer1
, 320, 240);
5071 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
5072 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5073 color
= get_surface_color(backbuffer2
, 320, 240);
5074 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5075 U5(fx
).dwFillColor
= 0xff0000ff;
5076 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5077 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5079 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer1
, DDFLIP_WAIT
);
5080 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5081 color
= get_surface_color(backbuffer2
, 320, 240);
5082 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
5083 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5084 color
= get_surface_color(backbuffer3
, 320, 240);
5085 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5086 U5(fx
).dwFillColor
= 0xffff0000;
5087 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5088 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5090 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer2
, DDFLIP_WAIT
);
5091 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5092 color
= get_surface_color(backbuffer1
, 320, 240);
5093 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5094 color
= get_surface_color(backbuffer3
, 320, 240);
5095 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
5096 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5097 U5(fx
).dwFillColor
= 0xff00ff00;
5098 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5099 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5101 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer3
, DDFLIP_WAIT
);
5102 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5103 color
= get_surface_color(backbuffer1
, 320, 240);
5104 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
5105 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5106 color
= get_surface_color(backbuffer2
, 320, 240);
5107 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5109 IDirectDrawSurface_Release(backbuffer3
);
5110 IDirectDrawSurface_Release(backbuffer2
);
5111 IDirectDrawSurface_Release(backbuffer1
);
5112 IDirectDrawSurface_Release(frontbuffer
);
5115 refcount
= IDirectDraw2_Release(ddraw
);
5116 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5117 DestroyWindow(window
);
5120 static void reset_ddsd(DDSURFACEDESC
*ddsd
)
5122 memset(ddsd
, 0, sizeof(*ddsd
));
5123 ddsd
->dwSize
= sizeof(*ddsd
);
5126 static void test_set_surface_desc(void)
5128 IDirectDraw2
*ddraw
;
5132 IDirectDrawSurface
*surface
;
5133 IDirectDrawSurface3
*surface3
;
5143 invalid_caps_tests
[] =
5145 {DDSCAPS_VIDEOMEMORY
, FALSE
, "videomemory plain"},
5146 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, TRUE
, "systemmemory texture"},
5147 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, FALSE
, "systemmemory primary"},
5150 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5151 0, 0, 640, 480, 0, 0, 0, 0);
5152 ddraw
= create_ddraw();
5153 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5154 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5155 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5158 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5161 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5162 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5163 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5164 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5165 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5166 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5167 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5169 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5170 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5172 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5173 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5174 IDirectDrawSurface_Release(surface
);
5177 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5178 ddsd
.lpSurface
= data
;
5179 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5180 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5182 /* Redundantly setting the same lpSurface is not an error. */
5183 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5184 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5185 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5186 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5187 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5188 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
5190 hr
= IDirectDrawSurface3_Lock(surface3
, NULL
, &ddsd
, 0, NULL
);
5191 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5192 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5193 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
5194 hr
= IDirectDrawSurface3_Unlock(surface3
, NULL
);
5195 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5198 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5199 ddsd
.lpSurface
= data
;
5200 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 1);
5201 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
5203 ddsd
.lpSurface
= NULL
;
5204 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5205 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
5207 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, NULL
, 0);
5208 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
5210 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5211 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5212 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5213 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5215 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5216 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5217 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
5219 ddsd
.dwFlags
= DDSD_CAPS
;
5220 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5221 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5223 /* dwCaps = 0 is allowed, but ignored. */
5224 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
5225 ddsd
.lpSurface
= data
;
5226 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5227 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5228 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5229 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5230 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5231 ddsd
.ddsCaps
.dwCaps
= 0;
5232 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5233 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5235 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5236 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5237 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5238 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5240 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5242 ddsd
.dwFlags
= DDSD_HEIGHT
;
5244 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5245 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
5247 ddsd
.lpSurface
= data
;
5248 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
5249 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5250 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5253 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5254 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
5257 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5258 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
5259 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5260 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5262 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
5264 ddsd
.dwFlags
= DDSD_PITCH
;
5265 U1(ddsd
).lPitch
= 8 * 4;
5266 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5267 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
5269 ddsd
.dwFlags
= DDSD_WIDTH
;
5271 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5272 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
5274 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
5275 ddsd
.lpSurface
= data
;
5276 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5277 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
5279 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
5280 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5281 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
5283 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5284 U1(ddsd
).lPitch
= 16 * 4;
5286 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5287 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5290 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5291 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5292 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5293 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5294 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
5296 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5298 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5299 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5300 U1(ddsd
).lPitch
= 4 * 4;
5301 ddsd
.lpSurface
= data
;
5302 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5303 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5305 U1(ddsd
).lPitch
= 4;
5306 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5307 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5309 U1(ddsd
).lPitch
= 16 * 4 + 1;
5310 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5311 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5313 U1(ddsd
).lPitch
= 16 * 4 + 3;
5314 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5315 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5317 U1(ddsd
).lPitch
= -4;
5318 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5319 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
5321 U1(ddsd
).lPitch
= 16 * 4;
5322 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5323 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5326 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5327 U1(ddsd
).lPitch
= 0;
5329 ddsd
.lpSurface
= data
;
5330 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5331 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
5333 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5334 U1(ddsd
).lPitch
= 16 * 4;
5336 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5337 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
5339 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5340 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
5341 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5342 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5343 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5344 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5345 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5346 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5347 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5348 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
5350 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
5351 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5352 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5354 /* Can't set color keys. */
5356 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
5357 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
5358 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
5359 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5360 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5362 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
5363 ddsd
.lpSurface
= data
;
5364 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5365 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5367 IDirectDrawSurface3_Release(surface3
);
5369 /* SetSurfaceDesc needs systemmemory surfaces.
5371 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5372 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
5375 ddsd
.dwFlags
= DDSD_CAPS
;
5376 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
5377 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5379 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5382 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5383 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5384 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5385 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5386 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5387 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5390 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5391 ok(SUCCEEDED(hr
) || hr
== DDERR_NODIRECTDRAWHW
, "Failed to create surface, hr %#x.\n", hr
);
5394 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5395 invalid_caps_tests
[i
].name
);
5398 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5399 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5400 IDirectDrawSurface_Release(surface
);
5403 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5404 ddsd
.lpSurface
= data
;
5405 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5406 if (invalid_caps_tests
[i
].supported
)
5408 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5412 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5413 invalid_caps_tests
[i
].name
, hr
);
5415 /* Check priority of error conditions. */
5416 ddsd
.dwFlags
= DDSD_WIDTH
;
5417 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5418 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5419 invalid_caps_tests
[i
].name
, hr
);
5422 IDirectDrawSurface3_Release(surface3
);
5426 ref
= IDirectDraw2_Release(ddraw
);
5427 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5428 DestroyWindow(window
);
5431 static void test_user_memory_getdc(void)
5433 IDirectDraw2
*ddraw
;
5437 IDirectDrawSurface
*surface
;
5438 IDirectDrawSurface3
*surface3
;
5447 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5448 0, 0, 640, 480, 0, 0, 0, 0);
5449 ddraw
= create_ddraw();
5450 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5452 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5453 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5456 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5459 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5460 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5461 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5462 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5463 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5464 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5465 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5466 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5467 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5469 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5470 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5471 IDirectDrawSurface_Release(surface
);
5473 memset(data
, 0xaa, sizeof(data
));
5475 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5476 ddsd
.lpSurface
= data
;
5477 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5478 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5480 hr
= IDirectDrawSurface3_GetDC(surface3
, &dc
);
5481 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5482 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
5483 ok(!!bitmap
, "Failed to get bitmap.\n");
5484 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
5485 ok(size
== sizeof(dib
), "Got unexpected size %d.\n", size
);
5486 ok(dib
.dsBm
.bmBits
== data
, "Got unexpected bits %p, expected %p.\n", dib
.dsBm
.bmBits
, data
);
5487 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
5488 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
5489 hr
= IDirectDrawSurface3_ReleaseDC(surface3
, dc
);
5490 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5492 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
5493 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
5495 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
5496 ddsd
.lpSurface
= data
;
5499 U1(ddsd
).lPitch
= sizeof(*data
);
5500 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5501 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5503 memset(data
, 0xaa, sizeof(data
));
5504 hr
= IDirectDrawSurface3_GetDC(surface3
, &dc
);
5505 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5506 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
5507 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
5508 hr
= IDirectDrawSurface3_ReleaseDC(surface3
, dc
);
5509 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5511 for (y
= 0; y
< 4; y
++)
5513 for (x
= 0; x
< 4; x
++)
5515 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
5516 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5519 ok(data
[y
][x
] == 0x00000000, "Expected color 0xaaaaaaaa on position %ux%u, got %#x.\n",
5523 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5525 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5527 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5529 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5532 IDirectDrawSurface3_Release(surface3
);
5533 ref
= IDirectDraw2_Release(ddraw
);
5534 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5535 DestroyWindow(window
);
5538 static void test_sysmem_overlay(void)
5540 IDirectDraw2
*ddraw
;
5544 IDirectDrawSurface
*surface
;
5547 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5548 0, 0, 640, 480, 0, 0, 0, 0);
5549 ddraw
= create_ddraw();
5550 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5552 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5553 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5556 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
5559 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
5560 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5561 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5562 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5563 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5564 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5565 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5566 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5567 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
5569 ref
= IDirectDraw2_Release(ddraw
);
5570 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5571 DestroyWindow(window
);
5574 static void test_primary_palette(void)
5576 DDSCAPS surface_caps
= {DDSCAPS_FLIP
};
5577 IDirectDrawSurface
*primary
, *backbuffer
;
5578 PALETTEENTRY palette_entries
[256];
5579 IDirectDrawPalette
*palette
, *tmp
;
5580 DDSURFACEDESC surface_desc
;
5581 IDirectDraw2
*ddraw
;
5587 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5588 0, 0, 640, 480, 0, 0, 0, 0);
5589 ddraw
= create_ddraw();
5590 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5591 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
5593 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5594 IDirectDraw2_Release(ddraw
);
5595 DestroyWindow(window
);
5598 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5599 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5601 memset(&surface_desc
, 0, sizeof(surface_desc
));
5602 surface_desc
.dwSize
= sizeof(surface_desc
);
5603 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
5604 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
5605 surface_desc
.dwBackBufferCount
= 1;
5606 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
5607 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5608 hr
= IDirectDrawSurface_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
5609 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5611 memset(palette_entries
, 0, sizeof(palette_entries
));
5612 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
5613 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5614 refcount
= get_refcount((IUnknown
*)palette
);
5615 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5617 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5618 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5619 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5621 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5622 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5624 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
5625 * and is generally somewhat broken with respect to 8 bpp / palette
5627 if (SUCCEEDED(IDirectDrawSurface_GetPalette(backbuffer
, &tmp
)))
5629 win_skip("Broken palette handling detected, skipping tests.\n");
5630 IDirectDrawPalette_Release(tmp
);
5631 IDirectDrawPalette_Release(palette
);
5632 /* The Windows 8 testbot keeps extra references to the primary and
5633 * backbuffer while in 8 bpp mode. */
5634 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
5635 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
5639 refcount
= get_refcount((IUnknown
*)palette
);
5640 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5642 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5643 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5644 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
5645 "Got unexpected palette caps %#x.\n", palette_caps
);
5647 hr
= IDirectDrawSurface_SetPalette(primary
, NULL
);
5648 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5649 refcount
= get_refcount((IUnknown
*)palette
);
5650 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5652 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5653 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5654 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5656 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5657 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5658 refcount
= get_refcount((IUnknown
*)palette
);
5659 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5661 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
5662 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
5663 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
5664 IDirectDrawPalette_Release(tmp
);
5665 hr
= IDirectDrawSurface_GetPalette(backbuffer
, &tmp
);
5666 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5668 refcount
= IDirectDrawPalette_Release(palette
);
5669 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5670 refcount
= IDirectDrawPalette_Release(palette
);
5671 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5673 /* Note that this only seems to work when the palette is attached to the
5674 * primary surface. When attached to a regular surface, attempting to get
5675 * the palette here will cause an access violation. */
5676 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
5677 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5679 hr
= IDirectDrawSurface_IsLost(primary
);
5680 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
5682 memset(&surface_desc
, 0, sizeof(surface_desc
));
5683 surface_desc
.dwSize
= sizeof(surface_desc
);
5684 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
5685 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5686 ok(surface_desc
.dwWidth
== 640, "Got unexpected surface width %u.\n", surface_desc
.dwWidth
);
5687 ok(surface_desc
.dwHeight
== 480, "Got unexpected surface height %u.\n", surface_desc
.dwHeight
);
5688 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 8, "Got unexpected bit count %u.\n",
5689 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
5691 hr
= set_display_mode(ddraw
, 640, 480);
5692 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
5694 memset(&surface_desc
, 0, sizeof(surface_desc
));
5695 surface_desc
.dwSize
= sizeof(surface_desc
);
5696 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
5697 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5698 ok(surface_desc
.dwWidth
== 640, "Got unexpected surface width %u.\n", surface_desc
.dwWidth
);
5699 ok(surface_desc
.dwHeight
== 480, "Got unexpected surface height %u.\n", surface_desc
.dwHeight
);
5700 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 32
5701 || U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 24,
5702 "Got unexpected bit count %u.\n", U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
5704 hr
= IDirectDrawSurface_IsLost(primary
);
5705 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
5706 hr
= IDirectDrawSurface_Restore(primary
);
5707 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
5708 hr
= IDirectDrawSurface_IsLost(primary
);
5709 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
5711 memset(&surface_desc
, 0, sizeof(surface_desc
));
5712 surface_desc
.dwSize
= sizeof(surface_desc
);
5713 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
5714 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5715 ok(surface_desc
.dwWidth
== 640, "Got unexpected surface width %u.\n", surface_desc
.dwWidth
);
5716 ok(surface_desc
.dwHeight
== 480, "Got unexpected surface height %u.\n", surface_desc
.dwHeight
);
5717 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 32
5718 || U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 24,
5719 "Got unexpected bit count %u.\n", U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
5722 refcount
= IDirectDrawSurface_Release(backbuffer
);
5723 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5724 refcount
= IDirectDrawSurface_Release(primary
);
5725 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5726 refcount
= IDirectDraw2_Release(ddraw
);
5727 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5728 DestroyWindow(window
);
5731 static HRESULT WINAPI
surface_counter(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
5733 UINT
*surface_count
= context
;
5736 IDirectDrawSurface_Release(surface
);
5738 return DDENUMRET_OK
;
5741 static void test_surface_attachment(void)
5743 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
5744 DDSCAPS caps
= {DDSCAPS_TEXTURE
};
5745 DDSURFACEDESC surface_desc
;
5746 IDirectDraw2
*ddraw
;
5752 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5753 0, 0, 640, 480, 0, 0, 0, 0);
5754 ddraw
= create_ddraw();
5755 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5756 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5757 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5759 memset(&surface_desc
, 0, sizeof(surface_desc
));
5760 surface_desc
.dwSize
= sizeof(surface_desc
);
5761 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
5762 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
5763 U2(surface_desc
).dwMipMapCount
= 3;
5764 surface_desc
.dwWidth
= 128;
5765 surface_desc
.dwHeight
= 128;
5766 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5767 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5769 hr
= IDirectDrawSurface_GetAttachedSurface(surface1
, &caps
, &surface2
);
5770 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5771 hr
= IDirectDrawSurface_GetAttachedSurface(surface2
, &caps
, &surface3
);
5772 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5773 hr
= IDirectDrawSurface_GetAttachedSurface(surface3
, &caps
, &surface4
);
5774 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5777 IDirectDrawSurface_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
5778 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5780 IDirectDrawSurface_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
5781 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5783 IDirectDrawSurface_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
5784 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
5786 memset(&surface_desc
, 0, sizeof(surface_desc
));
5787 surface_desc
.dwSize
= sizeof(surface_desc
);
5788 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5789 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
5790 surface_desc
.dwWidth
= 16;
5791 surface_desc
.dwHeight
= 16;
5792 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5793 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5795 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
5796 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5797 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5798 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5799 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
5800 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5801 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
5802 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5803 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
5804 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5805 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
5806 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5808 IDirectDrawSurface_Release(surface4
);
5810 memset(&surface_desc
, 0, sizeof(surface_desc
));
5811 surface_desc
.dwSize
= sizeof(surface_desc
);
5812 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5813 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5814 surface_desc
.dwWidth
= 16;
5815 surface_desc
.dwHeight
= 16;
5816 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5817 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5819 if (SUCCEEDED(hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
)))
5821 skip("Running on refrast, skipping some tests.\n");
5822 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface4
);
5823 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5827 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5828 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5829 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5830 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
5831 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5832 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
5833 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5834 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
5835 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5836 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
5837 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5840 IDirectDrawSurface_Release(surface4
);
5841 IDirectDrawSurface_Release(surface3
);
5842 IDirectDrawSurface_Release(surface2
);
5843 IDirectDrawSurface_Release(surface1
);
5845 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5846 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5848 /* Try a single primary and two offscreen plain surfaces. */
5849 memset(&surface_desc
, 0, sizeof(surface_desc
));
5850 surface_desc
.dwSize
= sizeof(surface_desc
);
5851 surface_desc
.dwFlags
= DDSD_CAPS
;
5852 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
5853 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5854 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5856 memset(&surface_desc
, 0, sizeof(surface_desc
));
5857 surface_desc
.dwSize
= sizeof(surface_desc
);
5858 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5859 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5860 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
5861 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
5862 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5863 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5865 memset(&surface_desc
, 0, sizeof(surface_desc
));
5866 surface_desc
.dwSize
= sizeof(surface_desc
);
5867 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5868 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5869 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
5870 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
5871 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5872 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5874 /* This one has a different size. */
5875 memset(&surface_desc
, 0, sizeof(surface_desc
));
5876 surface_desc
.dwSize
= sizeof(surface_desc
);
5877 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5878 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5879 surface_desc
.dwWidth
= 128;
5880 surface_desc
.dwHeight
= 128;
5881 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5882 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5884 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5885 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5886 /* Try the reverse without detaching first. */
5887 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
5888 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5889 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5890 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5892 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
5893 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5894 /* Try to detach reversed. */
5895 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5896 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5897 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
5898 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5900 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
);
5901 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5902 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
5903 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5905 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
5906 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5907 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5908 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5910 IDirectDrawSurface_Release(surface4
);
5911 IDirectDrawSurface_Release(surface3
);
5912 IDirectDrawSurface_Release(surface2
);
5913 IDirectDrawSurface_Release(surface1
);
5915 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
5916 memset(&surface_desc
, 0, sizeof(surface_desc
));
5917 surface_desc
.dwSize
= sizeof(surface_desc
);
5918 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5919 surface_desc
.dwWidth
= 64;
5920 surface_desc
.dwHeight
= 64;
5921 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5922 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5923 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
5924 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
5925 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
5926 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
5927 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
5928 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5929 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5930 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5931 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5933 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
5934 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
5935 U1(surface_desc
.ddpfPixelFormat
).dwZBufferBitDepth
= 16;
5936 U3(surface_desc
.ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
5937 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5938 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5940 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5941 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5942 refcount
= get_refcount((IUnknown
*)surface2
);
5943 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5944 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5945 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5947 /* Attaching while already attached to other surface. */
5948 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface2
);
5949 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5950 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface3
, 0, surface2
);
5951 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5952 IDirectDrawSurface_Release(surface3
);
5954 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5955 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5956 refcount
= get_refcount((IUnknown
*)surface2
);
5957 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5959 /* Automatic detachment on release. */
5960 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5961 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5962 refcount
= get_refcount((IUnknown
*)surface2
);
5963 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5964 refcount
= IDirectDrawSurface_Release(surface1
);
5965 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5966 refcount
= IDirectDrawSurface_Release(surface2
);
5967 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5968 refcount
= IDirectDraw2_Release(ddraw
);
5969 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5970 DestroyWindow(window
);
5973 static void test_pixel_format(void)
5975 HWND window
, window2
= NULL
;
5976 HDC hdc
, hdc2
= NULL
;
5978 int format
, test_format
;
5979 PIXELFORMATDESCRIPTOR pfd
;
5980 IDirectDraw2
*ddraw
= NULL
;
5981 IDirectDrawClipper
*clipper
= NULL
;
5983 IDirectDrawSurface
*primary
= NULL
;
5987 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
5988 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
5991 skip("Failed to create window\n");
5995 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
5996 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
5998 hdc
= GetDC(window
);
6001 skip("Failed to get DC\n");
6006 hdc2
= GetDC(window2
);
6008 gl
= LoadLibraryA("opengl32.dll");
6009 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6011 format
= GetPixelFormat(hdc
);
6012 ok(format
== 0, "new window has pixel format %d\n", format
);
6014 ZeroMemory(&pfd
, sizeof(pfd
));
6015 pfd
.nSize
= sizeof(pfd
);
6017 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
6018 pfd
.iPixelType
= PFD_TYPE_RGBA
;
6019 pfd
.iLayerType
= PFD_MAIN_PLANE
;
6020 format
= ChoosePixelFormat(hdc
, &pfd
);
6023 skip("no pixel format available\n");
6027 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
6029 skip("failed to set pixel format\n");
6033 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
6035 skip("failed to set pixel format on second window\n");
6038 ReleaseDC(window2
, hdc2
);
6043 ddraw
= create_ddraw();
6044 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6046 test_format
= GetPixelFormat(hdc
);
6047 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6049 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6052 skip("Failed to set cooperative level, hr %#x.\n", hr
);
6056 test_format
= GetPixelFormat(hdc
);
6057 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6061 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
6062 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
6063 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
6064 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
6066 test_format
= GetPixelFormat(hdc
);
6067 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6069 test_format
= GetPixelFormat(hdc2
);
6070 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6073 memset(&ddsd
, 0, sizeof(ddsd
));
6074 ddsd
.dwSize
= sizeof(ddsd
);
6075 ddsd
.dwFlags
= DDSD_CAPS
;
6076 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6078 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
6079 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
6081 test_format
= GetPixelFormat(hdc
);
6082 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6086 test_format
= GetPixelFormat(hdc2
);
6087 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6092 hr
= IDirectDrawSurface2_SetClipper(primary
, clipper
);
6093 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
6095 test_format
= GetPixelFormat(hdc
);
6096 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6098 test_format
= GetPixelFormat(hdc2
);
6099 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6102 memset(&fx
, 0, sizeof(fx
));
6103 fx
.dwSize
= sizeof(fx
);
6104 hr
= IDirectDrawSurface2_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6105 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
6107 test_format
= GetPixelFormat(hdc
);
6108 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6112 test_format
= GetPixelFormat(hdc2
);
6113 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6117 if (primary
) IDirectDrawSurface2_Release(primary
);
6118 if (clipper
) IDirectDrawClipper_Release(clipper
);
6119 if (ddraw
) IDirectDraw2_Release(ddraw
);
6120 if (gl
) FreeLibrary(gl
);
6121 if (hdc
) ReleaseDC(window
, hdc
);
6122 if (hdc2
) ReleaseDC(window2
, hdc2
);
6123 if (window
) DestroyWindow(window
);
6124 if (window2
) DestroyWindow(window2
);
6127 static void test_create_surface_pitch(void)
6129 IDirectDrawSurface
*surface
;
6130 DDSURFACEDESC surface_desc
;
6131 IDirectDraw2
*ddraw
;
6151 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6153 DDSD_PITCH
, 0x100, 0x100},
6154 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6155 DDSD_PITCH
, 0x104, DD_OK
,
6156 DDSD_PITCH
, 0x100, 0x100},
6157 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6158 DDSD_PITCH
, 0x0f8, DD_OK
,
6159 DDSD_PITCH
, 0x100, 0x100},
6160 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6161 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
6163 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6165 DDSD_PITCH
, 0x100, 0x0fc},
6167 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6168 DDSD_PITCH
, 0x104, DD_OK
,
6169 DDSD_PITCH
, 0x100, 0x0fc},
6170 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6171 DDSD_PITCH
, 0x0f8, DD_OK
,
6172 DDSD_PITCH
, 0x100, 0x0fc},
6173 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6174 DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
6175 DDSD_PITCH
, 0x100, 0x0fc},
6176 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6177 DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
6179 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6180 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
6183 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
6184 0, 0, DDERR_INVALIDCAPS
,
6186 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6188 DDSD_PITCH
, 0x100, 0 },
6189 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6190 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
6192 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
6193 0, 0, DDERR_INVALIDCAPS
,
6195 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6197 DDSD_PITCH
, 0x100, 0 },
6199 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6200 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
6203 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
6205 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6206 0, 0, 640, 480, 0, 0, 0, 0);
6207 ddraw
= create_ddraw();
6208 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6209 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6210 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6212 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
6214 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6216 memset(&surface_desc
, 0, sizeof(surface_desc
));
6217 surface_desc
.dwSize
= sizeof(surface_desc
);
6218 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
6219 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
6220 surface_desc
.dwWidth
= 63;
6221 surface_desc
.dwHeight
= 63;
6222 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
6223 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6224 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6225 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6226 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6227 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6228 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6229 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6230 if (test_data
[i
].flags_in
& DDSD_LPSURFACE
)
6232 HRESULT expected_hr
= SUCCEEDED(test_data
[i
].hr
) ? DDERR_INVALIDPARAMS
: test_data
[i
].hr
;
6233 ok(hr
== expected_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, expected_hr
);
6234 surface_desc
.lpSurface
= mem
;
6235 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6237 if ((test_data
[i
].caps
& DDSCAPS_VIDEOMEMORY
) && hr
== DDERR_NODIRECTDRAWHW
)
6239 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
6243 memset(&surface_desc
, 0, sizeof(surface_desc
));
6244 surface_desc
.dwSize
= sizeof(surface_desc
);
6245 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
6246 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
6247 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
6248 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6249 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
6250 /* The pitch for textures seems to be implementation specific. */
6251 if (!(test_data
[i
].caps
& DDSCAPS_TEXTURE
))
6253 if (is_ddraw64
&& test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
6254 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
6255 "Test %u: Got unexpected pitch %u, expected %u.\n",
6256 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
6258 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
6259 "Test %u: Got unexpected pitch %u, expected %u.\n",
6260 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
6262 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
6264 IDirectDrawSurface_Release(surface
);
6267 HeapFree(GetProcessHeap(), 0, mem
);
6268 refcount
= IDirectDraw2_Release(ddraw
);
6269 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6270 DestroyWindow(window
);
6273 static void test_mipmap(void)
6275 IDirectDrawSurface
*surface1
;
6276 IDirectDrawSurface2
*surface
, *surface2
;
6277 DDSURFACEDESC surface_desc
;
6278 IDirectDraw2
*ddraw
;
6283 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
6292 DWORD mipmap_count_in
;
6294 DWORD mipmap_count_out
;
6298 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 3, DD_OK
, 3},
6299 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDPARAMS
, 0},
6300 {0, DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 1},
6301 {0, DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDCAPS
, 0},
6302 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 6},
6303 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 32, 64, 0, DD_OK
, 6},
6306 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6307 0, 0, 640, 480, 0, 0, 0, 0);
6308 ddraw
= create_ddraw();
6309 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6310 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6311 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6313 memset(&hal_caps
, 0, sizeof(hal_caps
));
6314 hal_caps
.dwSize
= sizeof(hal_caps
);
6315 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
6316 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6317 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6319 skip("Mipmapped textures not supported, skipping tests.\n");
6320 IDirectDraw2_Release(ddraw
);
6321 DestroyWindow(window
);
6325 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
6327 memset(&surface_desc
, 0, sizeof(surface_desc
));
6328 surface_desc
.dwSize
= sizeof(surface_desc
);
6329 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| tests
[i
].flags
;
6330 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
6331 surface_desc
.dwWidth
= tests
[i
].width
;
6332 surface_desc
.dwHeight
= tests
[i
].height
;
6333 if (tests
[i
].flags
& DDSD_MIPMAPCOUNT
)
6334 U2(surface_desc
).dwMipMapCount
= tests
[i
].mipmap_count_in
;
6335 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6336 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
6340 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
6341 ok(SUCCEEDED(hr
), "Test %u: Failed to get IDirectDrawSurface2 interface, hr %#x.\n", i
, hr
);
6342 IDirectDrawSurface_Release(surface1
);
6344 memset(&surface_desc
, 0, sizeof(surface_desc
));
6345 surface_desc
.dwSize
= sizeof(surface_desc
);
6346 hr
= IDirectDrawSurface2_GetSurfaceDesc(surface
, &surface_desc
);
6347 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
6348 ok(surface_desc
.dwFlags
& DDSD_MIPMAPCOUNT
,
6349 "Test %u: Got unexpected flags %#x.\n", i
, surface_desc
.dwFlags
);
6350 ok(U2(surface_desc
).dwMipMapCount
== tests
[i
].mipmap_count_out
,
6351 "Test %u: Got unexpected mipmap count %u.\n", i
, U2(surface_desc
).dwMipMapCount
);
6353 if (U2(surface_desc
).dwMipMapCount
> 1)
6355 hr
= IDirectDrawSurface2_GetAttachedSurface(surface
, &caps
, &surface2
);
6356 ok(SUCCEEDED(hr
), "Test %u: Failed to get attached surface, hr %#x.\n", i
, hr
);
6358 memset(&surface_desc
, 0, sizeof(surface_desc
));
6359 surface_desc
.dwSize
= sizeof(surface_desc
);
6360 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
6361 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
6362 memset(&surface_desc
, 0, sizeof(surface_desc
));
6363 surface_desc
.dwSize
= sizeof(surface_desc
);
6364 hr
= IDirectDrawSurface2_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
6365 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
6366 IDirectDrawSurface2_Unlock(surface2
, NULL
);
6367 IDirectDrawSurface2_Unlock(surface
, NULL
);
6369 IDirectDrawSurface2_Release(surface2
);
6372 IDirectDrawSurface2_Release(surface
);
6375 refcount
= IDirectDraw2_Release(ddraw
);
6376 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6377 DestroyWindow(window
);
6380 static void test_palette_complex(void)
6382 IDirectDrawSurface
*surface1
;
6383 IDirectDrawSurface2
*surface
, *mipmap
, *tmp
;
6384 DDSURFACEDESC surface_desc
;
6385 IDirectDraw2
*ddraw
;
6386 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
6390 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
6392 PALETTEENTRY palette_entries
[256];
6398 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6399 0, 0, 640, 480, 0, 0, 0, 0);
6400 ddraw
= create_ddraw();
6401 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6402 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6403 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6405 memset(&hal_caps
, 0, sizeof(hal_caps
));
6406 hal_caps
.dwSize
= sizeof(hal_caps
);
6407 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
6408 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6409 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6411 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
6412 IDirectDraw2_Release(ddraw
);
6413 DestroyWindow(window
);
6417 memset(&surface_desc
, 0, sizeof(surface_desc
));
6418 surface_desc
.dwSize
= sizeof(surface_desc
);
6419 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6420 surface_desc
.dwWidth
= 128;
6421 surface_desc
.dwHeight
= 128;
6422 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6423 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6424 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6425 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6426 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6427 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6428 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
6429 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
6430 IDirectDrawSurface_Release(surface1
);
6432 memset(palette_entries
, 0, sizeof(palette_entries
));
6433 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6434 palette_entries
, &palette
, NULL
);
6435 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6437 memset(palette_entries
, 0, sizeof(palette_entries
));
6438 palette_entries
[1].peRed
= 0xff;
6439 palette_entries
[1].peGreen
= 0x80;
6440 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6441 palette_entries
, &palette_mipmap
, NULL
);
6442 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6444 palette2
= (void *)0xdeadbeef;
6445 hr
= IDirectDrawSurface2_GetPalette(surface
, &palette2
);
6446 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6447 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
6448 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
6449 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6450 hr
= IDirectDrawSurface2_GetPalette(surface
, &palette2
);
6451 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6452 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
6453 IDirectDrawPalette_Release(palette2
);
6456 IDirectDrawSurface2_AddRef(mipmap
);
6457 for (i
= 0; i
< 7; ++i
)
6459 hr
= IDirectDrawSurface2_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6460 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
6461 palette2
= (void *)0xdeadbeef;
6462 hr
= IDirectDrawSurface2_GetPalette(tmp
, &palette2
);
6463 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
6464 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
6466 hr
= IDirectDrawSurface2_SetPalette(tmp
, palette_mipmap
);
6467 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
6469 hr
= IDirectDrawSurface2_GetPalette(tmp
, &palette2
);
6470 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
6471 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
6472 IDirectDrawPalette_Release(palette2
);
6474 hr
= IDirectDrawSurface2_GetDC(tmp
, &dc
);
6475 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
6476 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
6477 ok(count
== 1, "Expected count 1, got %u.\n", count
);
6478 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
6479 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
6480 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
6481 hr
= IDirectDrawSurface2_ReleaseDC(tmp
, dc
);
6482 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
6484 IDirectDrawSurface2_Release(mipmap
);
6488 hr
= IDirectDrawSurface2_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6489 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6490 IDirectDrawSurface2_Release(mipmap
);
6491 refcount
= IDirectDrawSurface2_Release(surface
);
6492 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6493 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
6494 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6495 refcount
= IDirectDrawPalette_Release(palette
);
6496 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6498 refcount
= IDirectDraw2_Release(ddraw
);
6499 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6500 DestroyWindow(window
);
6503 static void test_p8_blit(void)
6505 IDirectDrawSurface
*src
, *dst
, *dst_p8
;
6506 DDSURFACEDESC surface_desc
;
6507 IDirectDraw2
*ddraw
;
6508 IDirectDrawPalette
*palette
, *palette2
;
6512 PALETTEENTRY palette_entries
[256];
6516 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
6517 static const BYTE src_data2
[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
6518 static const BYTE expected_p8
[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
6519 static const D3DCOLOR expected
[] =
6521 0x00101010, 0x00010101, 0x00020202, 0x00030303,
6522 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
6526 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6527 0, 0, 640, 480, 0, 0, 0, 0);
6528 ddraw
= create_ddraw();
6529 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6530 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6531 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6532 is_warp
= ddraw_is_warp(ddraw
);
6534 memset(palette_entries
, 0, sizeof(palette_entries
));
6535 palette_entries
[1].peGreen
= 0xff;
6536 palette_entries
[2].peBlue
= 0xff;
6537 palette_entries
[3].peFlags
= 0xff;
6538 palette_entries
[4].peRed
= 0xff;
6539 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6540 palette_entries
, &palette
, NULL
);
6541 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6542 palette_entries
[1].peBlue
= 0xff;
6543 palette_entries
[2].peGreen
= 0xff;
6544 palette_entries
[3].peRed
= 0xff;
6545 palette_entries
[4].peFlags
= 0x0;
6546 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6547 palette_entries
, &palette2
, NULL
);
6548 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6550 memset(&surface_desc
, 0, sizeof(surface_desc
));
6551 surface_desc
.dwSize
= sizeof(surface_desc
);
6552 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6553 surface_desc
.dwWidth
= 8;
6554 surface_desc
.dwHeight
= 1;
6555 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6556 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6557 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6558 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6559 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
6560 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6561 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst_p8
, NULL
);
6562 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6563 hr
= IDirectDrawSurface_SetPalette(dst_p8
, palette2
);
6564 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6566 memset(&surface_desc
, 0, sizeof(surface_desc
));
6567 surface_desc
.dwSize
= sizeof(surface_desc
);
6568 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6569 surface_desc
.dwWidth
= 8;
6570 surface_desc
.dwHeight
= 1;
6571 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6572 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6573 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6574 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6575 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6576 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6577 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6578 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6579 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
6580 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6582 memset(&surface_desc
, 0, sizeof(surface_desc
));
6583 surface_desc
.dwSize
= sizeof(surface_desc
);
6584 hr
= IDirectDrawSurface_Lock(src
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
6585 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
6586 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
6587 hr
= IDirectDrawSurface_Unlock(src
, NULL
);
6588 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
6590 hr
= IDirectDrawSurface_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
6591 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
6592 memcpy(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
));
6593 hr
= IDirectDrawSurface_Unlock(dst_p8
, NULL
);
6594 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
6596 hr
= IDirectDrawSurface_SetPalette(src
, palette
);
6597 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6598 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
6599 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
6600 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
6601 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
6602 "Failed to blit, hr %#x.\n", hr
);
6606 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
6608 color
= get_surface_color(dst
, x
, 0);
6609 todo_wine
ok(compare_color(color
, expected
[x
], 0),
6610 "Pixel %u: Got color %#x, expected %#x.\n",
6611 x
, color
, expected
[x
]);
6615 memset(&fx
, 0, sizeof(fx
));
6616 fx
.dwSize
= sizeof(fx
);
6617 fx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 0x2;
6618 fx
.ddckSrcColorkey
.dwColorSpaceLowValue
= 0x2;
6619 hr
= IDirectDrawSurface7_Blt(dst_p8
, NULL
, src
, NULL
, DDBLT_WAIT
| DDBLT_KEYSRCOVERRIDE
, &fx
);
6620 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
6622 hr
= IDirectDrawSurface_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
6623 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
6624 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
6625 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
6626 * for example) also works as expected.
6628 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
6629 * the display mode set to P8 doesn't help either. */
6630 ok(!memcmp(surface_desc
.lpSurface
, expected_p8
, sizeof(expected_p8
))
6631 || broken(is_warp
&& !memcmp(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
))),
6632 "Got unexpected P8 color key blit result.\n");
6633 hr
= IDirectDrawSurface_Unlock(dst_p8
, NULL
);
6634 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
6636 IDirectDrawSurface_Release(src
);
6637 IDirectDrawSurface_Release(dst
);
6638 IDirectDrawSurface_Release(dst_p8
);
6639 IDirectDrawPalette_Release(palette
);
6640 IDirectDrawPalette_Release(palette2
);
6642 refcount
= IDirectDraw2_Release(ddraw
);
6643 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6644 DestroyWindow(window
);
6647 static void test_material(void)
6649 IDirect3DMaterial2
*background
, *material
;
6650 D3DMATERIALHANDLE mat_handle
, tmp
;
6651 IDirect3DViewport2
*viewport
;
6652 IDirect3DDevice2
*device
;
6653 IDirectDrawSurface
*rt
;
6654 IDirectDraw2
*ddraw
;
6662 static D3DVERTEX quad
[] =
6664 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6665 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6666 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6667 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6672 D3DCOLOR expected_color
;
6677 {FALSE
, 0x00ffffff},
6679 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6681 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6682 0, 0, 640, 480, 0, 0, 0, 0);
6683 ddraw
= create_ddraw();
6684 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6685 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6687 skip("Failed to create a 3D device, skipping test.\n");
6688 DestroyWindow(window
);
6692 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6693 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6695 background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
6696 viewport
= create_viewport(device
, 0, 0, 640, 480);
6697 viewport_set_background(device
, viewport
, background
);
6698 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6699 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6701 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
6702 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6703 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6705 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6706 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6707 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6708 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6709 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6710 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6711 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6712 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6713 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, 0);
6714 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6715 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6716 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6717 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6719 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6721 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
6722 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6724 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
6725 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6727 hr
= IDirect3DDevice2_BeginScene(device
);
6728 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6729 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_VERTEX
, quad
, 4, 0);
6730 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6731 hr
= IDirect3DDevice2_EndScene(device
);
6732 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6733 color
= get_surface_color(rt
, 320, 240);
6734 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
6735 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
6738 destroy_material(material
);
6739 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
6740 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6741 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6743 hr
= IDirect3DViewport2_SetBackground(viewport
, mat_handle
);
6744 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
6745 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6746 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6747 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6748 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6749 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6750 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6751 color
= get_surface_color(rt
, 320, 240);
6752 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6754 hr
= IDirect3DViewport2_SetBackground(viewport
, 0);
6755 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6756 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6757 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6758 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6759 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6760 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6761 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6762 color
= get_surface_color(rt
, 320, 240);
6763 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6765 destroy_viewport(device
, viewport
);
6766 viewport
= create_viewport(device
, 0, 0, 640, 480);
6768 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6769 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6770 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6771 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
6772 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6773 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6774 color
= get_surface_color(rt
, 320, 240);
6775 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
6777 destroy_viewport(device
, viewport
);
6778 destroy_material(background
);
6779 destroy_material(material
);
6780 IDirectDrawSurface_Release(rt
);
6781 refcount
= IDirect3DDevice2_Release(device
);
6782 ok(!refcount
, "Device has %u references left.\n", refcount
);
6783 refcount
= IDirectDraw2_Release(ddraw
);
6784 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
6785 DestroyWindow(window
);
6788 static void test_lighting(void)
6790 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6791 static D3DMATRIX mat
=
6793 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6794 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6795 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6796 0.0f
, 0.0f
, 0.0f
, 1.0f
,
6800 1.0f
, 0.0f
, 1.0f
, 0.0f
,
6801 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6802 1.0f
, 0.0f
, 1.0f
, 0.0f
,
6803 0.0f
, 0.0f
, 0.5f
, 1.0f
,
6807 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6808 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6809 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
6810 10.f
, 10.0f
, 10.0f
, 1.0f
,
6814 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6815 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6816 0.0f
, 0.0f
, 1.0f
, -1.0f
,
6817 10.f
, 10.0f
, 10.0f
, 0.0f
,
6819 static D3DLVERTEX unlitquad
[] =
6821 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6822 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6823 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6824 {{ 0.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6828 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6829 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6830 {{ 0.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6831 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6833 static D3DVERTEX unlitnquad
[] =
6835 {{0.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6836 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6837 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6838 {{1.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6842 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6843 {{0.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6844 {{1.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6845 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6849 {{-1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6850 {{-1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6851 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6852 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6856 {{-10.0f
}, {-11.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6857 {{-10.0f
}, { -9.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6858 {{-10.0f
}, { -9.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6859 {{-10.0f
}, {-11.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6863 {{-11.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6864 {{-11.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6865 {{ -9.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6866 {{ -9.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6868 static WORD indices
[] = {0, 1, 2, 2, 3, 0};
6871 D3DMATRIX
*world_matrix
;
6874 const char *message
;
6878 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
6879 {&mat_singular
, nquad
, 0x000000b4, "Lit quad with singular world matrix"},
6880 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
6881 {&mat_nonaffine
, translatedquad
, 0x000000ff, "Lit quad with non-affine matrix"},
6886 IDirect3DDevice2
*device
;
6887 IDirectDraw2
*ddraw
;
6888 IDirectDrawSurface
*rt
;
6889 IDirect3DViewport2
*viewport
;
6890 IDirect3DMaterial2
*material
;
6891 IDirect3DLight
*light
;
6892 D3DMATERIALHANDLE mat_handle
;
6893 D3DLIGHT2 light_desc
;
6899 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6900 0, 0, 640, 480, 0, 0, 0, 0);
6901 ddraw
= create_ddraw();
6902 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6903 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6905 skip("Failed to create a 3D device, skipping test.\n");
6906 DestroyWindow(window
);
6910 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
6911 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
6913 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6914 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6916 viewport
= create_viewport(device
, 0, 0, 640, 480);
6917 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6918 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6920 material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
6921 viewport_set_background(device
, viewport
, material
);
6923 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6924 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6926 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
6927 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
6928 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
6929 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
6930 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
6931 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
6932 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
6933 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
6934 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
6935 ok(SUCCEEDED(hr
), "Failed to disable zbuffer, hr %#x.\n", hr
);
6936 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
6937 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
6938 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
6939 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
6941 hr
= IDirect3DDevice2_BeginScene(device
);
6942 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6944 /* There is no D3DRENDERSTATE_LIGHTING on ddraw < 7. */
6945 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
6946 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6947 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_LVERTEX
, unlitquad
,
6949 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6951 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
6952 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
6953 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_LVERTEX
, litquad
,
6955 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6957 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
6958 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6959 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, unlitnquad
,
6961 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6963 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
6964 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6965 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, litnquad
,
6967 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6969 hr
= IDirect3DDevice2_EndScene(device
);
6970 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6972 color
= get_surface_color(rt
, 160, 360);
6973 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color
);
6974 color
= get_surface_color(rt
, 160, 120);
6975 ok(color
== 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color
);
6976 color
= get_surface_color(rt
, 480, 360);
6977 ok(color
== 0x00ffffff, "Unlit quad with normals has color 0x%08x.\n", color
);
6978 color
= get_surface_color(rt
, 480, 120);
6979 ok(color
== 0x00ffffff, "Lit quad with normals has color 0x%08x.\n", color
);
6981 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6982 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6983 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6984 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6986 hr
= IDirect3D2_CreateLight(d3d
, &light
, NULL
);
6987 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
6988 memset(&light_desc
, 0, sizeof(light_desc
));
6989 light_desc
.dwSize
= sizeof(light_desc
);
6990 light_desc
.dltType
= D3DLIGHT_DIRECTIONAL
;
6991 U1(light_desc
.dcvColor
).r
= 0.0f
;
6992 U2(light_desc
.dcvColor
).g
= 0.0f
;
6993 U3(light_desc
.dcvColor
).b
= 1.0f
;
6994 U4(light_desc
.dcvColor
).a
= 1.0f
;
6995 U3(light_desc
.dvDirection
).z
= 1.0f
;
6996 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
6997 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
6998 hr
= IDirect3DViewport2_AddLight(viewport
, light
);
6999 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
7001 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7002 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7004 hr
= IDirect3DDevice2_BeginScene(device
);
7005 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7007 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, nquad
,
7009 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7011 hr
= IDirect3DDevice2_EndScene(device
);
7012 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7014 color
= get_surface_color(rt
, 320, 240);
7015 ok(color
== 0x00000000, "Lit quad with no light has color 0x%08x.\n", color
);
7017 light_desc
.dwFlags
= D3DLIGHT_ACTIVE
;
7018 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
7019 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
7021 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
7023 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, tests
[i
].world_matrix
);
7024 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
7026 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7027 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7029 hr
= IDirect3DDevice2_BeginScene(device
);
7030 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7032 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
,
7033 tests
[i
].quad
, 4, indices
, 6, 0);
7034 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7036 hr
= IDirect3DDevice2_EndScene(device
);
7037 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7039 color
= get_surface_color(rt
, 320, 240);
7040 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
7043 hr
= IDirect3DViewport2_DeleteLight(viewport
, light
);
7044 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
7045 IDirect3DLight_Release(light
);
7046 destroy_material(material
);
7047 destroy_viewport(device
, viewport
);
7048 IDirectDrawSurface2_Release(rt
);
7049 refcount
= IDirect3DDevice2_Release(device
);
7050 ok(!refcount
, "Device has %u references left.\n", refcount
);
7051 IDirect3D2_Release(d3d
);
7052 refcount
= IDirectDraw2_Release(ddraw
);
7053 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
7054 DestroyWindow(window
);
7057 static void test_specular_lighting(void)
7059 static const unsigned int vertices_side
= 5;
7060 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
7061 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7062 static D3DMATRIX mat
=
7064 1.0f
, 0.0f
, 0.0f
, 0.0f
,
7065 0.0f
, 1.0f
, 0.0f
, 0.0f
,
7066 0.0f
, 0.0f
, 1.0f
, 0.0f
,
7067 0.0f
, 0.0f
, 0.0f
, 1.0f
,
7069 static D3DLIGHT2 directional
=
7072 D3DLIGHT_DIRECTIONAL
,
7073 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7074 {{0.0f
}, {0.0f
}, {0.0f
}},
7075 {{0.0f
}, {0.0f
}, {1.0f
}},
7081 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7082 {{0.0f
}, {0.0f
}, {0.0f
}},
7083 {{0.0f
}, {0.0f
}, {0.0f
}},
7092 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7093 {{0.0f
}, {0.0f
}, {0.0f
}},
7094 {{0.0f
}, {0.0f
}, {1.0f
}},
7098 M_PI
/ 12.0f
, M_PI
/ 3.0f
7103 D3DLIGHT_PARALLELPOINT
,
7104 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7105 {{0.5f
}, {0.0f
}, {-1.0f
}},
7106 {{0.0f
}, {0.0f
}, {0.0f
}},
7108 static const struct expected_color
7113 expected_directional_local
[] =
7115 {160, 120, 0x003c3c3c},
7116 {320, 120, 0x00717171},
7117 {480, 120, 0x003c3c3c},
7118 {160, 240, 0x00717171},
7119 {320, 240, 0x00ffffff},
7120 {480, 240, 0x00717171},
7121 {160, 360, 0x003c3c3c},
7122 {320, 360, 0x00717171},
7123 {480, 360, 0x003c3c3c},
7125 expected_point_local
[] =
7127 {160, 120, 0x00000000},
7128 {320, 120, 0x00090909},
7129 {480, 120, 0x00000000},
7130 {160, 240, 0x00090909},
7131 {320, 240, 0x00fafafa},
7132 {480, 240, 0x00090909},
7133 {160, 360, 0x00000000},
7134 {320, 360, 0x00090909},
7135 {480, 360, 0x00000000},
7137 expected_spot_local
[] =
7139 {160, 120, 0x00000000},
7140 {320, 120, 0x00020202},
7141 {480, 120, 0x00000000},
7142 {160, 240, 0x00020202},
7143 {320, 240, 0x00fafafa},
7144 {480, 240, 0x00020202},
7145 {160, 360, 0x00000000},
7146 {320, 360, 0x00020202},
7147 {480, 360, 0x00000000},
7149 expected_parallelpoint
[] =
7151 {160, 120, 0x00050505},
7152 {320, 120, 0x002c2c2c},
7153 {480, 120, 0x006e6e6e},
7154 {160, 240, 0x00090909},
7155 {320, 240, 0x00717171},
7156 {480, 240, 0x00ffffff},
7157 {160, 360, 0x00050505},
7158 {320, 360, 0x002c2c2c},
7159 {480, 360, 0x006e6e6e},
7164 const struct expected_color
*expected
;
7165 unsigned int expected_count
;
7169 {&directional
, expected_directional_local
,
7170 sizeof(expected_directional_local
) / sizeof(expected_directional_local
[0])},
7171 {&point
, expected_point_local
,
7172 sizeof(expected_point_local
) / sizeof(expected_point_local
[0])},
7173 {&spot
, expected_spot_local
,
7174 sizeof(expected_spot_local
) / sizeof(expected_spot_local
[0])},
7175 {¶llelpoint
, expected_parallelpoint
,
7176 sizeof(expected_parallelpoint
) / sizeof(expected_parallelpoint
[0])},
7179 IDirect3DDevice2
*device
;
7180 IDirectDraw2
*ddraw
;
7181 IDirectDrawSurface
*rt
;
7182 IDirect3DViewport2
*viewport
;
7183 IDirect3DMaterial2
*material
, *background_material
;
7184 IDirect3DLight
*light
;
7185 D3DMATERIALHANDLE mat_handle
;
7190 unsigned int i
, j
, x
, y
;
7194 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7195 0, 0, 640, 480, 0, 0, 0, 0);
7196 ddraw
= create_ddraw();
7197 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7198 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
7200 skip("Failed to create a 3D device, skipping test.\n");
7201 DestroyWindow(window
);
7205 quad
= HeapAlloc(GetProcessHeap(), 0, vertices_side
* vertices_side
* sizeof(*quad
));
7206 indices
= HeapAlloc(GetProcessHeap(), 0, indices_count
* sizeof(*indices
));
7207 for (i
= 0, y
= 0; y
< vertices_side
; ++y
)
7209 for (x
= 0; x
< vertices_side
; ++x
)
7211 U1(quad
[i
]).x
= x
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
7212 U2(quad
[i
]).y
= y
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
7213 U3(quad
[i
]).z
= 1.0f
;
7214 U4(quad
[i
]).nx
= 0.0f
;
7215 U5(quad
[i
]).ny
= 0.0f
;
7216 U6(quad
[i
]).nz
= -1.0f
;
7217 U7(quad
[i
]).tu
= 0.0f
;
7218 U8(quad
[i
++]).tv
= 0.0f
;
7221 for (i
= 0, y
= 0; y
< (vertices_side
- 1); ++y
)
7223 for (x
= 0; x
< (vertices_side
- 1); ++x
)
7225 indices
[i
++] = y
* vertices_side
+ x
+ 1;
7226 indices
[i
++] = y
* vertices_side
+ x
;
7227 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
7228 indices
[i
++] = y
* vertices_side
+ x
+ 1;
7229 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
7230 indices
[i
++] = (y
+ 1) * vertices_side
+ x
+ 1;
7234 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
7235 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
7237 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
7238 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
7240 viewport
= create_viewport(device
, 0, 0, 640, 480);
7241 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
7242 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
7244 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
7245 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
7246 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
7247 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
7248 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
7249 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
7250 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
7251 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
7252 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
7253 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
7254 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
7255 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
7257 background_material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
7258 viewport_set_background(device
, viewport
, background_material
);
7260 material
= create_specular_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 30.0f
);
7261 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
7262 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
7263 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
7264 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
7266 hr
= IDirect3D2_CreateLight(d3d
, &light
, NULL
);
7267 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
7268 hr
= IDirect3DViewport2_AddLight(viewport
, light
);
7269 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
7271 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, TRUE
);
7272 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
7274 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
7276 tests
[i
].light
->dwFlags
= D3DLIGHT_ACTIVE
;
7277 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)tests
[i
].light
);
7278 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
7280 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7281 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7283 hr
= IDirect3DDevice2_BeginScene(device
);
7284 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7286 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
,
7287 quad
, vertices_side
* vertices_side
, indices
, indices_count
, 0);
7288 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7290 hr
= IDirect3DDevice2_EndScene(device
);
7291 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7293 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
7295 color
= get_surface_color(rt
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
7296 ok(compare_color(color
, tests
[i
].expected
[j
].color
, 1),
7297 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
7298 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
7299 tests
[i
].expected
[j
].y
, color
, i
);
7303 hr
= IDirect3DViewport2_DeleteLight(viewport
, light
);
7304 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
7305 IDirect3DLight_Release(light
);
7306 destroy_material(material
);
7307 destroy_material(background_material
);
7308 destroy_viewport(device
, viewport
);
7309 IDirectDrawSurface2_Release(rt
);
7310 refcount
= IDirect3DDevice2_Release(device
);
7311 ok(!refcount
, "Device has %u references left.\n", refcount
);
7312 IDirect3D2_Release(d3d
);
7313 refcount
= IDirectDraw2_Release(ddraw
);
7314 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
7315 DestroyWindow(window
);
7316 HeapFree(GetProcessHeap(), 0, indices
);
7317 HeapFree(GetProcessHeap(), 0, quad
);
7320 static void test_palette_gdi(void)
7322 IDirectDrawSurface
*surface
, *primary
;
7323 DDSURFACEDESC surface_desc
;
7324 IDirectDraw2
*ddraw
;
7325 IDirectDrawPalette
*palette
, *palette2
;
7329 PALETTEENTRY palette_entries
[256];
7335 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7336 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7337 * not the point of this test. */
7338 static const RGBQUAD expected1
[] =
7340 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7341 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7343 static const RGBQUAD expected2
[] =
7345 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7346 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7348 static const RGBQUAD expected3
[] =
7350 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7351 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7353 HPALETTE ddraw_palette_handle
;
7354 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7355 RGBQUAD rgbquad
[255];
7356 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
7358 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7359 0, 0, 640, 480, 0, 0, 0, 0);
7360 ddraw
= create_ddraw();
7361 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7362 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7363 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7365 memset(&surface_desc
, 0, sizeof(surface_desc
));
7366 surface_desc
.dwSize
= sizeof(surface_desc
);
7367 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7368 surface_desc
.dwWidth
= 16;
7369 surface_desc
.dwHeight
= 16;
7370 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7371 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7372 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7373 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
7374 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7375 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7377 /* Avoid colors from the Windows default palette. */
7378 memset(palette_entries
, 0, sizeof(palette_entries
));
7379 palette_entries
[1].peRed
= 0x01;
7380 palette_entries
[2].peGreen
= 0x02;
7381 palette_entries
[3].peBlue
= 0x03;
7382 palette_entries
[4].peRed
= 0x13;
7383 palette_entries
[4].peGreen
= 0x14;
7384 palette_entries
[4].peBlue
= 0x15;
7385 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7386 palette_entries
, &palette
, NULL
);
7387 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7389 /* If there is no palette assigned and the display mode is not 8 bpp, some
7390 * drivers refuse to create a DC while others allow it. If a DC is created,
7391 * the DIB color table is uninitialized and contains random colors. No error
7392 * is generated when trying to read pixels and random garbage is returned.
7394 * The most likely explanation is that if the driver creates a DC, it (or
7395 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7396 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7397 * contains uninitialized garbage. See comments below for the P8 case. */
7399 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
7400 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7401 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7402 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7403 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7404 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7405 "Got unexpected palette %p, expected %p.\n",
7406 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7408 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7409 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7410 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
7412 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
7413 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7414 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7415 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
7417 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7419 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7420 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7421 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7424 /* Update the palette while the DC is in use. This does not modify the DC. */
7425 palette_entries
[4].peRed
= 0x23;
7426 palette_entries
[4].peGreen
= 0x24;
7427 palette_entries
[4].peBlue
= 0x25;
7428 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
7429 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
7431 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7432 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7433 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7434 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7435 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7436 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7438 /* Neither does re-setting the palette. */
7439 hr
= IDirectDrawSurface_SetPalette(surface
, NULL
);
7440 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7441 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
7442 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7444 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7445 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7446 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7447 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7448 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7449 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7451 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7452 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7454 /* Refresh the DC. This updates the palette. */
7455 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7456 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7457 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7458 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7459 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7461 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7462 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7463 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7464 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7466 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7468 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7469 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7470 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7472 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7473 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7475 refcount
= IDirectDrawSurface_Release(surface
);
7476 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7478 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
7479 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7480 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7482 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7483 IDirectDrawPalette_Release(palette
);
7484 IDirectDraw2_Release(ddraw
);
7485 DestroyWindow(window
);
7488 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
7490 memset(&surface_desc
, 0, sizeof(surface_desc
));
7491 surface_desc
.dwSize
= sizeof(surface_desc
);
7492 surface_desc
.dwFlags
= DDSD_CAPS
;
7493 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7494 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
7495 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7497 memset(&fx
, 0, sizeof(fx
));
7498 fx
.dwSize
= sizeof(fx
);
7499 U5(fx
).dwFillColor
= 3;
7500 SetRect(&r
, 0, 0, 319, 479);
7501 hr
= IDirectDrawSurface_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7502 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
7503 SetRect(&r
, 320, 0, 639, 479);
7504 U5(fx
).dwFillColor
= 4;
7505 hr
= IDirectDrawSurface_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7506 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
7508 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
7509 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7510 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
7511 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7513 color
= GetPixel(dc
, 160, 240);
7514 ok(color
== 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color
);
7515 color
= GetPixel(dc
, 480, 240);
7516 ok(color
== 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color
);
7518 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7519 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7520 "Got unexpected palette %p, expected %p.\n",
7521 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7522 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
7524 /* The primary uses the system palette. In exclusive mode, the system palette matches
7525 * the ddraw palette attached to the primary, so the result is what you would expect
7526 * from a regular surface. Tests for the interaction between the ddraw palette and
7527 * the system palette are not included pending an application that depends on this.
7528 * The relation between those causes problems on Windows Vista and newer for games
7529 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
7530 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7531 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7532 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7534 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7535 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7536 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7537 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7539 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7541 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7542 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7543 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7545 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
7546 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7548 memset(&surface_desc
, 0, sizeof(surface_desc
));
7549 surface_desc
.dwSize
= sizeof(surface_desc
);
7550 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7551 surface_desc
.dwWidth
= 16;
7552 surface_desc
.dwHeight
= 16;
7553 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7554 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7555 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7557 /* Here the offscreen surface appears to use the primary's palette,
7558 * but in all likelihood it is actually the system palette. */
7559 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7560 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7561 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7562 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7563 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7565 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7566 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7567 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7568 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7570 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7572 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7573 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7574 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7576 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7577 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7579 /* On real hardware a change to the primary surface's palette applies immediately,
7580 * even on device contexts from offscreen surfaces that do not have their own
7581 * palette. On the testbot VMs this is not the case. Don't test this until we
7582 * know of an application that depends on this. */
7584 memset(palette_entries
, 0, sizeof(palette_entries
));
7585 palette_entries
[1].peBlue
= 0x40;
7586 palette_entries
[2].peRed
= 0x40;
7587 palette_entries
[3].peGreen
= 0x40;
7588 palette_entries
[4].peRed
= 0x12;
7589 palette_entries
[4].peGreen
= 0x34;
7590 palette_entries
[4].peBlue
= 0x56;
7591 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7592 palette_entries
, &palette2
, NULL
);
7593 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7594 hr
= IDirectDrawSurface_SetPalette(surface
, palette2
);
7595 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7597 /* A palette assigned to the offscreen surface overrides the primary / system
7599 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7600 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7601 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7602 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7603 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
7605 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
7606 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7607 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7608 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
7610 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7612 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7613 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7614 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7616 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7617 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7619 refcount
= IDirectDrawSurface_Release(surface
);
7620 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7622 /* The Windows 8 testbot keeps extra references to the primary and
7623 * backbuffer while in 8 bpp mode. */
7624 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
7625 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7627 refcount
= IDirectDrawSurface_Release(primary
);
7628 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7629 refcount
= IDirectDrawPalette_Release(palette2
);
7630 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7631 refcount
= IDirectDrawPalette_Release(palette
);
7632 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7633 refcount
= IDirectDraw2_Release(ddraw
);
7634 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7635 DestroyWindow(window
);
7638 static void test_palette_alpha(void)
7640 IDirectDrawSurface
*surface1
;
7641 IDirectDrawSurface2
*surface
;
7642 DDSURFACEDESC surface_desc
;
7643 IDirectDraw2
*ddraw
;
7644 IDirectDrawPalette
*palette
;
7648 PALETTEENTRY palette_entries
[256];
7653 BOOL attach_allowed
;
7658 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
7659 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
7660 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
7663 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7664 0, 0, 640, 480, 0, 0, 0, 0);
7665 ddraw
= create_ddraw();
7666 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7667 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7669 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7670 IDirectDraw2_Release(ddraw
);
7671 DestroyWindow(window
);
7674 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7675 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7677 memset(palette_entries
, 0, sizeof(palette_entries
));
7678 palette_entries
[1].peFlags
= 0x42;
7679 palette_entries
[2].peFlags
= 0xff;
7680 palette_entries
[3].peFlags
= 0x80;
7681 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
7682 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7684 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7685 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7686 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7687 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7688 palette_entries
[0].peFlags
);
7689 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7690 palette_entries
[1].peFlags
);
7691 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7692 palette_entries
[2].peFlags
);
7693 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7694 palette_entries
[3].peFlags
);
7696 IDirectDrawPalette_Release(palette
);
7698 memset(palette_entries
, 0, sizeof(palette_entries
));
7699 palette_entries
[1].peFlags
= 0x42;
7700 palette_entries
[1].peRed
= 0xff;
7701 palette_entries
[2].peFlags
= 0xff;
7702 palette_entries
[3].peFlags
= 0x80;
7703 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
7704 palette_entries
, &palette
, NULL
);
7705 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7707 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7708 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7709 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7710 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7711 palette_entries
[0].peFlags
);
7712 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7713 palette_entries
[1].peFlags
);
7714 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7715 palette_entries
[2].peFlags
);
7716 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7717 palette_entries
[3].peFlags
);
7719 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
7721 memset(&surface_desc
, 0, sizeof(surface_desc
));
7722 surface_desc
.dwSize
= sizeof(surface_desc
);
7723 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
7724 surface_desc
.dwWidth
= 128;
7725 surface_desc
.dwHeight
= 128;
7726 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
7727 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7728 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7729 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
7730 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
7731 IDirectDrawSurface_Release(surface1
);
7733 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
7734 if (test_data
[i
].attach_allowed
)
7735 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7737 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7745 hr
= IDirectDrawSurface2_GetDC(surface
, &dc
);
7746 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_CANTCREATEDC
) /* Win2k testbot */,
7747 "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7750 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
7751 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
7752 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
7753 rgbquad
.rgbRed
, test_data
[i
].name
);
7754 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
7755 rgbquad
.rgbGreen
, test_data
[i
].name
);
7756 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
7757 rgbquad
.rgbBlue
, test_data
[i
].name
);
7758 ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
7759 rgbquad
.rgbReserved
, test_data
[i
].name
);
7760 hr
= IDirectDrawSurface2_ReleaseDC(surface
, dc
);
7761 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7764 IDirectDrawSurface2_Release(surface
);
7767 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
7768 memset(&surface_desc
, 0, sizeof(surface_desc
));
7769 surface_desc
.dwSize
= sizeof(surface_desc
);
7770 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7771 surface_desc
.dwWidth
= 128;
7772 surface_desc
.dwHeight
= 128;
7773 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7774 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7775 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7776 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7777 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7778 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7779 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7780 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7781 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7782 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
7783 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
7784 IDirectDrawSurface_Release(surface1
);
7786 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
7787 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
7788 IDirectDrawSurface2_Release(surface
);
7790 /* The Windows 8 testbot keeps extra references to the primary
7791 * while in 8 bpp mode. */
7792 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
7793 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7795 refcount
= IDirectDrawPalette_Release(palette
);
7796 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7797 refcount
= IDirectDraw2_Release(ddraw
);
7798 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7799 DestroyWindow(window
);
7802 static void test_lost_device(void)
7804 IDirectDrawSurface
*surface
;
7805 DDSURFACEDESC surface_desc
;
7806 HWND window1
, window2
;
7807 IDirectDraw2
*ddraw
;
7812 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7813 0, 0, 640, 480, 0, 0, 0, 0);
7814 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7815 0, 0, 640, 480, 0, 0, 0, 0);
7816 ddraw
= create_ddraw();
7817 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7818 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7819 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7821 memset(&surface_desc
, 0, sizeof(surface_desc
));
7822 surface_desc
.dwSize
= sizeof(surface_desc
);
7823 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
7824 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
7825 surface_desc
.dwBackBufferCount
= 1;
7826 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7827 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7829 hr
= IDirectDrawSurface_IsLost(surface
);
7830 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7831 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7832 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7834 ret
= SetForegroundWindow(GetDesktopWindow());
7835 ok(ret
, "Failed to set foreground window.\n");
7836 hr
= IDirectDrawSurface_IsLost(surface
);
7837 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7838 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7839 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7841 ret
= SetForegroundWindow(window1
);
7842 ok(ret
, "Failed to set foreground window.\n");
7843 hr
= IDirectDrawSurface_IsLost(surface
);
7844 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7845 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7846 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7848 hr
= restore_surfaces(ddraw
);
7849 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7850 hr
= IDirectDrawSurface_IsLost(surface
);
7851 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7852 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7853 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7855 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
7856 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7857 hr
= IDirectDrawSurface_IsLost(surface
);
7858 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7859 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7860 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7862 /* Trying to restore the primary will crash, probably because flippable
7863 * surfaces can't exist in DDSCL_NORMAL. */
7864 IDirectDrawSurface_Release(surface
);
7865 memset(&surface_desc
, 0, sizeof(surface_desc
));
7866 surface_desc
.dwSize
= sizeof(surface_desc
);
7867 surface_desc
.dwFlags
= DDSD_CAPS
;
7868 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7869 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7870 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7872 hr
= IDirectDrawSurface_IsLost(surface
);
7873 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7875 ret
= SetForegroundWindow(GetDesktopWindow());
7876 ok(ret
, "Failed to set foreground window.\n");
7877 hr
= IDirectDrawSurface_IsLost(surface
);
7878 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7880 ret
= SetForegroundWindow(window1
);
7881 ok(ret
, "Failed to set foreground window.\n");
7882 hr
= IDirectDrawSurface_IsLost(surface
);
7883 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7885 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7886 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7887 hr
= IDirectDrawSurface_IsLost(surface
);
7888 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7890 hr
= restore_surfaces(ddraw
);
7891 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7892 hr
= IDirectDrawSurface_IsLost(surface
);
7893 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7895 IDirectDrawSurface_Release(surface
);
7896 memset(&surface_desc
, 0, sizeof(surface_desc
));
7897 surface_desc
.dwSize
= sizeof(surface_desc
);
7898 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
7899 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
7900 surface_desc
.dwBackBufferCount
= 1;
7901 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7902 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7904 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7905 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7906 hr
= IDirectDrawSurface_IsLost(surface
);
7907 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7908 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7909 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7911 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
7912 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7913 hr
= IDirectDrawSurface_IsLost(surface
);
7914 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7915 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7916 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7918 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
7919 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7920 hr
= IDirectDrawSurface_IsLost(surface
);
7921 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7922 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7923 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7925 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
7926 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7927 hr
= IDirectDrawSurface_IsLost(surface
);
7928 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7929 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7930 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7932 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
7933 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7934 hr
= IDirectDrawSurface_IsLost(surface
);
7935 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7936 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7937 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7939 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7940 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7941 hr
= IDirectDrawSurface_IsLost(surface
);
7942 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7943 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7944 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7946 IDirectDrawSurface_Release(surface
);
7947 refcount
= IDirectDraw2_Release(ddraw
);
7948 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7949 DestroyWindow(window2
);
7950 DestroyWindow(window1
);
7953 static void test_surface_desc_lock(void)
7955 IDirectDrawSurface
*surface
;
7956 DDSURFACEDESC surface_desc
;
7957 IDirectDraw2
*ddraw
;
7962 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7963 0, 0, 640, 480, 0, 0, 0, 0);
7964 ddraw
= create_ddraw();
7965 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7966 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7967 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7969 memset(&surface_desc
, 0, sizeof(surface_desc
));
7970 surface_desc
.dwSize
= sizeof(surface_desc
);
7971 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7972 surface_desc
.dwWidth
= 16;
7973 surface_desc
.dwHeight
= 16;
7974 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7975 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7976 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7978 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7979 surface_desc
.dwSize
= sizeof(surface_desc
);
7980 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7981 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7982 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7984 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7985 surface_desc
.dwSize
= sizeof(surface_desc
);
7986 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7987 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7988 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7989 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7990 surface_desc
.dwSize
= sizeof(surface_desc
);
7991 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7992 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7993 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7994 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
7995 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7997 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7998 surface_desc
.dwSize
= sizeof(surface_desc
);
7999 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
8000 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8001 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8003 IDirectDrawSurface_Release(surface
);
8004 refcount
= IDirectDraw2_Release(ddraw
);
8005 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8006 DestroyWindow(window
);
8009 static void test_texturemapblend(void)
8014 static RECT rect
= {0, 0, 64, 128};
8015 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8017 IDirectDrawSurface
*surface
, *rt
;
8018 IDirect3DTexture2
*texture
;
8019 D3DTEXTUREHANDLE texture_handle
;
8021 IDirectDraw2
*ddraw
;
8022 IDirect3DDevice2
*device
;
8023 IDirect3DMaterial2
*material
;
8024 IDirect3DViewport2
*viewport
;
8028 static D3DTLVERTEX test1_quads
[] =
8030 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {0.0f
}},
8031 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {1.0f
}},
8032 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {0.0f
}},
8033 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {1.0f
}},
8034 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {0.0f
}},
8035 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {1.0f
}},
8036 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {0.0f
}},
8037 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {1.0f
}},
8041 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {0.0f
}},
8042 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {1.0f
}},
8043 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {0.0f
}},
8044 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {1.0f
}},
8045 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {0.0f
}},
8046 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {1.0f
}},
8047 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {0.0f
}},
8048 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {1.0f
}},
8051 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8052 0, 0, 640, 480, 0, 0, 0, 0);
8053 ddraw
= create_ddraw();
8054 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8055 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8057 skip("Failed to create a 3D device, skipping test.\n");
8058 DestroyWindow(window
);
8059 IDirectDraw2_Release(ddraw
);
8063 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8064 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8066 material
= create_diffuse_material(device
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
8067 viewport
= create_viewport(device
, 0, 0, 640, 480);
8068 viewport_set_background(device
, viewport
, material
);
8069 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
8070 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
8072 /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel.
8074 * The vertex alpha is completely ignored in this case, so case 1 and 2 combined are not
8075 * a D3DTOP_MODULATE with texture alpha = 0xff in case 2 (no alpha in 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 memset(&fx
, 0, sizeof(fx
));
8103 fx
.dwSize
= sizeof(fx
);
8104 U5(fx
).dwFillColor
= 0xff0000ff;
8105 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8106 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8107 U5(fx
).dwFillColor
= 0x800000ff;
8108 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8109 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8111 /* Note that the ddraw1 version of this test runs tests 1-3 with D3DRENDERSTATE_COLORKEYENABLE
8112 * enabled, whereas this version only runs test 4 with color keying on. Because no color key
8113 * is set on the texture this should not result in different behavior. */
8114 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
8115 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8116 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8117 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8118 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
8119 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8120 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
8121 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8122 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
8123 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8124 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
);
8125 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8127 hr
= IDirect3DDevice2_BeginScene(device
);
8128 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8129 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8130 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8131 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8132 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8133 hr
= IDirect3DDevice2_EndScene(device
);
8134 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8136 color
= get_surface_color(rt
, 5, 5);
8137 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8138 color
= get_surface_color(rt
, 400, 5);
8139 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8140 color
= get_surface_color(rt
, 5, 245);
8141 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8142 color
= get_surface_color(rt
, 400, 245);
8143 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8145 IDirect3DTexture2_Release(texture
);
8146 ref
= IDirectDrawSurface_Release(surface
);
8147 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8149 /* Test alpha with texture that has no alpha channel - alpha should be taken from diffuse vertex color. */
8150 memset(&ddsd
, 0, sizeof(ddsd
));
8151 ddsd
.dwSize
= sizeof(ddsd
);
8152 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8153 ddsd
.dwHeight
= 128;
8155 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8156 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8157 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8158 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8159 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8160 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8161 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8163 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8164 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8166 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8167 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8168 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8169 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8170 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8171 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8173 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8174 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8176 U5(fx
).dwFillColor
= 0xff0000ff;
8177 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8178 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8179 U5(fx
).dwFillColor
= 0x800000ff;
8180 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8181 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8183 hr
= IDirect3DDevice2_BeginScene(device
);
8184 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8185 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8186 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8187 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8188 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8189 hr
= IDirect3DDevice2_EndScene(device
);
8190 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8192 color
= get_surface_color(rt
, 5, 5);
8193 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8194 color
= get_surface_color(rt
, 400, 5);
8195 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8196 color
= get_surface_color(rt
, 5, 245);
8197 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8198 color
= get_surface_color(rt
, 400, 245);
8199 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8201 IDirect3DTexture2_Release(texture
);
8202 ref
= IDirectDrawSurface_Release(surface
);
8203 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8205 /* Test RGB - should multiply color components from diffuse vertex color and texture. */
8206 memset(&ddsd
, 0, sizeof(ddsd
));
8207 ddsd
.dwSize
= sizeof(ddsd
);
8208 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8209 ddsd
.dwHeight
= 128;
8211 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8212 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8213 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
8214 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8215 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8216 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8217 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8218 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
8219 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8220 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8222 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8223 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8224 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8225 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8226 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8227 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8229 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8230 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8232 U5(fx
).dwFillColor
= 0x00ffffff;
8233 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8234 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8235 U5(fx
).dwFillColor
= 0x00ffff80;
8236 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8237 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8239 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
8240 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8242 hr
= IDirect3DDevice2_BeginScene(device
);
8243 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8244 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test2_quads
[0], 4, 0);
8245 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8246 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test2_quads
[4], 4, 0);
8247 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8248 hr
= IDirect3DDevice2_EndScene(device
);
8249 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8251 color
= get_surface_color(rt
, 5, 5);
8252 ok(compare_color(color
, 0x00ff0040, 2), "Got unexpected color 0x%08x.\n", color
);
8253 color
= get_surface_color(rt
, 400, 5);
8254 ok(compare_color(color
, 0x00ff0080, 2), "Got unexpected color 0x%08x.\n", color
);
8255 color
= get_surface_color(rt
, 5, 245);
8256 ok(compare_color(color
, 0x00800080, 2), "Got unexpected color 0x%08x.\n", color
);
8257 color
= get_surface_color(rt
, 400, 245);
8258 ok(compare_color(color
, 0x008000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8260 IDirect3DTexture2_Release(texture
);
8261 ref
= IDirectDrawSurface_Release(surface
);
8262 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8264 /* Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere). */
8265 memset(&ddsd
, 0, sizeof(ddsd
));
8266 ddsd
.dwSize
= sizeof(ddsd
);
8267 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8268 ddsd
.dwHeight
= 128;
8270 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8271 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8272 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8273 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 16;
8274 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
8275 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
8276 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
8278 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8279 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8281 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8282 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8283 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8284 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8285 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8286 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8288 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8289 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8291 U5(fx
).dwFillColor
= 0xf800;
8292 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8293 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8294 U5(fx
).dwFillColor
= 0x001f;
8295 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8296 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8298 ckey
.dwColorSpaceLowValue
= 0x001f;
8299 ckey
.dwColorSpaceHighValue
= 0x001f;
8300 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8301 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8303 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
8304 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8305 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
8306 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8308 hr
= IDirect3DDevice2_BeginScene(device
);
8309 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8310 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8311 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8312 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8313 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8314 hr
= IDirect3DDevice2_EndScene(device
);
8315 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8317 color
= get_surface_color(rt
, 5, 5);
8318 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
8319 color
= get_surface_color(rt
, 400, 5);
8320 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
8321 color
= get_surface_color(rt
, 5, 245);
8322 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
8323 color
= get_surface_color(rt
, 400, 245);
8324 ok(compare_color(color
, 0x00800000, 2), "Got unexpected color 0x%08x.\n", color
);
8326 IDirect3DTexture2_Release(texture
);
8327 ref
= IDirectDrawSurface_Release(surface
);
8328 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8330 destroy_viewport(device
, viewport
);
8331 ref
= IDirect3DMaterial2_Release(material
);
8332 ok(ref
== 0, "Material not properly released, refcount %u.\n", ref
);
8333 IDirectDrawSurface_Release(rt
);
8334 IDirect3DDevice2_Release(device
);
8335 ref
= IDirectDraw2_Release(ddraw
);
8336 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
8337 DestroyWindow(window
);
8340 static void test_viewport_clear_rect(void)
8343 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8344 static D3DRECT clear_rect2
= {{90}, {90}, {110}, {110}};
8345 IDirectDrawSurface
*rt
;
8347 IDirectDraw2
*ddraw
;
8348 IDirect3DDevice2
*device
;
8349 IDirect3DMaterial2
*red
, *green
;
8350 IDirect3DViewport2
*viewport
, *viewport2
;
8354 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8355 0, 0, 640, 480, 0, 0, 0, 0);
8356 ddraw
= create_ddraw();
8357 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8358 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8360 skip("Failed to create a 3D device, skipping test.\n");
8361 DestroyWindow(window
);
8362 IDirectDraw2_Release(ddraw
);
8366 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8367 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8369 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
8370 viewport
= create_viewport(device
, 0, 0, 640, 480);
8371 viewport_set_background(device
, viewport
, red
);
8372 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8373 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8375 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
8376 viewport2
= create_viewport(device
, 100, 100, 20, 20);
8377 viewport_set_background(device
, viewport2
, green
);
8378 hr
= IDirect3DViewport2_Clear(viewport2
, 1, &clear_rect2
, D3DCLEAR_TARGET
);
8379 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8381 color
= get_surface_color(rt
, 85, 85); /* Outside both. */
8382 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8383 color
= get_surface_color(rt
, 95, 95); /* Outside vp, inside rect. */
8384 /* AMD GPUs ignore the viewport dimensions and only care about the rectangle. */
8385 ok(compare_color(color
, 0x00ff0000, 1) || broken(compare_color(color
, 0x0000ff00, 1)),
8386 "Got unexpected color 0x%08x.\n", color
);
8387 color
= get_surface_color(rt
, 105, 105); /* Inside both. */
8388 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
8389 color
= get_surface_color(rt
, 115, 115); /* Inside vp, outside rect. */
8390 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8391 color
= get_surface_color(rt
, 125, 125); /* Outside both. */
8392 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8394 destroy_viewport(device
, viewport2
);
8395 destroy_material(green
);
8396 destroy_viewport(device
, viewport
);
8397 destroy_material(red
);
8398 IDirectDrawSurface_Release(rt
);
8399 IDirect3DDevice2_Release(device
);
8400 ref
= IDirectDraw2_Release(ddraw
);
8401 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
8402 DestroyWindow(window
);
8405 static void test_color_fill(void)
8408 IDirect3DDevice2
*device
;
8409 IDirectDraw2
*ddraw
;
8410 IDirectDrawSurface
*surface
, *surface2
;
8411 DDSURFACEDESC surface_desc
;
8417 RECT rect
= {5, 5, 7, 7};
8419 DWORD num_fourcc_codes
, *fourcc_codes
;
8421 BOOL support_uyvy
= FALSE
, support_yuy2
= FALSE
;
8425 HRESULT colorfill_hr
, depthfill_hr
;
8430 DDPIXELFORMAT format
;
8435 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8436 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8438 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8439 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8443 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
8444 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8446 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8447 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8451 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
8452 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
8454 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8455 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8459 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
8460 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
8462 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8463 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8467 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
,
8468 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0xdeadbeef, TRUE
,
8469 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
8472 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
8473 * different afterwards. DX9+ GPUs set one of the two luminance values
8474 * in each block, but AMD and Nvidia GPUs disagree on which luminance
8475 * value they set. r200 (dx8) just sets the entire block to the clear
8477 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8478 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
8480 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8481 {0}, {0}, {0}, {0}, {0}
8485 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8486 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
8488 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8489 {0}, {0}, {0}, {0}, {0}
8493 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
8494 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
8496 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8497 {0}, {0}, {0}, {0}, {0}
8501 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
8502 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
8504 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8505 {0}, {0}, {0}, {0}, {0}
8509 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
8510 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
8512 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8513 {0}, {0}, {0}, {0}, {0}
8517 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
8518 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
8520 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8521 {0}, {0}, {0}, {0}, {0}
8525 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
8526 * surface works, presumably because it is handled by the runtime instead of
8528 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8529 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
8531 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
8532 {8}, {0}, {0}, {0}, {0}
8536 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
8537 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
8539 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
8540 {8}, {0}, {0}, {0}, {0}
8552 {SRCCOPY
, "SRCCOPY", DD_OK
},
8553 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
8554 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
8555 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
8556 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
8557 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
8558 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
8559 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
8560 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
8561 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
8562 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
8563 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
8564 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
8565 {BLACKNESS
, "BLACKNESS", DD_OK
},
8566 {WHITENESS
, "WHITENESS", DD_OK
},
8567 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
8570 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8571 0, 0, 640, 480, 0, 0, 0, 0);
8572 ddraw
= create_ddraw();
8573 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8574 is_warp
= ddraw_is_warp(ddraw
);
8575 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8577 skip("Failed to create a 3D device, skipping test.\n");
8578 DestroyWindow(window
);
8579 IDirectDraw2_Release(ddraw
);
8583 hr
= IDirectDraw2_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
8584 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
8585 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
8586 num_fourcc_codes
* sizeof(*fourcc_codes
));
8589 hr
= IDirectDraw2_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
8590 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
8591 for (i
= 0; i
< num_fourcc_codes
; i
++)
8593 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
8594 support_yuy2
= TRUE
;
8595 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
8596 support_uyvy
= TRUE
;
8598 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
8600 memset(&hal_caps
, 0, sizeof(hal_caps
));
8601 hal_caps
.dwSize
= sizeof(hal_caps
);
8602 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
8603 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
8605 if ((!support_yuy2
&& !support_uyvy
) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
8606 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
8608 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
8610 DWORD expected_broken
= tests
[i
].result
;
8611 DWORD mask
= 0xffffffffu
;
8613 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
8614 memset(&fx
, 0, sizeof(fx
));
8615 fx
.dwSize
= sizeof(fx
);
8616 U5(fx
).dwFillColor
= 0xdeadbeef;
8618 memset(&surface_desc
, 0, sizeof(surface_desc
));
8619 surface_desc
.dwSize
= sizeof(surface_desc
);
8620 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8621 surface_desc
.dwWidth
= 64;
8622 surface_desc
.dwHeight
= 64;
8623 surface_desc
.ddpfPixelFormat
= tests
[i
].format
;
8624 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
8626 if (tests
[i
].caps
& DDSCAPS_TEXTURE
)
8628 struct format_support_check check
= {&tests
[i
].format
, FALSE
};
8629 hr
= IDirect3DDevice2_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
8630 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
8631 if (!check
.supported
)
8635 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !support_yuy2
)
8637 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !support_uyvy
)
8639 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
8642 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
8644 surface_desc
.dwFlags
&= ~DDSD_PIXELFORMAT
;
8645 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
8646 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
8647 mask
>>= (32 - U2(surface_desc
).dwZBufferBitDepth
);
8648 /* Some drivers seem to convert depth values incorrectly or not at
8649 * all. Affects at least AMD PALM, 8.17.10.1247. */
8650 if (tests
[i
].caps
& DDSCAPS_VIDEOMEMORY
)
8655 expected
= tests
[i
].result
& mask
;
8656 f
= ceilf(log2f(expected
+ 1.0f
));
8657 g
= (f
+ 1.0f
) / 2.0f
;
8659 expected_broken
= (expected
/ exp2f(f
) - g
) * 256;
8660 expected_broken
*= 0x01010101;
8664 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8665 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8667 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8668 todo_wine_if (tests
[i
].format
.dwFourCC
)
8669 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8670 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8672 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8673 todo_wine_if (tests
[i
].format
.dwFourCC
)
8674 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8675 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8677 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8679 memset(&surface_desc
, 0, sizeof(surface_desc
));
8680 surface_desc
.dwSize
= sizeof(surface_desc
);
8681 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8682 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8683 color
= surface_desc
.lpSurface
;
8684 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
8685 *color
, tests
[i
].result
, tests
[i
].name
);
8686 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8687 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8690 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8691 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8692 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
8693 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8694 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8695 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
8697 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8699 memset(&surface_desc
, 0, sizeof(surface_desc
));
8700 surface_desc
.dwSize
= sizeof(surface_desc
);
8701 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8702 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8703 color
= surface_desc
.lpSurface
;
8704 todo_wine_if(tests
[i
].caps
& DDSCAPS_VIDEOMEMORY
&& U2(surface_desc
).dwZBufferBitDepth
!= 16)
8705 ok((*color
& mask
) == (tests
[i
].result
& mask
) || broken((*color
& mask
) == (expected_broken
& mask
))
8706 || broken(is_warp
&& (*color
& mask
) == (~0u & mask
)) /* Windows 8+ testbot. */,
8707 "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
8708 *color
& mask
, tests
[i
].result
& mask
, tests
[i
].name
);
8709 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8710 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8713 U5(fx
).dwFillColor
= 0xdeadbeef;
8714 fx
.dwROP
= BLACKNESS
;
8715 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8716 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
8717 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
8718 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8719 U5(fx
).dwFillColor
, tests
[i
].name
);
8721 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8723 memset(&surface_desc
, 0, sizeof(surface_desc
));
8724 surface_desc
.dwSize
= sizeof(surface_desc
);
8725 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8726 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8727 color
= surface_desc
.lpSurface
;
8728 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
8729 *color
, tests
[i
].name
);
8730 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8731 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8734 fx
.dwROP
= WHITENESS
;
8735 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8736 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
8737 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
8738 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8739 U5(fx
).dwFillColor
, tests
[i
].name
);
8741 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8743 memset(&surface_desc
, 0, sizeof(surface_desc
));
8744 surface_desc
.dwSize
= sizeof(surface_desc
);
8745 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8746 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8747 color
= surface_desc
.lpSurface
;
8748 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
8749 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
8750 *color
, tests
[i
].name
);
8751 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8752 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8755 IDirectDrawSurface_Release(surface
);
8758 memset(&fx
, 0, sizeof(fx
));
8759 fx
.dwSize
= sizeof(fx
);
8760 U5(fx
).dwFillColor
= 0xdeadbeef;
8761 fx
.dwROP
= WHITENESS
;
8763 memset(&surface_desc
, 0, sizeof(surface_desc
));
8764 surface_desc
.dwSize
= sizeof(surface_desc
);
8765 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8766 surface_desc
.dwWidth
= 64;
8767 surface_desc
.dwHeight
= 64;
8768 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
8769 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8770 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8771 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8772 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8773 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8774 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
8775 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8776 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8777 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
8778 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8781 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
8782 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8783 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
8784 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8786 /* Unused source rectangle. */
8787 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8788 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8789 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8790 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8792 /* Unused source surface. */
8793 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8794 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8795 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8796 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8797 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8798 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8799 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8800 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8802 /* Inverted destination or source rectangle. */
8803 SetRect(&rect
, 5, 7, 7, 5);
8804 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8805 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8806 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8807 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8808 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8809 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8810 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8811 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8812 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8813 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8815 /* Negative rectangle. */
8816 SetRect(&rect
, -1, -1, 5, 5);
8817 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8818 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8819 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8820 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8821 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8822 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8823 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8824 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8825 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8826 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8828 /* Out of bounds rectangle. */
8829 SetRect(&rect
, 0, 0, 65, 65);
8830 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8831 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8832 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8833 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8835 /* Combine multiple flags. */
8836 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8837 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8838 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8839 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8840 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8841 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8843 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
8845 fx
.dwROP
= rops
[i
].rop
;
8846 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8847 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
8850 IDirectDrawSurface_Release(surface2
);
8851 IDirectDrawSurface_Release(surface
);
8853 memset(&surface_desc
, 0, sizeof(surface_desc
));
8854 surface_desc
.dwSize
= sizeof(surface_desc
);
8855 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_ZBUFFERBITDEPTH
;
8856 surface_desc
.dwWidth
= 64;
8857 surface_desc
.dwHeight
= 64;
8858 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
8859 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
8860 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8861 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8862 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
8863 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8866 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
8867 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8869 /* Unused source rectangle. */
8870 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8871 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8873 /* Unused source surface. */
8874 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8875 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8876 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8877 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8879 /* Inverted destination or source rectangle. */
8880 SetRect(&rect
, 5, 7, 7, 5);
8881 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8882 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8883 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8884 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8885 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8886 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8887 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8888 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8890 /* Negative rectangle. */
8891 SetRect(&rect
, -1, -1, 5, 5);
8892 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8893 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8894 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8895 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8896 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8897 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8898 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8899 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8901 /* Out of bounds rectangle. */
8902 SetRect(&rect
, 0, 0, 65, 65);
8903 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8904 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8906 /* Combine multiple flags. */
8907 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8908 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8910 IDirectDrawSurface_Release(surface2
);
8911 IDirectDrawSurface_Release(surface
);
8914 IDirect3DDevice2_Release(device
);
8915 refcount
= IDirectDraw2_Release(ddraw
);
8916 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
8917 DestroyWindow(window
);
8920 static void test_colorkey_precision(void)
8922 static D3DLVERTEX quad
[] =
8924 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {0.0f
}, {0.0f
}},
8925 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {0.0f
}, {1.0f
}},
8926 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {1.0f
}, {0.0f
}},
8927 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {1.0f
}, {1.0f
}},
8929 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8930 IDirect3DDevice2
*device
;
8931 IDirectDraw2
*ddraw
;
8932 IDirectDrawSurface
*rt
;
8933 IDirect3DViewport2
*viewport
;
8936 IDirectDrawSurface
*src
, *dst
, *texture
;
8937 D3DTEXTUREHANDLE handle
;
8938 IDirect3DTexture2
*d3d_texture
;
8939 IDirect3DMaterial2
*green
;
8940 DDSURFACEDESC surface_desc
, lock_desc
;
8946 DWORD data
[4] = {0}, color_mask
;
8947 BOOL is_nvidia
, is_warp
;
8950 unsigned int max
, shift
, bpp
, clear
;
8958 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE
,
8960 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8961 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
8966 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE
,
8968 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8969 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
8974 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE
,
8976 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8977 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
8982 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE
,
8984 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8985 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
8990 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8991 0, 0, 640, 480, 0, 0, 0, 0);
8992 ddraw
= create_ddraw();
8993 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8994 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8996 skip("Failed to create a 3D device, skipping test.\n");
8997 DestroyWindow(window
);
8998 IDirectDraw2_Release(ddraw
);
9001 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9002 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9004 is_nvidia
= ddraw_is_nvidia(ddraw
);
9005 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
9006 * (color key doesn't match although the values are equal), and a false
9007 * positive when the color key is 0 and the texture contains the value 1.
9008 * I don't want to mark this broken unconditionally since this would
9009 * essentially disable the test on Windows. Also on random occasions
9010 * 254 == 255 and 255 != 255.*/
9011 is_warp
= ddraw_is_warp(ddraw
);
9013 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
9014 viewport
= create_viewport(device
, 0, 0, 640, 480);
9015 viewport_set_background(device
, viewport
, green
);
9016 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
9017 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
9019 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9020 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9021 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
9022 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
9023 /* There's no way to ignore the texture color in d3d2, so multiply the texture color
9024 * with a black vertex color. */
9025 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATEALPHA
);
9026 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9028 memset(&fx
, 0, sizeof(fx
));
9029 fx
.dwSize
= sizeof(fx
);
9030 memset(&lock_desc
, 0, sizeof(lock_desc
));
9031 lock_desc
.dwSize
= sizeof(lock_desc
);
9033 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
9035 if (is_nvidia
&& tests
[t
].skip_nv
)
9037 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests
[t
].name
);
9041 memset(&surface_desc
, 0, sizeof(surface_desc
));
9042 surface_desc
.dwSize
= sizeof(surface_desc
);
9043 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9044 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9045 surface_desc
.dwWidth
= 4;
9046 surface_desc
.dwHeight
= 1;
9047 surface_desc
.ddpfPixelFormat
= tests
[t
].fmt
;
9048 /* Windows XP (at least with the r200 driver, other drivers untested) produces
9049 * garbage when doing color keyed texture->texture blits. */
9050 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
9051 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9052 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
9053 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9055 U5(fx
).dwFillColor
= tests
[t
].clear
;
9056 /* On the w8 testbot (WARP driver) the blit result has different values in the
9058 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
9059 | U3(tests
[t
].fmt
).dwGBitMask
9060 | U4(tests
[t
].fmt
).dwBBitMask
;
9062 for (c
= 0; c
<= tests
[t
].max
; ++c
)
9064 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
9065 * texture after it has been set once... */
9066 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
9067 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9068 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9069 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9070 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
9071 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9073 hr
= IDirectDrawSurface4_QueryInterface(texture
, &IID_IDirect3DTexture2
, (void **)&d3d_texture
);
9074 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9075 hr
= IDirect3DTexture2_GetHandle(d3d_texture
, device
, &handle
);
9076 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
9077 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, handle
);
9078 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
9079 IDirect3DTexture2_Release(d3d_texture
);
9081 hr
= IDirectDrawSurface_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9082 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
9084 hr
= IDirectDrawSurface_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9085 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9086 switch (tests
[t
].bpp
)
9089 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9090 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9091 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9092 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
9096 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9097 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9098 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9099 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
9102 hr
= IDirectDrawSurface_Unlock(src
, 0);
9103 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9104 hr
= IDirectDrawSurface_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
9105 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9107 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9108 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9109 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
9110 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9112 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
9113 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9115 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
9116 hr
= IDirectDrawSurface_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9117 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9118 switch (tests
[t
].bpp
)
9121 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9122 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9123 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9124 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
9128 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9129 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9130 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9131 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
9134 hr
= IDirectDrawSurface_Unlock(dst
, 0);
9135 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9139 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9140 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
9142 if (data
[3] == tests
[t
].clear
)
9144 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
9145 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
9146 * even when a different surface is used. The blit itself doesn't draw anything,
9147 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
9148 * never be masked out by the key.
9150 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
9151 * test is disabled entirely.
9153 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
9154 * terrible on WARP. */
9155 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
9156 IDirectDrawSurface_Release(texture
);
9157 IDirectDrawSurface_Release(src
);
9158 IDirectDrawSurface_Release(dst
);
9163 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9164 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
9166 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9167 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
9169 if (c
== tests
[t
].max
)
9170 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9171 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
9173 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9174 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
9176 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
9177 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9179 hr
= IDirect3DDevice2_BeginScene(device
);
9180 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9181 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
9182 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9183 hr
= IDirect3DDevice2_EndScene(device
);
9184 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9186 color
= get_surface_color(rt
, 80, 240);
9188 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9189 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9190 color
, tests
[t
].name
, c
);
9192 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
9193 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9194 color
, tests
[t
].name
, c
);
9196 color
= get_surface_color(rt
, 240, 240);
9197 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9198 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9199 color
, tests
[t
].name
, c
);
9201 color
= get_surface_color(rt
, 400, 240);
9202 if (c
== tests
[t
].max
)
9203 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9204 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9205 color
, tests
[t
].name
, c
);
9207 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
9208 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9209 color
, tests
[t
].name
, c
);
9211 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
9212 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
9213 IDirectDrawSurface_Release(texture
);
9215 IDirectDrawSurface_Release(src
);
9216 IDirectDrawSurface_Release(dst
);
9220 destroy_viewport(device
, viewport
);
9221 destroy_material(green
);
9222 IDirectDrawSurface_Release(rt
);
9223 IDirect3DDevice2_Release(device
);
9224 refcount
= IDirectDraw2_Release(ddraw
);
9225 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
9226 DestroyWindow(window
);
9229 static void test_range_colorkey(void)
9231 IDirectDraw2
*ddraw
;
9234 IDirectDrawSurface
*surface
;
9235 DDSURFACEDESC surface_desc
;
9239 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9240 0, 0, 640, 480, 0, 0, 0, 0);
9241 ddraw
= create_ddraw();
9242 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9243 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9244 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9246 memset(&surface_desc
, 0, sizeof(surface_desc
));
9247 surface_desc
.dwSize
= sizeof(surface_desc
);
9248 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
9249 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9250 surface_desc
.dwWidth
= 1;
9251 surface_desc
.dwHeight
= 1;
9252 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9253 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
9254 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9255 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9256 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9257 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
9259 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
9260 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9261 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
9262 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9263 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9265 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
9266 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9267 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9268 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9270 /* Same for DDSCAPS_OFFSCREENPLAIN. */
9271 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9272 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9273 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
9274 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9275 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9277 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
9278 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9279 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9280 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9282 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9283 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9284 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9285 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9287 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
9288 ckey
.dwColorSpaceLowValue
= 0x00000000;
9289 ckey
.dwColorSpaceHighValue
= 0x00000001;
9290 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9291 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9293 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9294 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9295 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9296 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9298 ckey
.dwColorSpaceLowValue
= 0x00000001;
9299 ckey
.dwColorSpaceHighValue
= 0x00000000;
9300 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9301 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9303 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9304 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9305 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9306 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9308 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
9309 ckey
.dwColorSpaceLowValue
= 0x00000000;
9310 ckey
.dwColorSpaceHighValue
= 0x00000000;
9311 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9312 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9314 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
9315 ckey
.dwColorSpaceLowValue
= 0x00000001;
9316 ckey
.dwColorSpaceHighValue
= 0x00000000;
9317 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9318 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9319 ckey
.dwColorSpaceLowValue
= 0x00000000;
9320 ckey
.dwColorSpaceHighValue
= 0x00000001;
9321 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9322 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9323 /* Range destination keys don't work either. */
9324 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
9325 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9327 /* Just to show it's not because of A, R, and G having equal values. */
9328 ckey
.dwColorSpaceLowValue
= 0x00000000;
9329 ckey
.dwColorSpaceHighValue
= 0x01010101;
9330 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9331 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9333 /* None of these operations modified the key. */
9334 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9335 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9336 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9337 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9339 IDirectDrawSurface_Release(surface
),
9340 refcount
= IDirectDraw2_Release(ddraw
);
9341 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
9342 DestroyWindow(window
);
9345 static void test_shademode(void)
9347 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9348 IDirect3DMaterial2
*background
;
9349 IDirect3DViewport2
*viewport
;
9350 IDirect3DDevice2
*device
;
9351 IDirectDrawSurface
*rt
;
9352 DWORD color0
, color1
;
9353 IDirectDraw2
*ddraw
;
9359 static D3DLVERTEX quad_strip
[] =
9361 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
9362 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9363 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9364 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
9368 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
9369 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9370 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9372 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9373 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9374 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
9380 DWORD color0
, color1
;
9384 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
9385 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
9386 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
9387 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
9388 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
9389 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
9392 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9393 0, 0, 640, 480, 0, 0, 0, 0);
9394 ddraw
= create_ddraw();
9395 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9396 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9398 skip("Failed to create a 3D device, skipping test.\n");
9399 IDirectDraw2_Release(ddraw
);
9400 DestroyWindow(window
);
9404 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9405 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9407 background
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
9408 viewport
= create_viewport(device
, 0, 0, 640, 480);
9409 viewport_set_background(device
, viewport
, background
);
9410 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
9411 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
9413 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
9414 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
9416 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
9417 * the color fixups we have to do for FLAT shading will be dependent on that. */
9419 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
9421 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
9422 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
9424 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
9425 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
9427 hr
= IDirect3DDevice2_BeginScene(device
);
9428 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9429 quad
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? quad_strip
: quad_list
;
9430 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
9431 hr
= IDirect3DDevice2_DrawPrimitive(device
, tests
[i
].primtype
, D3DVT_LVERTEX
, quad
, count
, 0);
9432 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9433 hr
= IDirect3DDevice2_EndScene(device
);
9434 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9436 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
9437 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
9439 /* For D3DSHADE_FLAT it should take the color of the first vertex of
9440 * each triangle. This requires EXT_provoking_vertex or similar
9441 * functionality being available. */
9442 /* PHONG should be the same as GOURAUD, since no hardware implements
9444 ok(compare_color(color0
, tests
[i
].color0
, 1), "Test %u shading has color0 %08x, expected %08x.\n",
9445 i
, color0
, tests
[i
].color0
);
9446 ok(compare_color(color1
, tests
[i
].color1
, 1), "Test %u shading has color1 %08x, expected %08x.\n",
9447 i
, color1
, tests
[i
].color1
);
9450 destroy_viewport(device
, viewport
);
9451 destroy_material(background
);
9452 IDirectDrawSurface_Release(rt
);
9453 refcount
= IDirect3DDevice2_Release(device
);
9454 ok(!refcount
, "Device has %u references left.\n", refcount
);
9455 IDirectDraw_Release(ddraw
);
9456 DestroyWindow(window
);
9459 static void test_lockrect_invalid(void)
9462 IDirectDraw2
*ddraw
;
9463 IDirectDrawSurface
*surface1
;
9464 IDirectDrawSurface2
*surface
;
9467 DDSURFACEDESC surface_desc
;
9469 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
9470 static RECT valid
[] =
9478 static RECT invalid
[] =
9480 {68, 60, 60, 68}, /* left > right */
9481 {60, 68, 68, 60}, /* top > bottom */
9482 {-8, 60, 0, 68}, /* left < surface */
9483 {60, -8, 68, 0}, /* top < surface */
9484 {-16, 60, -8, 68}, /* right < surface */
9485 {60, -16, 68, -8}, /* bottom < surface */
9486 {60, 60, 136, 68}, /* right > surface */
9487 {60, 60, 68, 136}, /* bottom > surface */
9488 {136, 60, 144, 68}, /* left > surface */
9489 {60, 136, 68, 144}, /* top > surface */
9499 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, "sysmem offscreenplain", DDERR_INVALIDPARAMS
},
9500 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, "vidmem offscreenplain", DDERR_INVALIDPARAMS
},
9501 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, "sysmem texture", DDERR_INVALIDPARAMS
},
9502 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, "vidmem texture", DDERR_INVALIDPARAMS
},
9505 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9506 0, 0, 640, 480, 0, 0, 0, 0);
9507 ddraw
= create_ddraw();
9508 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9509 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9510 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9512 memset(&hal_caps
, 0, sizeof(hal_caps
));
9513 hal_caps
.dwSize
= sizeof(hal_caps
);
9514 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
9515 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9516 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
9518 skip("Required surface types not supported, skipping test.\n");
9522 for (r
= 0; r
< sizeof(resources
) / sizeof(*resources
); ++r
)
9524 memset(&surface_desc
, 0, sizeof(surface_desc
));
9525 surface_desc
.dwSize
= sizeof(surface_desc
);
9526 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9527 surface_desc
.ddsCaps
.dwCaps
= resources
[r
].caps
;
9528 surface_desc
.dwWidth
= 128;
9529 surface_desc
.dwHeight
= 128;
9530 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
9531 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9532 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
9533 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xff0000;
9534 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x00ff00;
9535 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x0000ff;
9537 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
9538 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9539 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
9540 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface2 interface, hr %#x.\n", hr
);
9541 IDirectDrawSurface_Release(surface1
);
9543 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, NULL
, DDLOCK_WAIT
, NULL
);
9544 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
9546 for (i
= 0; i
< sizeof(valid
) / sizeof(*valid
); ++i
)
9548 RECT
*rect
= &valid
[i
];
9550 memset(&surface_desc
, 0, sizeof(surface_desc
));
9551 surface_desc
.dwSize
= sizeof(surface_desc
);
9553 hr
= IDirectDrawSurface2_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9554 ok(SUCCEEDED(hr
), "Lock failed (%#x) for rect %s, type %s.\n",
9555 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
9557 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9558 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9561 for (i
= 0; i
< sizeof(invalid
) / sizeof(*invalid
); ++i
)
9563 RECT
*rect
= &invalid
[i
];
9565 memset(&surface_desc
, 1, sizeof(surface_desc
));
9566 surface_desc
.dwSize
= sizeof(surface_desc
);
9568 hr
= IDirectDrawSurface2_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9569 ok(hr
== resources
[r
].hr
, "Lock returned %#x for rect %s, type %s.\n",
9570 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
9573 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9574 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9577 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
9580 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9581 ok(SUCCEEDED(hr
), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
9582 hr
, resources
[r
].name
);
9583 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9584 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned %#x, type %s.\n",
9585 hr
, resources
[r
].name
);
9586 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9587 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9589 hr
= IDirectDrawSurface2_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
9590 ok(SUCCEEDED(hr
), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid
[0]), hr
);
9591 hr
= IDirectDrawSurface2_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
9592 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = %s) failed (%#x).\n",
9593 wine_dbgstr_rect(&valid
[0]), hr
);
9595 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
9596 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
9598 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9599 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9601 IDirectDrawSurface2_Release(surface
);
9605 IDirectDraw2_Release(ddraw
);
9606 DestroyWindow(window
);
9609 static void test_yv12_overlay(void)
9611 IDirectDrawSurface
*src_surface
, *dst_surface
;
9612 RECT rect
= {13, 17, 14, 18};
9613 unsigned int offset
, y
;
9614 unsigned char *base
;
9615 IDirectDraw2
*ddraw
;
9620 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9621 0, 0, 640, 480, 0, 0, 0, 0);
9622 ddraw
= create_ddraw();
9623 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9624 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9625 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9627 if (!(src_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
9629 skip("Failed to create a YV12 overlay, skipping test.\n");
9633 memset(&desc
, 0, sizeof(desc
));
9634 desc
.dwSize
= sizeof(desc
);
9635 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
9636 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9638 ok(desc
.dwFlags
== (DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_PITCH
),
9639 "Got unexpected flags %#x.\n", desc
.dwFlags
);
9640 ok(desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_HWCODEC
)
9641 || desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
9642 "Got unexpected caps %#x.\n", desc
.ddsCaps
.dwCaps
);
9643 ok(desc
.dwWidth
== 256, "Got unexpected width %u.\n", desc
.dwWidth
);
9644 ok(desc
.dwHeight
== 256, "Got unexpected height %u.\n", desc
.dwHeight
);
9645 /* The overlay pitch seems to have 256 byte alignment. */
9646 ok(!(U1(desc
).lPitch
& 0xff), "Got unexpected pitch %u.\n", U1(desc
).lPitch
);
9648 /* Fill the surface with some data for the blit test. */
9649 base
= desc
.lpSurface
;
9651 for (y
= 0; y
< desc
.dwHeight
; ++y
)
9653 memset(base
+ U1(desc
).lPitch
* y
, 0x10, desc
.dwWidth
);
9656 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 4; ++y
)
9658 memset(base
+ U1(desc
).lPitch
* y
, 0x20, desc
.dwWidth
);
9661 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 2; ++y
)
9663 memset(base
+ U1(desc
).lPitch
* y
, 0x30, desc
.dwWidth
);
9666 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
9667 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9669 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
9670 * other block-based formats like DXT the entire Y channel is stored in
9671 * one big chunk of memory, followed by the chroma channels. So partial
9672 * locks do not really make sense. Show that they are allowed nevertheless
9673 * and the offset points into the luminance data. */
9674 hr
= IDirectDrawSurface_Lock(src_surface
, &rect
, &desc
, DDLOCK_WAIT
, NULL
);
9675 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9676 offset
= ((const unsigned char *)desc
.lpSurface
- base
);
9677 ok(offset
== rect
.top
* U1(desc
).lPitch
+ rect
.left
, "Got unexpected offset %u, expected %u.\n",
9678 offset
, rect
.top
* U1(desc
).lPitch
+ rect
.left
);
9679 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
9680 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9682 if (!(dst_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
9684 /* Windows XP with a Radeon X1600 GPU refuses to create a second
9685 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
9686 skip("Failed to create a second YV12 surface, skipping blit test.\n");
9687 IDirectDrawSurface_Release(src_surface
);
9691 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, NULL
, DDBLT_WAIT
, NULL
);
9692 /* VMware rejects YV12 blits. This behavior has not been seen on real
9693 * hardware yet, so mark it broken. */
9694 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
), "Failed to blit, hr %#x.\n", hr
);
9698 memset(&desc
, 0, sizeof(desc
));
9699 desc
.dwSize
= sizeof(desc
);
9700 hr
= IDirectDrawSurface_Lock(dst_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
9701 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9703 base
= desc
.lpSurface
;
9704 ok(base
[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base
[0]);
9705 base
+= desc
.dwHeight
* U1(desc
).lPitch
;
9706 todo_wine
ok(base
[0] == 0x20, "Got unexpected V data 0x%02x.\n", base
[0]);
9707 base
+= desc
.dwHeight
/ 4 * U1(desc
).lPitch
;
9708 todo_wine
ok(base
[0] == 0x30, "Got unexpected U data 0x%02x.\n", base
[0]);
9710 hr
= IDirectDrawSurface_Unlock(dst_surface
, NULL
);
9711 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9714 IDirectDrawSurface_Release(dst_surface
);
9715 IDirectDrawSurface_Release(src_surface
);
9717 IDirectDraw2_Release(ddraw
);
9718 DestroyWindow(window
);
9721 static BOOL
dwm_enabled(void)
9725 if (!strcmp(winetest_platform
, "wine"))
9727 if (!pDwmIsCompositionEnabled
)
9729 if (FAILED(pDwmIsCompositionEnabled(&ret
)))
9734 static void test_offscreen_overlay(void)
9736 IDirectDrawSurface
*overlay
, *offscreen
, *primary
;
9737 DDSURFACEDESC surface_desc
;
9738 IDirectDraw2
*ddraw
;
9743 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9744 0, 0, 640, 480, 0, 0, 0, 0);
9745 ddraw
= create_ddraw();
9746 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9747 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9748 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9750 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
9752 skip("Failed to create a UYVY overlay, skipping test.\n");
9756 memset(&surface_desc
, 0, sizeof(surface_desc
));
9757 surface_desc
.dwSize
= sizeof(surface_desc
);
9758 surface_desc
.dwFlags
= DDSD_CAPS
;
9759 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
9760 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
9761 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9763 /* On Windows 7, and probably Vista, UpdateOverlay() will return
9764 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
9765 * surface prevents this by disabling the dwm. */
9766 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
9767 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
9768 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
9769 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
9771 /* Try to overlay a NULL surface. */
9772 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_SHOW
, NULL
);
9773 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9774 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_HIDE
, NULL
);
9775 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9777 /* Try to overlay an offscreen surface. */
9778 memset(&surface_desc
, 0, sizeof(surface_desc
));
9779 surface_desc
.dwSize
= sizeof(surface_desc
);
9780 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
9781 surface_desc
.dwWidth
= 64;
9782 surface_desc
.dwHeight
= 64;
9783 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9784 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
9785 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9786 surface_desc
.ddpfPixelFormat
.dwFourCC
= 0;
9787 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
9788 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
9789 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
9790 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
9791 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
9792 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9794 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, offscreen
, NULL
, DDOVER_SHOW
, NULL
);
9795 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_OUTOFCAPS
&& dwm_enabled()),
9796 "Failed to update overlay, hr %#x.\n", hr
);
9798 /* Try to overlay the primary with a non-overlay surface. */
9799 hr
= IDirectDrawSurface_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
9800 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
9801 hr
= IDirectDrawSurface_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
9802 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
9804 IDirectDrawSurface_Release(offscreen
);
9805 IDirectDrawSurface_Release(primary
);
9806 IDirectDrawSurface_Release(overlay
);
9808 IDirectDraw2_Release(ddraw
);
9809 DestroyWindow(window
);
9812 static void test_overlay_rect(void)
9814 IDirectDrawSurface
*overlay
, *primary
= NULL
;
9815 DDSURFACEDESC surface_desc
;
9816 RECT rect
= {0, 0, 64, 64};
9817 IDirectDraw2
*ddraw
;
9823 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9824 0, 0, 640, 480, 0, 0, 0, 0);
9825 ddraw
= create_ddraw();
9826 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9827 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9828 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9830 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
9832 skip("Failed to create a UYVY overlay, skipping test.\n");
9836 memset(&surface_desc
, 0, sizeof(surface_desc
));
9837 surface_desc
.dwSize
= sizeof(surface_desc
);
9838 surface_desc
.dwFlags
= DDSD_CAPS
;
9839 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
9840 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
9841 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9843 /* On Windows 7, and probably Vista, UpdateOverlay() will return
9844 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
9845 * surface prevents this by disabling the dwm. */
9846 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
9847 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
9848 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
9849 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
9851 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
9854 win_skip("Cannot disable DWM, skipping overlay test.\n");
9858 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
9859 * used. This is not true in Windows Vista and earlier, but changed in
9861 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
9862 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9863 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
9864 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9865 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
9866 ok(hr
== DD_OK
|| hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9868 /* Show that the overlay position is the (top, left) coordinate of the
9869 * destination rectangle. */
9870 OffsetRect(&rect
, 32, 16);
9871 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
9872 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9873 pos_x
= -1; pos_y
= -1;
9874 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9875 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
9876 ok(pos_x
== rect
.left
, "Got unexpected pos_x %d, expected %d.\n", pos_x
, rect
.left
);
9877 ok(pos_y
== rect
.top
, "Got unexpected pos_y %d, expected %d.\n", pos_y
, rect
.top
);
9879 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
9880 * seen that the overlay overlays the whole primary(==screen). */
9881 hr2
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, 0, NULL
);
9882 ok(hr2
== DD_OK
|| hr2
== DDERR_INVALIDPARAMS
|| hr2
== DDERR_OUTOFCAPS
, "Got unexpected hr %#x.\n", hr2
);
9883 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9884 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
9887 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
9888 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
9892 ok(pos_x
== 32, "Got unexpected pos_x %d.\n", pos_x
);
9893 ok(pos_y
== 16, "Got unexpected pos_y %d.\n", pos_y
);
9896 /* The position cannot be retrieved when the overlay is not shown. */
9897 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_HIDE
, NULL
);
9898 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9899 pos_x
= -1; pos_y
= -1;
9900 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9901 ok(hr
== DDERR_OVERLAYNOTVISIBLE
, "Got unexpected hr %#x.\n", hr
);
9902 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
9903 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
9905 IDirectDrawSurface_Release(overlay
);
9908 IDirectDrawSurface_Release(primary
);
9909 IDirectDraw2_Release(ddraw
);
9910 DestroyWindow(window
);
9913 static void test_blt(void)
9915 IDirectDrawSurface
*surface
, *rt
;
9916 DDSURFACEDESC surface_desc
;
9917 IDirect3DDevice2
*device
;
9918 IDirectDraw2
*ddraw
;
9932 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit. */
9933 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, flipped source. */
9934 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, mirrored source. */
9935 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched x. */
9936 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched y. */
9937 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK
}, /* Full surface blit. */
9938 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT
}, /* Full surface, flipped destination. */
9939 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored destination. */
9940 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, flipped source. */
9941 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored source. */
9944 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9945 0, 0, 640, 480, 0, 0, 0, 0);
9946 ddraw
= create_ddraw();
9947 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9948 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9950 skip("Failed to create a 3D device, skipping test.\n");
9951 IDirectDraw2_Release(ddraw
);
9952 DestroyWindow(window
);
9956 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9957 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9959 memset(&surface_desc
, 0, sizeof(surface_desc
));
9960 surface_desc
.dwSize
= sizeof(surface_desc
);
9961 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
9962 surface_desc
.dwWidth
= 640;
9963 surface_desc
.dwHeight
= 480;
9964 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9965 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9966 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9968 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface
, NULL
, 0, NULL
);
9969 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9971 hr
= IDirectDrawSurface_Blt(surface
, NULL
, rt
, NULL
, 0, NULL
);
9972 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9974 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
9976 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
9977 surface
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
9978 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
9980 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
9981 rt
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
9982 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
9985 IDirectDrawSurface_Release(surface
);
9986 IDirectDrawSurface_Release(rt
);
9987 refcount
= IDirect3DDevice2_Release(device
);
9988 ok(!refcount
, "Device has %u references left.\n", refcount
);
9989 IDirectDraw2_Release(ddraw
);
9990 DestroyWindow(window
);
9993 static void test_getdc(void)
9995 IDirectDrawSurface
*surface
, *surface2
, *tmp
;
9996 DDSURFACEDESC surface_desc
, map_desc
;
9997 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
9998 IDirectDraw2
*ddraw
;
10004 static const struct
10007 DDPIXELFORMAT format
;
10008 BOOL getdc_supported
;
10009 HRESULT alt_result
;
10013 {"D3DFMT_A8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
10014 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE
},
10015 {"D3DFMT_X8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
10016 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE
},
10017 {"D3DFMT_R5G6B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
10018 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE
},
10019 {"D3DFMT_X1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
10020 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE
},
10021 {"D3DFMT_A1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
10022 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE
},
10023 {"D3DFMT_A4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
10024 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
10025 {"D3DFMT_X4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
10026 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
10027 {"D3DFMT_A2R10G10B10", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
10028 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE
},
10029 {"D3DFMT_A8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
10030 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
10031 {"D3DFMT_X8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
10032 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
10033 {"D3DFMT_R3G3B2", {sizeof(test_data
->format
), DDPF_RGB
, 0, {8},
10034 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE
},
10035 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
10036 * This is not implemented in wine yet, so disable the test for now.
10037 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
10038 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
10039 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
10041 {"D3DFMT_L8", {sizeof(test_data
->format
), DDPF_LUMINANCE
, 0, {8},
10042 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10043 {"D3DFMT_A8L8", {sizeof(test_data
->format
), DDPF_ALPHAPIXELS
| DDPF_LUMINANCE
, 0, {16},
10044 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE
},
10045 {"D3DFMT_DXT1", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','1'), {0},
10046 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10047 {"D3DFMT_DXT2", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','2'), {0},
10048 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10049 {"D3DFMT_DXT3", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','3'), {0},
10050 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10051 {"D3DFMT_DXT4", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','4'), {0},
10052 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10053 {"D3DFMT_DXT5", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','5'), {0},
10054 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10057 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10058 0, 0, 640, 480, 0, 0, 0, 0);
10059 ddraw
= create_ddraw();
10060 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10061 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10062 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10064 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
10066 memset(&surface_desc
, 0, sizeof(surface_desc
));
10067 surface_desc
.dwSize
= sizeof(surface_desc
);
10068 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10069 surface_desc
.dwWidth
= 64;
10070 surface_desc
.dwHeight
= 64;
10071 surface_desc
.ddpfPixelFormat
= test_data
[i
].format
;
10072 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10074 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
10076 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10077 if (FAILED(hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
10079 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data
[i
].name
, hr
);
10084 dc
= (void *)0x1234;
10085 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10086 if (test_data
[i
].getdc_supported
)
10087 ok(SUCCEEDED(hr
) || (test_data
[i
].alt_result
&& hr
== test_data
[i
].alt_result
),
10088 "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10090 ok(FAILED(hr
), "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10094 unsigned int width_bytes
;
10100 type
= GetObjectType(dc
);
10101 ok(type
== OBJ_MEMDC
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
10102 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
10103 type
= GetObjectType(bitmap
);
10104 ok(type
== OBJ_BITMAP
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
10106 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
10107 ok(size
== sizeof(dib
), "Got unexpected size %d for format %s.\n", size
, test_data
[i
].name
);
10108 ok(!dib
.dsBm
.bmType
, "Got unexpected type %#x for format %s.\n",
10109 dib
.dsBm
.bmType
, test_data
[i
].name
);
10110 ok(dib
.dsBm
.bmWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
10111 dib
.dsBm
.bmWidth
, test_data
[i
].name
);
10112 ok(dib
.dsBm
.bmHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
10113 dib
.dsBm
.bmHeight
, test_data
[i
].name
);
10114 width_bytes
= ((dib
.dsBm
.bmWidth
* U1(test_data
[i
].format
).dwRGBBitCount
+ 31) >> 3) & ~3;
10115 ok(dib
.dsBm
.bmWidthBytes
== width_bytes
, "Got unexpected width bytes %d for format %s.\n",
10116 dib
.dsBm
.bmWidthBytes
, test_data
[i
].name
);
10117 ok(dib
.dsBm
.bmPlanes
== 1, "Got unexpected plane count %d for format %s.\n",
10118 dib
.dsBm
.bmPlanes
, test_data
[i
].name
);
10119 ok(dib
.dsBm
.bmBitsPixel
== U1(test_data
[i
].format
).dwRGBBitCount
,
10120 "Got unexpected bit count %d for format %s.\n",
10121 dib
.dsBm
.bmBitsPixel
, test_data
[i
].name
);
10122 ok(!!dib
.dsBm
.bmBits
, "Got unexpected bits %p for format %s.\n",
10123 dib
.dsBm
.bmBits
, test_data
[i
].name
);
10125 ok(dib
.dsBmih
.biSize
== sizeof(dib
.dsBmih
), "Got unexpected size %u for format %s.\n",
10126 dib
.dsBmih
.biSize
, test_data
[i
].name
);
10127 ok(dib
.dsBmih
.biWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
10128 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
10129 ok(dib
.dsBmih
.biHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
10130 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
10131 ok(dib
.dsBmih
.biPlanes
== 1, "Got unexpected plane count %u for format %s.\n",
10132 dib
.dsBmih
.biPlanes
, test_data
[i
].name
);
10133 ok(dib
.dsBmih
.biBitCount
== U1(test_data
[i
].format
).dwRGBBitCount
,
10134 "Got unexpected bit count %u for format %s.\n",
10135 dib
.dsBmih
.biBitCount
, test_data
[i
].name
);
10136 ok(dib
.dsBmih
.biCompression
== (U1(test_data
[i
].format
).dwRGBBitCount
== 16 ? BI_BITFIELDS
: BI_RGB
)
10137 || broken(U1(test_data
[i
].format
).dwRGBBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_BITFIELDS
),
10138 "Got unexpected compression %#x for format %s.\n",
10139 dib
.dsBmih
.biCompression
, test_data
[i
].name
);
10140 ok(!dib
.dsBmih
.biSizeImage
, "Got unexpected image size %u for format %s.\n",
10141 dib
.dsBmih
.biSizeImage
, test_data
[i
].name
);
10142 ok(!dib
.dsBmih
.biXPelsPerMeter
, "Got unexpected horizontal resolution %d for format %s.\n",
10143 dib
.dsBmih
.biXPelsPerMeter
, test_data
[i
].name
);
10144 ok(!dib
.dsBmih
.biYPelsPerMeter
, "Got unexpected vertical resolution %d for format %s.\n",
10145 dib
.dsBmih
.biYPelsPerMeter
, test_data
[i
].name
);
10146 ok(!dib
.dsBmih
.biClrUsed
, "Got unexpected used colour count %u for format %s.\n",
10147 dib
.dsBmih
.biClrUsed
, test_data
[i
].name
);
10148 ok(!dib
.dsBmih
.biClrImportant
, "Got unexpected important colour count %u for format %s.\n",
10149 dib
.dsBmih
.biClrImportant
, test_data
[i
].name
);
10151 if (dib
.dsBmih
.biCompression
== BI_BITFIELDS
)
10153 ok((dib
.dsBitfields
[0] == U2(test_data
[i
].format
).dwRBitMask
10154 && dib
.dsBitfields
[1] == U3(test_data
[i
].format
).dwGBitMask
10155 && dib
.dsBitfields
[2] == U4(test_data
[i
].format
).dwBBitMask
)
10156 || broken(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2]),
10157 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
10158 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
10162 ok(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2],
10163 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
10164 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
10166 ok(!dib
.dshSection
, "Got unexpected section %p for format %s.\n", dib
.dshSection
, test_data
[i
].name
);
10167 ok(!dib
.dsOffset
, "Got unexpected offset %u for format %s.\n", dib
.dsOffset
, test_data
[i
].name
);
10169 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10170 ok(hr
== DD_OK
, "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10174 ok(!dc
, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
10177 IDirectDrawSurface_Release(surface
);
10182 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
10183 if (FAILED(hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
10185 skip("Failed to create mip-mapped texture for format %s (hr %#x), skipping tests.\n",
10186 test_data
[i
].name
, hr
);
10190 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
10191 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10192 hr
= IDirectDrawSurface_GetAttachedSurface(tmp
, &caps
, &surface2
);
10193 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10194 IDirectDrawSurface_Release(tmp
);
10196 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10197 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10198 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10199 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10200 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10201 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10202 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10203 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10205 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10206 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10207 dc2
= (void *)0x1234;
10208 hr
= IDirectDrawSurface_GetDC(surface
, &dc2
);
10209 ok(hr
== DDERR_DCALREADYCREATED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10210 ok(dc2
== (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
10211 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10212 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10213 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10214 ok(hr
== DDERR_NODC
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10216 map_desc
.dwSize
= sizeof(map_desc
);
10217 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10218 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10219 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10220 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10221 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10222 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10223 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10224 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10226 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10227 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10228 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10229 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10230 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10231 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10233 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10234 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10235 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10236 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10237 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10238 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10239 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10240 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10242 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10243 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10244 hr
= IDirectDrawSurface_GetDC(surface2
, &dc2
);
10245 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10246 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc2
);
10247 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10248 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10249 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10251 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10252 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10253 hr
= IDirectDrawSurface_GetDC(surface
, &dc2
);
10254 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10255 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc2
);
10256 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10257 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10258 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10260 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10261 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10262 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10263 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10264 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10265 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10266 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10267 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10269 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10270 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10271 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10272 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10273 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10274 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10275 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10276 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10278 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10279 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10280 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10281 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10282 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10283 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10284 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10285 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10287 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10288 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10289 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10290 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10291 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10292 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10293 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10294 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10296 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10297 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10298 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10299 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10300 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10301 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10302 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10303 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10305 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10306 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10307 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10308 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10309 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10310 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10311 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10312 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10313 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10314 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10316 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10317 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10318 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10319 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10320 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10321 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10322 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10323 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10324 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10325 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10327 IDirectDrawSurface_Release(surface2
);
10328 IDirectDrawSurface_Release(surface
);
10331 IDirectDraw2_Release(ddraw
);
10332 DestroyWindow(window
);
10335 static void test_draw_primitive(void)
10337 static WORD indices
[] = {0, 1, 2, 3};
10338 static D3DVERTEX quad
[] =
10340 {{-1.0f
}, {-1.0f
}, {0.0f
}},
10341 {{-1.0f
}, { 1.0f
}, {0.0f
}},
10342 {{ 1.0f
}, {-1.0f
}, {0.0f
}},
10343 {{ 1.0f
}, { 1.0f
}, {0.0f
}},
10345 IDirect3DViewport2
*viewport
;
10346 IDirect3DDevice2
*device
;
10347 IDirectDraw2
*ddraw
;
10353 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10354 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
10355 ddraw
= create_ddraw();
10356 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10357 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10359 skip("Failed to create a 3D device, skipping test.\n");
10360 IDirectDraw2_Release(ddraw
);
10361 DestroyWindow(window
);
10365 viewport
= create_viewport(device
, 0, 0, 640, 480);
10366 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
10367 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10369 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
10370 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
10372 IDirect3D2_Release(d3d
);
10374 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, NULL
, 0, 0);
10375 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10376 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, 0);
10377 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10379 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, indices
, 4, 0);
10380 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10382 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, NULL
, 0, 0);
10383 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10384 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, 0);
10385 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10386 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, indices
, 4, 0);
10387 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10389 destroy_viewport(device
, viewport
);
10390 refcount
= IDirect3DDevice2_Release(device
);
10391 ok(!refcount
, "Device has %u references left.\n", refcount
);
10392 IDirectDraw2_Release(ddraw
);
10393 DestroyWindow(window
);
10396 static void test_edge_antialiasing_blending(void)
10398 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10399 IDirect3DMaterial2
*green_background
;
10400 IDirect3DMaterial2
*red_background
;
10401 IDirectDrawSurface
*offscreen
, *ds
;
10402 D3DDEVICEDESC hal_desc
, hel_desc
;
10403 IDirect3DViewport2
*viewport
;
10404 DDSURFACEDESC surface_desc
;
10405 IDirect3DDevice2
*device
;
10406 IDirectDraw2
*ddraw
;
10412 static D3DMATRIX mat
=
10414 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10415 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10416 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10417 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10419 static D3DLVERTEX green_quad
[] =
10421 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10422 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10423 {{ 1.0f
}, {-1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10424 {{ 1.0f
}, { 1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10426 static D3DLVERTEX red_quad
[] =
10428 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xccff0000}},
10429 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xccff0000}},
10430 {{ 1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xccff0000}},
10431 {{ 1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xccff0000}},
10434 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10435 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
10436 ddraw
= create_ddraw();
10437 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10438 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10440 skip("Failed to create a 3D device.\n");
10441 DestroyWindow(window
);
10445 memset(&hal_desc
, 0, sizeof(hal_desc
));
10446 hal_desc
.dwSize
= sizeof(hal_desc
);
10447 memset(&hel_desc
, 0, sizeof(hel_desc
));
10448 hel_desc
.dwSize
= sizeof(hel_desc
);
10449 hr
= IDirect3DDevice2_GetCaps(device
, &hal_desc
, &hel_desc
);
10450 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
10451 trace("HAL line edge antialiasing support: %#x.\n",
10452 hal_desc
.dpcLineCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10453 trace("HAL triangle edge antialiasing support: %#x.\n",
10454 hal_desc
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10455 trace("HEL line edge antialiasing support: %#x.\n",
10456 hel_desc
.dpcLineCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10457 trace("HEL triangle edge antialiasing support: %#x.\n",
10458 hel_desc
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10460 memset(&surface_desc
, 0, sizeof(surface_desc
));
10461 surface_desc
.dwSize
= sizeof(surface_desc
);
10462 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
10463 surface_desc
.dwWidth
= 640;
10464 surface_desc
.dwHeight
= 480;
10465 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
10466 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
10467 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
10468 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
10469 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10470 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10471 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10472 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
10473 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
10474 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr %#x.\n", hr
);
10476 ds
= get_depth_stencil(device
);
10477 hr
= IDirectDrawSurface_AddAttachedSurface(offscreen
, ds
);
10478 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
10479 IDirectDrawSurface_Release(ds
);
10481 hr
= IDirect3DDevice2_SetRenderTarget(device
, offscreen
, 0);
10482 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
10484 red_background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 0.8f
);
10485 green_background
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.5f
);
10487 viewport
= create_viewport(device
, 0, 0, 640, 480);
10488 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
10489 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10491 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
10492 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
10493 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
10494 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
10495 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
10496 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
10497 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
10498 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
10499 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
10500 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
10501 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10502 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10503 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
10504 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
10505 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
10506 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
10507 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10508 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
10510 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
10511 ok(SUCCEEDED(hr
), "Failed to enable blending, hr %#x.\n", hr
);
10512 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
10513 ok(SUCCEEDED(hr
), "Failed to set src blend, hr %#x.\n", hr
);
10514 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_DESTALPHA
);
10515 ok(SUCCEEDED(hr
), "Failed to set dest blend, hr %#x.\n", hr
);
10517 viewport_set_background(device
, viewport
, red_background
);
10518 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10519 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10520 hr
= IDirect3DDevice2_BeginScene(device
);
10521 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10522 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10523 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10524 hr
= IDirect3DDevice2_EndScene(device
);
10525 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10526 color
= get_surface_color(offscreen
, 320, 240);
10527 ok(compare_color(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
10529 viewport_set_background(device
, viewport
, green_background
);
10530 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10531 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10532 hr
= IDirect3DDevice2_BeginScene(device
);
10533 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10534 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, red_quad
, 4, 0);
10535 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10536 hr
= IDirect3DDevice2_EndScene(device
);
10537 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10538 color
= get_surface_color(offscreen
, 320, 240);
10539 ok(compare_color(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
10541 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
10542 ok(SUCCEEDED(hr
), "Failed to disable blending, hr %#x.\n", hr
);
10544 viewport_set_background(device
, viewport
, red_background
);
10545 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10546 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10547 hr
= IDirect3DDevice2_BeginScene(device
);
10548 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10549 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10550 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10551 hr
= IDirect3DDevice2_EndScene(device
);
10552 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10553 color
= get_surface_color(offscreen
, 320, 240);
10554 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
10556 viewport_set_background(device
, viewport
, green_background
);
10557 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10558 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10559 hr
= IDirect3DDevice2_BeginScene(device
);
10560 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10561 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, red_quad
, 4, 0);
10562 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10563 hr
= IDirect3DDevice2_EndScene(device
);
10564 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10565 color
= get_surface_color(offscreen
, 320, 240);
10566 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
10568 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_EDGEANTIALIAS
, TRUE
);
10569 ok(SUCCEEDED(hr
), "Failed to enable edge antialiasing, hr %#x.\n", hr
);
10571 viewport_set_background(device
, viewport
, red_background
);
10572 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10573 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10574 hr
= IDirect3DDevice2_BeginScene(device
);
10575 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10576 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10577 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10578 hr
= IDirect3DDevice2_EndScene(device
);
10579 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10580 color
= get_surface_color(offscreen
, 320, 240);
10581 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
10583 viewport_set_background(device
, viewport
, green_background
);
10584 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10585 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10586 hr
= IDirect3DDevice2_BeginScene(device
);
10587 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10588 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, red_quad
, 4, 0);
10589 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10590 hr
= IDirect3DDevice2_EndScene(device
);
10591 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10592 color
= get_surface_color(offscreen
, 320, 240);
10593 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
10595 IDirectDrawSurface_Release(offscreen
);
10596 destroy_viewport(device
, viewport
);
10597 destroy_material(red_background
);
10598 destroy_material(green_background
);
10599 refcount
= IDirect3DDevice2_Release(device
);
10600 ok(!refcount
, "Device has %u references left.\n", refcount
);
10601 IDirectDraw2_Release(ddraw
);
10602 DestroyWindow(window
);
10605 /* TransformVertices always writes 32 bytes regardless of the input / output stride.
10606 * The stride is honored for navigating to the next vertex. 3 floats input position
10607 * are read, and 16 bytes extra vertex data are copied around. */
10608 struct transform_input
10610 float x
, y
, z
, unused1
; /* Position data, transformed. */
10611 DWORD v1
, v2
, v3
, v4
; /* Extra data, e.g. color and texture coords, copied. */
10615 struct transform_output
10618 DWORD v1
, v2
, v3
, v4
;
10619 DWORD unused3
, unused4
;
10622 static void test_transform_vertices(void)
10624 IDirect3DDevice2
*device
;
10625 IDirectDrawSurface
*rt
;
10626 IDirectDraw2
*ddraw
;
10631 IDirect3DViewport2
*viewport
;
10632 IDirect3DMaterial2
*background
;
10634 static struct transform_input position_tests
[] =
10636 { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
10637 { 1.0f
, 1.0f
, 1.0f
, 8.0f
, 6, 7, 8, 9, 10},
10638 {-1.0f
, -1.0f
, -1.0f
, 4.0f
, 11, 12, 13, 14, 15},
10639 { 0.5f
, 0.5f
, 0.5f
, 2.0f
, 16, 17, 18, 19, 20},
10640 {-0.5f
, -0.5f
, -0.5f
, 1.0f
, ~1U, ~2U, ~3U, ~4U, ~5U},
10641 {-0.5f
, -0.5f
, 0.0f
, 0.0f
, ~6U, ~7U, ~8U, ~9U, ~0U},
10643 static struct transform_input cliptest
[] =
10645 { 25.59f
, 25.59f
, 1.0f
, 0.0f
, 1, 2, 3, 4, 5},
10646 { 25.61f
, 25.61f
, 1.01f
, 0.0f
, 1, 2, 3, 4, 5},
10647 {-25.59f
, -25.59f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
10648 {-25.61f
, -25.61f
, -0.01f
, 0.0f
, 1, 2, 3, 4, 5},
10650 static struct transform_input offscreentest
[] =
10652 {128.1f
, 0.0f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
10654 struct transform_output out
[ARRAY_SIZE(position_tests
)];
10655 D3DHVERTEX out_h
[ARRAY_SIZE(position_tests
)];
10656 D3DTRANSFORMDATA transformdata
;
10657 static const D3DVIEWPORT vp_template
=
10659 sizeof(vp_template
), 0, 0, 256, 256, 5.0f
, 5.0f
, 256.0f
, 256.0f
, -25.0f
, 60.0f
10661 D3DVIEWPORT vp_data
=
10663 sizeof(vp_data
), 0, 0, 256, 256, 1.0f
, 1.0f
, 256.0f
, 256.0f
, 0.0f
, 1.0f
10665 D3DVIEWPORT2 vp2_data
;
10668 static D3DMATRIX mat_scale
=
10670 2.0f
, 0.0f
, 0.0f
, 0.0f
,
10671 0.0f
, 2.0f
, 0.0f
, 0.0f
,
10672 0.0f
, 0.0f
, 2.0f
, 0.0f
,
10673 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10677 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10678 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10679 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10680 1.0f
, 0.0f
, 0.0f
, 1.0f
,
10684 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10685 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10686 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10687 0.0f
, 1.0f
, 0.0f
, 1.0f
,
10691 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10692 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10693 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10694 0.0f
, 19.2f
, 0.0f
, 2.0f
,
10698 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10699 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10700 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10701 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10703 static D3DLVERTEX quad
[] =
10705 {{-0.75f
},{-0.5f
}, {0.0f
}, 0, {0xffff0000}},
10706 {{-0.75f
},{ 0.25f
}, {0.0f
}, 0, {0xffff0000}},
10707 {{ 0.5f
}, {-0.5f
}, {0.0f
}, 0, {0xffff0000}},
10708 {{ 0.5f
}, { 0.25f
}, {0.0f
}, 0, {0xffff0000}},
10710 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10713 for (i
= 0; i
< ARRAY_SIZE(out
); ++i
)
10715 out
[i
].unused3
= 0xdeadbeef;
10716 out
[i
].unused4
= 0xcafecafe;
10719 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10720 0, 0, 640, 480, 0, 0, 0, 0);
10721 ddraw
= create_ddraw();
10722 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10723 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10725 skip("Failed to create a 3D device, skipping test.\n");
10726 IDirectDraw2_Release(ddraw
);
10727 DestroyWindow(window
);
10730 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
10731 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10733 viewport
= create_viewport(device
, 0, 0, 256, 256);
10734 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10735 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10737 memset(&transformdata
, 0, sizeof(transformdata
));
10738 transformdata
.dwSize
= sizeof(transformdata
);
10739 transformdata
.lpIn
= position_tests
;
10740 transformdata
.dwInSize
= sizeof(position_tests
[0]);
10741 transformdata
.lpOut
= out
;
10742 transformdata
.dwOutSize
= sizeof(out
[0]);
10743 transformdata
.lpHOut
= NULL
;
10745 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10746 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10747 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10748 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10750 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10752 static const struct vec4 cmp
[] =
10754 {128.0f
, 128.0f
, 0.0f
, 1.0f
}, {129.0f
, 127.0f
, 1.0f
, 1.0f
}, {127.0f
, 129.0f
, -1.0f
, 1.0f
},
10755 {128.5f
, 127.5f
, 0.5f
, 1.0f
}, {127.5f
, 128.5f
, -0.5f
, 1.0f
}, {127.5f
, 128.5f
, 0.0f
, 1.0f
}
10758 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10759 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10760 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10761 ok(out
[i
].v1
== position_tests
[i
].v1
&& out
[i
].v2
== position_tests
[i
].v2
10762 && out
[i
].v3
== position_tests
[i
].v3
&& out
[i
].v4
== position_tests
[i
].v4
,
10763 "Vertex %u payload is %u %u %u %u.\n", i
, out
[i
].v1
, out
[i
].v2
, out
[i
].v3
, out
[i
].v4
);
10764 ok(out
[i
].unused3
== 0xdeadbeef && out
[i
].unused4
== 0xcafecafe,
10765 "Vertex %u unused data is %#x, %#x.\n", i
, out
[i
].unused3
, out
[i
].unused4
);
10768 vp_data
= vp_template
;
10769 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10770 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10771 offscreen
= 0xdeadbeef;
10772 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10773 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10774 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10775 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10777 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10779 static const struct vec4 cmp
[] =
10781 {128.0f
, 128.0f
, 0.0f
, 1.0f
}, {133.0f
, 123.0f
, 1.0f
, 1.0f
}, {123.0f
, 133.0f
, -1.0f
, 1.0f
},
10782 {130.5f
, 125.5f
, 0.5f
, 1.0f
}, {125.5f
, 130.5f
, -0.5f
, 1.0f
}, {125.5f
, 130.5f
, 0.0f
, 1.0f
}
10784 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10785 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10786 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10791 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10792 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10793 offscreen
= 0xdeadbeef;
10794 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10795 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10796 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10797 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10798 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10800 static const struct vec4 cmp
[] =
10802 {138.0f
, 148.0f
, 0.0f
, 1.0f
}, {143.0f
, 143.0f
, 1.0f
, 1.0f
}, {133.0f
, 153.0f
, -1.0f
, 1.0f
},
10803 {140.5f
, 145.5f
, 0.5f
, 1.0f
}, {135.5f
, 150.5f
, -0.5f
, 1.0f
}, {135.5f
, 150.5f
, 0.0f
, 1.0f
}
10805 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10806 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10807 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10810 transformdata
.lpHOut
= out_h
;
10811 offscreen
= 0xdeadbeef;
10812 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10813 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10814 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10815 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10816 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10818 static const D3DHVERTEX cmp_h
[] =
10820 {0, { 0.0f
}, { 0.0f
}, { 0.0f
}}, {0, { 1.0f
}, { 1.0f
}, {1.0f
}},
10821 {D3DCLIP_FRONT
, {-1.0f
}, {-1.0f
}, {-1.0f
}}, {0, { 0.5f
}, { 0.5f
}, {0.5f
}},
10822 {D3DCLIP_FRONT
, {-0.5f
}, {-0.5f
}, {-0.5f
}}, {0, {-0.5f
}, {-0.5f
}, {0.0f
}}
10824 ok(compare_float(U1(cmp_h
[i
]).hx
, U1(out_h
[i
]).hx
, 4096)
10825 && compare_float(U2(cmp_h
[i
]).hy
, U2(out_h
[i
]).hy
, 4096)
10826 && compare_float(U3(cmp_h
[i
]).hz
, U3(out_h
[i
]).hz
, 4096)
10827 && cmp_h
[i
].dwFlags
== out_h
[i
].dwFlags
,
10828 "HVertex %u differs. Got %#x %f %f %f.\n", i
,
10829 out_h
[i
].dwFlags
, U1(out_h
[i
]).hx
, U2(out_h
[i
]).hy
, U3(out_h
[i
]).hz
);
10831 /* No scheme has been found behind those return values. It seems to be
10832 * whatever data windows has when throwing the vertex away. Modify the
10833 * input test vertices to test this more. Depending on the input data
10834 * it can happen that the z coord gets written into y, or similar things. */
10837 static const struct vec4 cmp
[] =
10839 {138.0f
, 148.0f
, 0.0f
, 1.0f
}, {143.0f
, 143.0f
, 1.0f
, 1.0f
}, { -1.0f
, -1.0f
, 0.5f
, 1.0f
},
10840 {140.5f
, 145.5f
, 0.5f
, 1.0f
}, { -0.5f
, -0.5f
, -0.5f
, 1.0f
}, {135.5f
, 150.5f
, 0.0f
, 1.0f
}
10842 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10843 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10844 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10848 transformdata
.lpIn
= cliptest
;
10849 transformdata
.dwInSize
= sizeof(cliptest
[0]);
10850 offscreen
= 0xdeadbeef;
10851 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
10852 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10853 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10854 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10855 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
10857 static const DWORD flags
[] =
10860 D3DCLIP_RIGHT
| D3DCLIP_BACK
| D3DCLIP_TOP
,
10862 D3DCLIP_LEFT
| D3DCLIP_BOTTOM
| D3DCLIP_FRONT
,
10864 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
10867 vp_data
= vp_template
;
10868 vp_data
.dwWidth
= 10;
10869 vp_data
.dwHeight
= 480;
10870 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10871 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10872 offscreen
= 0xdeadbeef;
10873 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
10874 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10875 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10876 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10877 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
10879 static const DWORD flags
[] =
10882 D3DCLIP_RIGHT
| D3DCLIP_BACK
,
10884 D3DCLIP_LEFT
| D3DCLIP_FRONT
,
10886 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
10889 vp_data
= vp_template
;
10890 vp_data
.dwWidth
= 256;
10891 vp_data
.dwHeight
= 256;
10892 vp_data
.dvScaleX
= 1;
10893 vp_data
.dvScaleY
= 1;
10894 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10895 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10896 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
10897 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10898 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10899 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10900 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
10902 static const DWORD flags
[] =
10909 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
10912 /* Finally try to figure out how the DWORD dwOffscreen works.
10913 * It is a logical AND of the vertices' dwFlags members. */
10914 vp_data
= vp_template
;
10915 vp_data
.dwWidth
= 5;
10916 vp_data
.dwHeight
= 5;
10917 vp_data
.dvScaleX
= 10000.0f
;
10918 vp_data
.dvScaleY
= 10000.0f
;
10919 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10920 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10921 transformdata
.lpIn
= cliptest
;
10922 offscreen
= 0xdeadbeef;
10923 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10924 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10925 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10926 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10928 offscreen
= 0xdeadbeef;
10929 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10930 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10931 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10932 ok(offscreen
== (D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
10933 offscreen
= 0xdeadbeef;
10934 hr
= IDirect3DViewport2_TransformVertices(viewport
, 2,
10935 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10936 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10937 ok(offscreen
== (D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
10938 hr
= IDirect3DViewport2_TransformVertices(viewport
, 3,
10939 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10940 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10941 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10943 transformdata
.lpIn
= cliptest
+ 1;
10944 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10945 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10946 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10947 ok(offscreen
== (D3DCLIP_BACK
| D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
10949 transformdata
.lpIn
= cliptest
+ 2;
10950 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10951 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10952 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10953 ok(offscreen
== (D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
10954 offscreen
= 0xdeadbeef;
10955 hr
= IDirect3DViewport2_TransformVertices(viewport
, 2,
10956 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10957 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10958 ok(offscreen
== (D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
10960 transformdata
.lpIn
= cliptest
+ 3;
10961 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10962 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10963 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10964 ok(offscreen
== (D3DCLIP_FRONT
| D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
10966 transformdata
.lpIn
= offscreentest
;
10967 transformdata
.dwInSize
= sizeof(offscreentest
[0]);
10968 vp_data
= vp_template
;
10969 vp_data
.dwWidth
= 257;
10970 vp_data
.dwHeight
= 257;
10971 vp_data
.dvScaleX
= 1.0f
;
10972 vp_data
.dvScaleY
= 1.0f
;
10973 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10974 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10975 offscreen
= 0xdeadbeef;
10976 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10977 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10978 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10979 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10981 vp_data
.dwWidth
= 256;
10982 vp_data
.dwHeight
= 256;
10983 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10984 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10985 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10986 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10987 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10988 ok(offscreen
== D3DCLIP_RIGHT
, "Offscreen is %x.\n", offscreen
);
10990 /* Test the effect of Matrices.
10992 * Basically the x coordinate ends up as ((x + 1) * 2 + 0) * 5 and
10993 * y as ((y + 0) * 2 + 1) * 5. The 5 comes from dvScaleX/Y, 2 from
10994 * the view matrix and the +1's from the world and projection matrix. */
10997 vp_data
.dwWidth
= 256;
10998 vp_data
.dwHeight
= 256;
10999 vp_data
.dvScaleX
= 5.0f
;
11000 vp_data
.dvScaleY
= 5.0f
;
11001 vp_data
.dvMinZ
= 0.0f
;
11002 vp_data
.dvMaxZ
= 1.0f
;
11003 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
11004 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
11006 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat_translate1
);
11007 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11008 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat_scale
);
11009 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11010 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat_translate2
);
11011 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11013 transformdata
.lpIn
= position_tests
;
11014 transformdata
.dwInSize
= sizeof(position_tests
[0]);
11015 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
11016 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11017 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11019 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
11021 static const struct vec4 cmp
[] =
11023 {138.0f
, 123.0f
, 0.0f
, 1.0f
}, {148.0f
, 113.0f
, 2.0f
, 1.0f
}, {128.0f
, 133.0f
, -2.0f
, 1.0f
},
11024 {143.0f
, 118.0f
, 1.0f
, 1.0f
}, {133.0f
, 128.0f
, -1.0f
, 1.0f
}, {133.0f
, 128.0f
, 0.0f
, 1.0f
}
11027 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
11028 "Vertex %u differs. Got %f %f %f %f.\n", i
,
11029 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
11032 /* Invalid flags. */
11033 offscreen
= 0xdeadbeef;
11034 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
11035 &transformdata
, 0, &offscreen
);
11036 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11037 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11039 /* NULL transform data. */
11040 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11041 NULL
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11042 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11043 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11044 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11045 NULL
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11046 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11047 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11049 /* NULL transform data and NULL dwOffscreen.
11051 * Valid transform data + NULL dwOffscreen -> crash. */
11052 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11053 NULL
, D3DTRANSFORM_UNCLIPPED
, NULL
);
11054 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11057 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11058 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11059 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11060 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
11061 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11062 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11063 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11064 ok(offscreen
== ~0U, "Offscreen is %x.\n", offscreen
);
11066 /* Invalid sizes. */
11067 offscreen
= 0xdeadbeef;
11068 transformdata
.dwSize
= sizeof(transformdata
) - 1;
11069 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11070 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11071 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11072 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11073 transformdata
.dwSize
= sizeof(transformdata
) + 1;
11074 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11075 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11076 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11077 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11079 /* NULL lpIn or lpOut -> crash, except when transforming 0 vertices. */
11080 transformdata
.dwSize
= sizeof(transformdata
);
11081 transformdata
.lpIn
= NULL
;
11082 transformdata
.lpOut
= NULL
;
11083 offscreen
= 0xdeadbeef;
11084 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11085 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11086 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11087 ok(offscreen
== ~0U, "Offscreen is %x.\n", offscreen
);
11089 /* Test how vertices are transformed during draws. */
11092 vp_data
.dwWidth
= 200;
11093 vp_data
.dwHeight
= 400;
11094 vp_data
.dvScaleX
= 20.0f
;
11095 vp_data
.dvScaleY
= 50.0f
;
11096 vp_data
.dvMinZ
= 0.0f
;
11097 vp_data
.dvMaxZ
= 1.0f
;
11098 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
11099 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
11100 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
11101 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
11103 ok(SUCCEEDED(hr
), "Failed to clear the render target, hr %#x.\n", hr
);
11104 background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 0.0f
);
11105 viewport_set_background(device
, viewport
, background
);
11106 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
11107 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
11109 hr
= IDirect3DDevice2_BeginScene(device
);
11110 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11111 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
11112 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11113 hr
= IDirect3DDevice2_EndScene(device
);
11114 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11116 color
= get_surface_color(rt
, 128, 143);
11117 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11118 color
= get_surface_color(rt
, 132, 143);
11119 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11120 color
= get_surface_color(rt
, 128, 147);
11121 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11122 color
= get_surface_color(rt
, 132, 147);
11123 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11125 color
= get_surface_color(rt
, 177, 217);
11126 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11127 color
= get_surface_color(rt
, 181, 217);
11128 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11129 color
= get_surface_color(rt
, 177, 221);
11130 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11131 color
= get_surface_color(rt
, 181, 221);
11132 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11134 /* Test D3DVIEWPORT2 behavior. */
11135 vp2_data
.dwSize
= sizeof(vp2_data
);
11138 vp2_data
.dwWidth
= 200;
11139 vp2_data
.dwHeight
= 400;
11140 vp2_data
.dvClipX
= -0.5f
;
11141 vp2_data
.dvClipY
= 4.0f
;
11142 vp2_data
.dvClipWidth
= 5.0f
;
11143 vp2_data
.dvClipHeight
= 10.0f
;
11144 vp2_data
.dvMinZ
= 0.0f
;
11145 vp2_data
.dvMaxZ
= 2.0f
;
11146 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp2_data
);
11147 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
11148 transformdata
.lpIn
= position_tests
;
11149 transformdata
.lpOut
= out
;
11150 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
11151 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11152 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11153 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
11155 static const struct vec4 cmp
[] =
11157 {120.0f
, 140.0f
, 0.0f
, 1.0f
}, {200.0f
, 60.0f
, 1.0f
, 1.0f
}, {40.0f
, 220.0f
, -1.0f
, 1.0f
},
11158 {160.0f
, 100.0f
, 0.5f
, 1.0f
}, { 80.0f
, 180.0f
, -0.5f
, 1.0f
}, {80.0f
, 180.0f
, 0.0f
, 1.0f
}
11161 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
11162 "Vertex %u differs. Got %f %f %f %f.\n", i
,
11163 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
11166 memset(&mat
, 0, sizeof(mat
));
11167 mat
.dwSize
= sizeof(mat
);
11168 U1(U(mat
).diffuse
).r
= 0.0f
;
11169 U2(U(mat
).diffuse
).g
= 1.0f
;
11170 U3(U(mat
).diffuse
).b
= 0.0f
;
11171 U4(U(mat
).diffuse
).a
= 0.0f
;
11172 hr
= IDirect3DMaterial2_SetMaterial(background
, &mat
);
11173 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
11174 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
11175 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
11177 hr
= IDirect3DDevice2_BeginScene(device
);
11178 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11179 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
11180 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11181 hr
= IDirect3DDevice2_EndScene(device
);
11182 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11184 color
= get_surface_color(rt
, 58, 118);
11185 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11186 color
= get_surface_color(rt
, 62, 118);
11187 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11188 color
= get_surface_color(rt
, 58, 122);
11189 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11190 color
= get_surface_color(rt
, 62, 122);
11191 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11193 color
= get_surface_color(rt
, 157, 177);
11194 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11195 color
= get_surface_color(rt
, 161, 177);
11196 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11197 color
= get_surface_color(rt
, 157, 181);
11198 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11199 color
= get_surface_color(rt
, 161, 181);
11200 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11202 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat_identity
);
11203 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11204 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat_identity
);
11205 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11206 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat_transform3
);
11207 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11209 vp2_data
.dwX
= 0.0;
11210 vp2_data
.dwY
= 0.0;
11211 vp2_data
.dwWidth
= 1;
11212 vp2_data
.dwHeight
= 1;
11213 vp2_data
.dvClipX
= -12.8f
;
11214 vp2_data
.dvClipY
= 12.8f
+ mat_transform3
._42
/ mat_transform3
._44
;
11215 vp2_data
.dvClipWidth
= 25.6f
;
11216 vp2_data
.dvClipHeight
= 25.6f
;
11217 vp2_data
.dvMinZ
= 0.0f
;
11218 vp2_data
.dvMaxZ
= 0.5f
;
11219 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp2_data
);
11220 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
11221 transformdata
.lpIn
= cliptest
;
11222 transformdata
.dwInSize
= sizeof(cliptest
[0]);
11223 offscreen
= 0xdeadbeef;
11224 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
11225 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11226 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11227 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
11228 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
11230 static const D3DHVERTEX cmp_h
[] =
11232 {0, { 25.59f
}, { 44.79f
}, { 1.0f
}},
11233 {D3DCLIP_RIGHT
| D3DCLIP_TOP
| D3DCLIP_BACK
, { 25.61f
}, { 44.81f
}, { 1.01f
}},
11234 {0, {-25.59f
}, {-6.39f
}, { 0.0f
}},
11235 {D3DCLIP_LEFT
| D3DCLIP_BOTTOM
| D3DCLIP_FRONT
,{-25.61f
}, {-6.41f
}, {-0.01f
}},
11237 ok(compare_float(U1(cmp_h
[i
]).hx
, U1(out_h
[i
]).hx
, 4096)
11238 && compare_float(U2(cmp_h
[i
]).hy
, U2(out_h
[i
]).hy
, 4096)
11239 && compare_float(U3(cmp_h
[i
]).hz
, U3(out_h
[i
]).hz
, 4096)
11240 && cmp_h
[i
].dwFlags
== out_h
[i
].dwFlags
,
11241 "HVertex %u differs. Got %#x %f %f %f.\n", i
,
11242 out_h
[i
].dwFlags
, U1(out_h
[i
]).hx
, U2(out_h
[i
]).hy
, U3(out_h
[i
]).hz
);
11245 IDirectDrawSurface_Release(rt
);
11246 destroy_viewport(device
, viewport
);
11247 IDirect3DMaterial2_Release(background
);
11248 refcount
= IDirect3DDevice_Release(device
);
11249 ok(!refcount
, "Device has %u references left.\n", refcount
);
11250 IDirectDraw2_Release(ddraw
);
11251 DestroyWindow(window
);
11254 static void test_display_mode_surface_pixel_format(void)
11256 unsigned int width
, height
, bpp
;
11257 IDirectDrawSurface
*surface
;
11258 DDSURFACEDESC surface_desc
;
11259 IDirectDraw2
*ddraw
;
11264 if (!(ddraw
= create_ddraw()))
11266 skip("Failed to create ddraw.\n");
11270 surface_desc
.dwSize
= sizeof(surface_desc
);
11271 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
11272 ok(SUCCEEDED(hr
), "Failed to get display mode, hr %#x.\n", hr
);
11273 width
= surface_desc
.dwWidth
;
11274 height
= surface_desc
.dwHeight
;
11276 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11277 0, 0, width
, height
, NULL
, NULL
, NULL
, NULL
);
11278 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
11279 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11282 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 16, 0, 0)))
11284 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0)))
11286 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
11288 ok(bpp
, "Set display mode failed.\n");
11290 surface_desc
.dwSize
= sizeof(surface_desc
);
11291 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
11292 ok(SUCCEEDED(hr
), "Failed to get display mode, hr %#x.\n", hr
);
11293 ok(surface_desc
.dwWidth
== width
, "Got width %u, expected %u.\n", surface_desc
.dwWidth
, width
);
11294 ok(surface_desc
.dwHeight
== height
, "Got height %u, expected %u.\n", surface_desc
.dwHeight
, height
);
11295 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== bpp
, "Got bpp %u, expected %u.\n",
11296 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, bpp
);
11298 memset(&surface_desc
, 0, sizeof(surface_desc
));
11299 surface_desc
.dwSize
= sizeof(surface_desc
);
11300 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
11301 surface_desc
.dwBackBufferCount
= 1;
11302 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
;
11303 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
11304 ok(hr
== D3D_OK
, "Failed to create surface, hr %#x.\n", hr
);
11305 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
11306 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
11307 ok(surface_desc
.dwWidth
== width
, "Got width %u, expected %u.\n", surface_desc
.dwWidth
, width
);
11308 ok(surface_desc
.dwHeight
== height
, "Got height %u, expected %u.\n", surface_desc
.dwHeight
, height
);
11309 ok(surface_desc
.ddpfPixelFormat
.dwFlags
== DDPF_RGB
, "Got unexpected pixel format flags %#x.\n",
11310 surface_desc
.ddpfPixelFormat
.dwFlags
);
11311 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== bpp
, "Got bpp %u, expected %u.\n",
11312 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, bpp
);
11313 IDirectDrawSurface_Release(surface
);
11315 memset(&surface_desc
, 0, sizeof(surface_desc
));
11316 surface_desc
.dwSize
= sizeof(surface_desc
);
11317 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
11318 surface_desc
.dwWidth
= width
;
11319 surface_desc
.dwHeight
= height
;
11320 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11321 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
11322 ok(hr
== D3D_OK
, "Failed to create surface, hr %#x.\n", hr
);
11323 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
11324 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
11325 ok(surface_desc
.ddpfPixelFormat
.dwFlags
== DDPF_RGB
, "Got unexpected pixel format flags %#x.\n",
11326 surface_desc
.ddpfPixelFormat
.dwFlags
);
11327 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== bpp
, "Got bpp %u, expected %u.\n",
11328 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, bpp
);
11329 IDirectDrawSurface_Release(surface
);
11331 refcount
= IDirectDraw2_Release(ddraw
);
11332 ok(!refcount
, "DirectDraw has %u references left.\n", refcount
);
11333 DestroyWindow(window
);
11336 static void test_surface_desc_size(void)
11341 DDSURFACEDESC desc1
;
11342 DDSURFACEDESC2 desc2
;
11345 IDirectDrawSurface7
*surface7
;
11346 IDirectDrawSurface2
*surface2
;
11347 IDirectDrawSurface
*surface
;
11348 DDSURFACEDESC surface_desc
;
11349 HRESULT expected_hr
, hr
;
11350 IDirectDraw2
*ddraw
;
11354 static const struct
11361 {DDSCAPS_OFFSCREENPLAIN
, "offscreenplain"},
11362 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, "systemmemory texture"},
11363 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, "videomemory texture"},
11365 static const unsigned int desc_sizes
[] =
11367 sizeof(DDSURFACEDESC
),
11368 sizeof(DDSURFACEDESC2
),
11369 sizeof(DDSURFACEDESC
) + 1,
11370 sizeof(DDSURFACEDESC2
) + 1,
11371 2 * sizeof(DDSURFACEDESC
),
11372 2 * sizeof(DDSURFACEDESC2
),
11373 sizeof(DDSURFACEDESC
) - 1,
11374 sizeof(DDSURFACEDESC2
) - 1,
11375 sizeof(DDSURFACEDESC
) / 2,
11376 sizeof(DDSURFACEDESC2
) / 2,
11381 sizeof(desc
) - 100,
11384 if (!(ddraw
= create_ddraw()))
11386 skip("Failed to create ddraw.\n");
11389 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
11390 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11392 for (i
= 0; i
< sizeof(surface_caps
) / sizeof(*surface_caps
); ++i
)
11394 memset(&surface_desc
, 0, sizeof(surface_desc
));
11395 surface_desc
.dwSize
= sizeof(surface_desc
);
11396 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
11397 surface_desc
.ddsCaps
.dwCaps
= surface_caps
[i
].caps
;
11398 surface_desc
.dwHeight
= 128;
11399 surface_desc
.dwWidth
= 128;
11400 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11402 skip("Failed to create surface, type %s.\n", surface_caps
[i
].name
);
11405 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface2
, (void **)&surface2
);
11406 ok(hr
== DD_OK
, "Failed to query IDirectDrawSurface2, hr %#x, type %s.\n", hr
, surface_caps
[i
].name
);
11407 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface7
, (void **)&surface7
);
11408 ok(hr
== DD_OK
, "Failed to query IDirectDrawSurface7, hr %#x, type %s.\n", hr
, surface_caps
[i
].name
);
11410 /* GetSurfaceDesc() */
11411 for (j
= 0; j
< sizeof(desc_sizes
) / sizeof(*desc_sizes
); ++j
)
11413 memset(&desc
, 0, sizeof(desc
));
11414 desc
.dwSize
= desc_sizes
[j
];
11415 expected_hr
= desc
.dwSize
== sizeof(DDSURFACEDESC
) ? DD_OK
: DDERR_INVALIDPARAMS
;
11416 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &desc
.desc1
);
11417 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11418 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11420 memset(&desc
, 0, sizeof(desc
));
11421 desc
.dwSize
= desc_sizes
[j
];
11422 expected_hr
= desc
.dwSize
== sizeof(DDSURFACEDESC
) ? DD_OK
: DDERR_INVALIDPARAMS
;
11423 hr
= IDirectDrawSurface2_GetSurfaceDesc(surface2
, &desc
.desc1
);
11424 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11425 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11427 memset(&desc
, 0, sizeof(desc
));
11428 desc
.dwSize
= desc_sizes
[j
];
11429 expected_hr
= desc
.dwSize
== sizeof(DDSURFACEDESC2
) ? DD_OK
: DDERR_INVALIDPARAMS
;
11430 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
11431 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11432 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11436 for (j
= 0; j
< sizeof(desc_sizes
) / sizeof(*desc_sizes
); ++j
)
11438 const BOOL valid_size
= desc_sizes
[j
] == sizeof(DDSURFACEDESC
)
11439 || desc_sizes
[j
] == sizeof(DDSURFACEDESC2
);
11440 DWORD expected_texture_stage
;
11442 memset(&desc
, 0, sizeof(desc
));
11443 desc
.dwSize
= desc_sizes
[j
];
11444 desc
.desc2
.dwTextureStage
= 0xdeadbeef;
11445 desc
.blob
[sizeof(DDSURFACEDESC2
)] = 0xef;
11446 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &desc
.desc1
, 0, 0);
11447 expected_hr
= valid_size
? DD_OK
: DDERR_INVALIDPARAMS
;
11448 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11449 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11450 ok(desc
.dwSize
== desc_sizes
[j
], "dwSize was changed from %u to %u, type %s.\n",
11451 desc_sizes
[j
], desc
.dwSize
, surface_caps
[i
].name
);
11452 ok(desc
.blob
[sizeof(DDSURFACEDESC2
)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
11453 desc
.blob
[sizeof(DDSURFACEDESC2
)], desc_sizes
[j
], surface_caps
[i
].name
);
11456 ok(desc
.desc1
.dwWidth
== 128, "Got unexpected width %u, dwSize %u, type %s.\n",
11457 desc
.desc1
.dwWidth
, desc_sizes
[j
], surface_caps
[i
].name
);
11458 ok(desc
.desc1
.dwHeight
== 128, "Got unexpected height %u, dwSize %u, type %s.\n",
11459 desc
.desc1
.dwHeight
, desc_sizes
[j
], surface_caps
[i
].name
);
11460 expected_texture_stage
= desc_sizes
[j
] >= sizeof(DDSURFACEDESC2
) ? 0 : 0xdeadbeef;
11461 todo_wine_if(!expected_texture_stage
)
11462 ok(desc
.desc2
.dwTextureStage
== expected_texture_stage
,
11463 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
11464 desc
.desc2
.dwTextureStage
, desc_sizes
[j
], surface_caps
[i
].name
);
11465 IDirectDrawSurface_Unlock(surface
, NULL
);
11468 memset(&desc
, 0, sizeof(desc
));
11469 desc
.dwSize
= desc_sizes
[j
];
11470 desc
.desc2
.dwTextureStage
= 0xdeadbeef;
11471 desc
.blob
[sizeof(DDSURFACEDESC2
)] = 0xef;
11472 hr
= IDirectDrawSurface2_Lock(surface2
, NULL
, &desc
.desc1
, 0, 0);
11473 expected_hr
= valid_size
? DD_OK
: DDERR_INVALIDPARAMS
;
11474 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11475 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11476 ok(desc
.dwSize
== desc_sizes
[j
], "dwSize was changed from %u to %u, type %s.\n",
11477 desc_sizes
[j
], desc
.dwSize
, surface_caps
[i
].name
);
11478 ok(desc
.blob
[sizeof(DDSURFACEDESC2
)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
11479 desc
.blob
[sizeof(DDSURFACEDESC2
)], desc_sizes
[j
], surface_caps
[i
].name
);
11482 ok(desc
.desc2
.dwWidth
== 128, "Got unexpected width %u, dwSize %u, type %s.\n",
11483 desc
.desc2
.dwWidth
, desc_sizes
[j
], surface_caps
[i
].name
);
11484 ok(desc
.desc2
.dwHeight
== 128, "Got unexpected height %u, dwSize %u, type %s.\n",
11485 desc
.desc2
.dwHeight
, desc_sizes
[j
], surface_caps
[i
].name
);
11486 expected_texture_stage
= desc_sizes
[j
] >= sizeof(DDSURFACEDESC2
) ? 0 : 0xdeadbeef;
11487 todo_wine_if(!expected_texture_stage
)
11488 ok(desc
.desc2
.dwTextureStage
== expected_texture_stage
,
11489 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
11490 desc
.desc2
.dwTextureStage
, desc_sizes
[j
], surface_caps
[i
].name
);
11491 IDirectDrawSurface2_Unlock(surface2
, NULL
);
11494 memset(&desc
, 0, sizeof(desc
));
11495 desc
.dwSize
= desc_sizes
[j
];
11496 desc
.desc2
.dwTextureStage
= 0xdeadbeef;
11497 desc
.blob
[sizeof(DDSURFACEDESC2
)] = 0xef;
11498 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
11499 expected_hr
= valid_size
? DD_OK
: DDERR_INVALIDPARAMS
;
11500 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11501 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11502 ok(desc
.dwSize
== desc_sizes
[j
], "dwSize was changed from %u to %u, type %s.\n",
11503 desc_sizes
[j
], desc
.dwSize
, surface_caps
[i
].name
);
11504 ok(desc
.blob
[sizeof(DDSURFACEDESC2
)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
11505 desc
.blob
[sizeof(DDSURFACEDESC2
)], desc_sizes
[j
], surface_caps
[i
].name
);
11508 ok(desc
.desc2
.dwWidth
== 128, "Got unexpected width %u, dwSize %u, type %s.\n",
11509 desc
.desc2
.dwWidth
, desc_sizes
[j
], surface_caps
[i
].name
);
11510 ok(desc
.desc2
.dwHeight
== 128, "Got unexpected height %u, dwSize %u, type %s.\n",
11511 desc
.desc2
.dwHeight
, desc_sizes
[j
], surface_caps
[i
].name
);
11512 expected_texture_stage
= desc_sizes
[j
] >= sizeof(DDSURFACEDESC2
) ? 0 : 0xdeadbeef;
11513 ok(desc
.desc2
.dwTextureStage
== expected_texture_stage
,
11514 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
11515 desc
.desc2
.dwTextureStage
, desc_sizes
[j
], surface_caps
[i
].name
);
11516 IDirectDrawSurface7_Unlock(surface7
, NULL
);
11520 IDirectDrawSurface7_Release(surface7
);
11521 IDirectDrawSurface2_Release(surface2
);
11522 IDirectDrawSurface_Release(surface
);
11525 refcount
= IDirectDraw2_Release(ddraw
);
11526 ok(!refcount
, "DirectDraw has %u references left.\n", refcount
);
11529 static void test_ck_operation(void)
11531 IDirectDrawSurface2
*src
, *dst
;
11532 IDirectDrawSurface7
*src7
, *dst7
;
11533 IDirectDrawSurface
*surface1
;
11534 DDSURFACEDESC surface_desc
;
11535 IDirectDraw2
*ddraw
;
11544 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11545 0, 0, 640, 480, 0, 0, 0, 0);
11546 ddraw
= create_ddraw();
11547 ok(!!ddraw
, "Failed to create a ddraw object.\n");
11548 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
11549 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11551 memset(&surface_desc
, 0, sizeof(surface_desc
));
11552 surface_desc
.dwSize
= sizeof(surface_desc
);
11553 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
11554 surface_desc
.dwWidth
= 4;
11555 surface_desc
.dwHeight
= 1;
11556 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11557 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
11558 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
11559 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
11560 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
11561 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
11562 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
11563 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
11564 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&dst
);
11565 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface2, hr %#x.\n", hr
);
11566 IDirectDrawSurface_Release(surface1
);
11568 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
11569 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff00ff;
11570 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff00ff;
11571 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
11572 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
11573 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&src
);
11574 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface2, hr %#x.\n", hr
);
11575 IDirectDrawSurface_Release(surface1
);
11577 hr
= IDirectDrawSurface2_Lock(src
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11578 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11579 ok(!(surface_desc
.dwFlags
& DDSD_LPSURFACE
), "Surface desc has LPSURFACE Flags set.\n");
11580 color
= surface_desc
.lpSurface
;
11581 color
[0] = 0x77010203;
11582 color
[1] = 0x00010203;
11583 color
[2] = 0x77ff00ff;
11584 color
[3] = 0x00ff00ff;
11585 hr
= IDirectDrawSurface2_Unlock(src
, NULL
);
11586 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11588 for (i
= 0; i
< 2; ++i
)
11590 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11591 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11592 color
= surface_desc
.lpSurface
;
11593 color
[0] = 0xcccccccc;
11594 color
[1] = 0xcccccccc;
11595 color
[2] = 0xcccccccc;
11596 color
[3] = 0xcccccccc;
11597 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11598 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11602 hr
= IDirectDrawSurface2_BltFast(dst
, 0, 0, src
, NULL
, DDBLTFAST_SRCCOLORKEY
);
11603 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11607 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
, NULL
);
11608 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11611 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
| DDLOCK_READONLY
, NULL
);
11612 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11613 ok(!(surface_desc
.dwFlags
& DDSD_LPSURFACE
), "Surface desc has LPSURFACE Flags set.\n");
11614 color
= surface_desc
.lpSurface
;
11615 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
11616 * color keying, but copy it to the destination surface. Others (sysmem surfaces) apply it for
11617 * color keying, but do not copy it into the destination surface. Nvidia neither uses it for
11618 * color keying nor copies it. */
11619 ok((color
[0] == 0x77010203 && color
[1] == 0x00010203
11620 && color
[2] == 0xcccccccc && color
[3] == 0xcccccccc) /* AMD, Wine */
11621 || broken(color
[0] == 0x00010203 && color
[1] == 0x00010203
11622 && color
[2] == 0x00ff00ff && color
[3] == 0xcccccccc) /* Sysmem surfaces? */
11623 || broken(color
[0] == 0x00010203 && color
[1] == 0x00010203
11624 && color
[2] == 0xcccccccc && color
[3] == 0xcccccccc) /* Nvidia */
11625 || broken(color
[0] == 0xff010203 && color
[1] == 0xff010203
11626 && color
[2] == 0xcccccccc && color
[3] == 0xcccccccc) /* Testbot */,
11627 "Destination data after blitting is %08x %08x %08x %08x, i=%u.\n",
11628 color
[0], color
[1], color
[2], color
[3], i
);
11629 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11630 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11633 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11634 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
11635 ok(ckey
.dwColorSpaceLowValue
== 0x00ff00ff && ckey
.dwColorSpaceHighValue
== 0x00ff00ff,
11636 "Got unexpected color key low=%08x high=%08x.\n", ckey
.dwColorSpaceLowValue
, ckey
.dwColorSpaceHighValue
);
11638 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
11639 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11640 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11642 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0;
11643 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11644 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
11645 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00 && ckey
.dwColorSpaceHighValue
== 0x0000ff00,
11646 "Got unexpected color key low=%08x high=%08x.\n", ckey
.dwColorSpaceLowValue
, ckey
.dwColorSpaceHighValue
);
11648 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0;
11649 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0;
11650 hr
= IDirectDrawSurface2_GetSurfaceDesc(src
, &surface_desc
);
11651 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
11652 ok(surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
== 0x0000ff00
11653 && surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
== 0x0000ff00,
11654 "Got unexpected color key low=%08x high=%08x.\n", surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
,
11655 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
);
11657 /* Test SetColorKey with dwColorSpaceHighValue < dwColorSpaceLowValue */
11658 ckey
.dwColorSpaceLowValue
= 0x000000ff;
11659 ckey
.dwColorSpaceHighValue
= 0x00000000;
11660 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11661 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11663 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0;
11664 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11665 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
11666 ok(ckey
.dwColorSpaceLowValue
== 0x000000ff && ckey
.dwColorSpaceHighValue
== 0x000000ff,
11667 "Got unexpected color key low=%08x high=%08x.\n", ckey
.dwColorSpaceLowValue
, ckey
.dwColorSpaceHighValue
);
11669 ckey
.dwColorSpaceLowValue
= 0x000000ff;
11670 ckey
.dwColorSpaceHighValue
= 0x00000001;
11671 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11672 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11674 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0;
11675 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11676 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
11677 ok(ckey
.dwColorSpaceLowValue
== 0x000000ff && ckey
.dwColorSpaceHighValue
== 0x000000ff,
11678 "Got unexpected color key low=%08x high=%08x.\n", ckey
.dwColorSpaceLowValue
, ckey
.dwColorSpaceHighValue
);
11680 ckey
.dwColorSpaceLowValue
= 0x000000fe;
11681 ckey
.dwColorSpaceHighValue
= 0x000000fd;
11682 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11683 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11685 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0;
11686 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11687 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
11688 ok(ckey
.dwColorSpaceLowValue
== 0x000000fe && ckey
.dwColorSpaceHighValue
== 0x000000fe,
11689 "Got unexpected color key low=%08x high=%08x.\n", ckey
.dwColorSpaceLowValue
, ckey
.dwColorSpaceHighValue
);
11691 IDirectDrawSurface2_Release(src
);
11692 IDirectDrawSurface2_Release(dst
);
11694 /* Test source and destination keys and where they are read from. Use a surface with alpha
11695 * to avoid driver-dependent content in the X channel. */
11696 memset(&surface_desc
, 0, sizeof(surface_desc
));
11697 surface_desc
.dwSize
= sizeof(surface_desc
);
11698 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
11699 surface_desc
.dwWidth
= 6;
11700 surface_desc
.dwHeight
= 1;
11701 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11702 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
11703 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
11704 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
11705 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
11706 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
11707 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
11708 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
11709 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
11710 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&dst
);
11711 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface2, hr %#x.\n", hr
);
11712 IDirectDrawSurface_Release(surface1
);
11714 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
11715 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
11716 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&src
);
11717 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface2, hr %#x.\n", hr
);
11718 IDirectDrawSurface_Release(surface1
);
11720 ckey
.dwColorSpaceLowValue
= 0x0000ff00;
11721 ckey
.dwColorSpaceHighValue
= 0x0000ff00;
11722 hr
= IDirectDrawSurface2_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
11723 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11724 ckey
.dwColorSpaceLowValue
= 0x00ff0000;
11725 ckey
.dwColorSpaceHighValue
= 0x00ff0000;
11726 hr
= IDirectDrawSurface2_SetColorKey(dst
, DDCKEY_DESTBLT
, &ckey
);
11727 ok(SUCCEEDED(hr
) || hr
== DDERR_NOCOLORKEYHW
, "Failed to set color key, hr %#x.\n", hr
);
11730 /* Nvidia reject dest keys, AMD allows them. This applies to vidmem and sysmem surfaces. */
11731 skip("Failed to set destination color key, skipping related tests.\n");
11735 ckey
.dwColorSpaceLowValue
= 0x000000ff;
11736 ckey
.dwColorSpaceHighValue
= 0x000000ff;
11737 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11738 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11739 ckey
.dwColorSpaceLowValue
= 0x000000aa;
11740 ckey
.dwColorSpaceHighValue
= 0x000000aa;
11741 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_DESTBLT
, &ckey
);
11742 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11744 memset(&fx
, 0, sizeof(fx
));
11745 fx
.dwSize
= sizeof(fx
);
11746 fx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 0x00110000;
11747 fx
.ddckSrcColorkey
.dwColorSpaceLowValue
= 0x00110000;
11748 fx
.ddckDestColorkey
.dwColorSpaceHighValue
= 0x00001100;
11749 fx
.ddckDestColorkey
.dwColorSpaceLowValue
= 0x00001100;
11751 hr
= IDirectDrawSurface2_Lock(src
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11752 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11753 color
= surface_desc
.lpSurface
;
11754 color
[0] = 0x000000ff; /* Applies to src blt key in src surface. */
11755 color
[1] = 0x000000aa; /* Applies to dst blt key in src surface. */
11756 color
[2] = 0x00ff0000; /* Dst color key in dst surface. */
11757 color
[3] = 0x0000ff00; /* Src color key in dst surface. */
11758 color
[4] = 0x00001100; /* Src color key in ddbltfx. */
11759 color
[5] = 0x00110000; /* Dst color key in ddbltfx. */
11760 hr
= IDirectDrawSurface2_Unlock(src
, NULL
);
11761 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11763 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11764 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11765 color
= surface_desc
.lpSurface
;
11766 color
[0] = color
[1] = color
[2] = color
[3] = color
[4] = color
[5] = 0x55555555;
11767 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11768 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11770 /* Test a blit without keying. */
11771 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, 0, &fx
);
11772 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11774 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11775 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11776 color
= surface_desc
.lpSurface
;
11777 /* Should have copied src data unmodified to dst. */
11778 ok(color
[0] == 0x000000ff && color
[1] == 0x000000aa && color
[2] == 0x00ff0000 &&
11779 color
[3] == 0x0000ff00 && color
[4] == 0x00001100 && color
[5] == 0x00110000,
11780 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11781 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11783 color
[0] = color
[1] = color
[2] = color
[3] = color
[4] = color
[5] = 0x55555555;
11784 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11785 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11788 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
, &fx
);
11789 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11791 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11792 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11793 color
= surface_desc
.lpSurface
;
11794 /* Src key applied to color[0]. It is unmodified, the others are copied. */
11795 ok(color
[0] == 0x55555555 && color
[1] == 0x000000aa && color
[2] == 0x00ff0000 &&
11796 color
[3] == 0x0000ff00 && color
[4] == 0x00001100 && color
[5] == 0x00110000,
11797 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11798 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11800 color
[0] = color
[1] = color
[2] = color
[3] = color
[4] = color
[5] = 0x55555555;
11801 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11802 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11804 /* Src override. */
11805 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRCOVERRIDE
, &fx
);
11806 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11808 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11809 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11810 color
= surface_desc
.lpSurface
;
11811 /* Override key applied to color[5]. It is unmodified, the others are copied. */
11812 ok(color
[0] == 0x000000ff && color
[1] == 0x000000aa && color
[2] == 0x00ff0000 &&
11813 color
[3] == 0x0000ff00 && color
[4] == 0x00001100 && color
[5] == 0x55555555,
11814 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11815 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11817 color
[0] = color
[1] = color
[2] = color
[3] = color
[4] = color
[5] = 0x55555555;
11818 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11819 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11821 /* Src override AND src key. That is not supposed to work. */
11822 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_KEYSRCOVERRIDE
, &fx
);
11823 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
11825 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11826 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11827 color
= surface_desc
.lpSurface
;
11828 /* Ensure the destination was not changed. */
11829 ok(color
[0] == 0x55555555 && color
[1] == 0x55555555 && color
[2] == 0x55555555 &&
11830 color
[3] == 0x55555555 && color
[4] == 0x55555555 && color
[5] == 0x55555555,
11831 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11832 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11834 /* Use different dst colors for the dst key test. */
11835 color
[0] = 0x00ff0000; /* Dest key in dst surface. */
11836 color
[1] = 0x00ff0000; /* Dest key in dst surface. */
11837 color
[2] = 0x00001100; /* Dest key in override. */
11838 color
[3] = 0x00001100; /* Dest key in override. */
11839 color
[4] = 0x000000aa; /* Dest key in src surface. */
11840 color
[5] = 0x000000aa; /* Dest key in src surface. */
11841 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11842 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11844 /* Dest key blit. The key is taken from the SOURCE surface in v2! */
11845 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDEST
, &fx
);
11846 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11848 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11849 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11850 color
= surface_desc
.lpSurface
;
11851 /* Dst key applied to color[4,5], they are the only changed pixels. */
11852 ok(color
[0] == 0x00ff0000 && color
[1] == 0x00ff0000 && color
[2] == 0x00001100 &&
11853 color
[3] == 0x00001100 && color
[4] == 0x00001100 && color
[5] == 0x00110000,
11854 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11855 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11857 color
[0] = 0x00ff0000; /* Dest key in dst surface. */
11858 color
[1] = 0x00ff0000; /* Dest key in dst surface. */
11859 color
[2] = 0x00001100; /* Dest key in override. */
11860 color
[3] = 0x00001100; /* Dest key in override. */
11861 color
[4] = 0x000000aa; /* Dest key in src surface. */
11862 color
[5] = 0x000000aa; /* Dest key in src surface. */
11863 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11864 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11866 /* What happens with a QI'd newer version of the interface? It takes the key
11867 * from the destination surface. */
11868 hr
= IDirectDrawSurface2_QueryInterface(src
, &IID_IDirectDrawSurface7
, (void **)&src7
);
11869 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr
);
11870 hr
= IDirectDrawSurface2_QueryInterface(dst
, &IID_IDirectDrawSurface7
, (void **)&dst7
);
11871 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr
);
11873 hr
= IDirectDrawSurface7_Blt(dst7
, NULL
, src7
, NULL
, DDBLT_KEYDEST
, &fx
);
11874 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11876 IDirectDrawSurface7_Release(dst7
);
11877 IDirectDrawSurface7_Release(src7
);
11879 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11880 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11881 color
= surface_desc
.lpSurface
;
11882 /* Dst key applied to color[0,1], they are the only changed pixels. */
11883 todo_wine
ok(color
[0] == 0x000000ff && color
[1] == 0x000000aa && color
[2] == 0x00001100 &&
11884 color
[3] == 0x00001100 && color
[4] == 0x000000aa && color
[5] == 0x000000aa,
11885 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11886 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11888 color
[0] = 0x00ff0000; /* Dest key in dst surface. */
11889 color
[1] = 0x00ff0000; /* Dest key in dst surface. */
11890 color
[2] = 0x00001100; /* Dest key in override. */
11891 color
[3] = 0x00001100; /* Dest key in override. */
11892 color
[4] = 0x000000aa; /* Dest key in src surface. */
11893 color
[5] = 0x000000aa; /* Dest key in src surface. */
11894 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11895 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11897 /* Dest override key blit. */
11898 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDESTOVERRIDE
, &fx
);
11899 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11901 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11902 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11903 color
= surface_desc
.lpSurface
;
11904 /* Dst key applied to color[2,3], they are the only changed pixels. */
11905 ok(color
[0] == 0x00ff0000 && color
[1] == 0x00ff0000 && color
[2] == 0x00ff0000 &&
11906 color
[3] == 0x0000ff00 && color
[4] == 0x000000aa && color
[5] == 0x000000aa,
11907 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11908 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11910 color
[0] = 0x00ff0000; /* Dest key in dst surface. */
11911 color
[1] = 0x00ff0000; /* Dest key in dst surface. */
11912 color
[2] = 0x00001100; /* Dest key in override. */
11913 color
[3] = 0x00001100; /* Dest key in override. */
11914 color
[4] = 0x000000aa; /* Dest key in src surface. */
11915 color
[5] = 0x000000aa; /* Dest key in src surface. */
11916 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11917 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11919 /* Dest override together with surface key. Supposed to fail. */
11920 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDEST
| DDBLT_KEYDESTOVERRIDE
, &fx
);
11921 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
11923 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11924 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11925 color
= surface_desc
.lpSurface
;
11926 /* Destination is unchanged. */
11927 ok(color
[0] == 0x00ff0000 && color
[1] == 0x00ff0000 && color
[2] == 0x00001100 &&
11928 color
[3] == 0x00001100 && color
[4] == 0x000000aa && color
[5] == 0x000000aa,
11929 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11930 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11931 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11932 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11934 /* Source and destination key. This is driver dependent. New HW treats it like
11935 * DDBLT_KEYSRC. Older HW and some software renderers apply both keys. */
11938 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDEST
| DDBLT_KEYSRC
, &fx
);
11939 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11941 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11942 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11943 color
= surface_desc
.lpSurface
;
11944 /* Color[0] is filtered by the src key, 2-5 are filtered by the dst key, if
11945 * the driver applies it. */
11946 ok(color
[0] == 0x00ff0000 && color
[1] == 0x000000aa && color
[2] == 0x00ff0000 &&
11947 color
[3] == 0x0000ff00 && color
[4] == 0x00001100 && color
[5] == 0x00110000,
11948 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11949 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11951 color
[0] = 0x00ff0000; /* Dest key in dst surface. */
11952 color
[1] = 0x00ff0000; /* Dest key in dst surface. */
11953 color
[2] = 0x00001100; /* Dest key in override. */
11954 color
[3] = 0x00001100; /* Dest key in override. */
11955 color
[4] = 0x000000aa; /* Dest key in src surface. */
11956 color
[5] = 0x000000aa; /* Dest key in src surface. */
11957 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11958 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11961 /* Override keys without ddbltfx parameter fail */
11962 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDESTOVERRIDE
, NULL
);
11963 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
11964 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRCOVERRIDE
, NULL
);
11965 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
11967 /* Try blitting without keys in the source surface. */
11968 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
11969 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11970 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_DESTBLT
, NULL
);
11971 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11973 /* That fails now. Do not bother to check that the data is unmodified. */
11974 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
, &fx
);
11975 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
11977 /* Surprisingly this still works. It uses the old key from the src surface. */
11978 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDEST
, &fx
);
11979 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11981 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11982 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11983 color
= surface_desc
.lpSurface
;
11984 /* Dst key applied to color[4,5], they are the only changed pixels. */
11985 ok(color
[0] == 0x00ff0000 && color
[1] == 0x00ff0000 && color
[2] == 0x00001100 &&
11986 color
[3] == 0x00001100 && color
[4] == 0x00001100 && color
[5] == 0x00110000,
11987 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11988 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11989 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11990 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11992 /* This returns DDERR_NOCOLORKEY as expected. */
11993 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_DESTBLT
, &ckey
);
11994 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
11996 /* GetSurfaceDesc returns a zeroed key as expected. */
11997 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x12345678;
11998 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x12345678;
11999 hr
= IDirectDrawSurface2_GetSurfaceDesc(src
, &surface_desc
);
12000 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
12001 ok(!surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
12002 && !surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
,
12003 "Got unexpected color key low=%08x high=%08x.\n", surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
,
12004 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
);
12006 /* Try blitting without keys in the destination surface. */
12007 hr
= IDirectDrawSurface2_SetColorKey(dst
, DDCKEY_SRCBLT
, NULL
);
12008 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
12009 hr
= IDirectDrawSurface2_SetColorKey(dst
, DDCKEY_DESTBLT
, NULL
);
12010 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
12012 /* This fails, as sanity would dictate. */
12013 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDEST
, &fx
);
12014 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
12017 IDirectDrawSurface2_Release(src
);
12018 IDirectDrawSurface2_Release(dst
);
12019 refcount
= IDirectDraw2_Release(ddraw
);
12020 ok(!refcount
, "DirectDraw has %u references left.\n", refcount
);
12021 DestroyWindow(window
);
12026 IDirectDraw2
*ddraw
;
12027 DEVMODEW current_mode
;
12030 if (!(ddraw
= create_ddraw()))
12032 skip("Failed to create a ddraw object, skipping tests.\n");
12035 IDirectDraw2_Release(ddraw
);
12037 memset(¤t_mode
, 0, sizeof(current_mode
));
12038 current_mode
.dmSize
= sizeof(current_mode
);
12039 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
12040 registry_mode
.dmSize
= sizeof(registry_mode
);
12041 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
12042 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
12043 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
12045 skip("Current mode does not match registry mode, skipping test.\n");
12049 if ((dwmapi
= LoadLibraryA("dwmapi.dll")))
12050 pDwmIsCompositionEnabled
= (void *)GetProcAddress(dwmapi
, "DwmIsCompositionEnabled");
12052 test_coop_level_create_device_window();
12053 test_clipper_blt();
12054 test_coop_level_d3d_state();
12055 test_surface_interface_mismatch();
12056 test_coop_level_threaded();
12058 test_texture_load_ckey();
12067 test_window_style();
12068 test_redundant_mode_set();
12069 test_coop_level_mode_set();
12070 test_coop_level_mode_set_multi();
12072 test_coop_level_surf_create();
12073 test_coop_level_multi_window();
12074 test_clear_rect_count();
12075 test_coop_level_versions();
12076 test_lighting_interface_versions();
12077 test_coop_level_activateapp();
12078 test_unsupported_formats();
12080 test_primary_caps();
12081 test_surface_lock();
12082 test_surface_discard();
12084 test_set_surface_desc();
12085 test_user_memory_getdc();
12086 test_sysmem_overlay();
12087 test_primary_palette();
12088 test_surface_attachment();
12089 test_pixel_format();
12090 test_create_surface_pitch();
12092 test_palette_complex();
12096 test_specular_lighting();
12097 test_palette_gdi();
12098 test_palette_alpha();
12099 test_lost_device();
12100 test_surface_desc_lock();
12101 test_texturemapblend();
12102 test_viewport_clear_rect();
12104 test_colorkey_precision();
12105 test_range_colorkey();
12107 test_lockrect_invalid();
12108 test_yv12_overlay();
12109 test_offscreen_overlay();
12110 test_overlay_rect();
12113 test_draw_primitive();
12114 test_edge_antialiasing_blending();
12115 test_transform_vertices();
12116 test_display_mode_surface_pixel_format();
12117 test_surface_desc_size();
12118 test_ck_operation();