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"
28 static BOOL is_ddraw64
= sizeof(DWORD
) != sizeof(DWORD
*);
29 static DEVMODEW registry_mode
;
31 static HRESULT (WINAPI
*pDwmIsCompositionEnabled
)(BOOL
*);
34 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
42 struct create_window_thread_param
45 HANDLE window_created
;
46 HANDLE destroy_window
;
50 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
52 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
54 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
56 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
58 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
62 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
72 if (abs(x
- y
) > ulps
)
78 static BOOL
compare_vec4(const struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
80 return compare_float(vec
->x
, x
, ulps
)
81 && compare_float(vec
->y
, y
, ulps
)
82 && compare_float(vec
->z
, z
, ulps
)
83 && compare_float(vec
->w
, w
, ulps
);
86 static BOOL
ddraw_is_warp(IDirectDraw2
*ddraw
)
89 DDDEVICEIDENTIFIER identifier
;
92 if (!strcmp(winetest_platform
, "wine"))
95 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
96 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
97 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, &identifier
, 0);
98 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
99 IDirectDraw4_Release(ddraw4
);
101 return !!strstr(identifier
.szDriver
, "warp");
104 static BOOL
ddraw_is_nvidia(IDirectDraw2
*ddraw
)
106 IDirectDraw4
*ddraw4
;
107 DDDEVICEIDENTIFIER identifier
;
110 if (!strcmp(winetest_platform
, "wine"))
113 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
114 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
115 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, &identifier
, 0);
116 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
117 IDirectDraw4_Release(ddraw4
);
119 return identifier
.dwVendorId
== 0x10de;
122 static BOOL
ddraw_is_intel(IDirectDraw2
*ddraw
)
124 IDirectDraw4
*ddraw4
;
125 DDDEVICEIDENTIFIER identifier
;
128 if (!strcmp(winetest_platform
, "wine"))
131 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
132 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
133 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, &identifier
, 0);
134 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
135 IDirectDraw4_Release(ddraw4
);
137 return identifier
.dwVendorId
== 0x8086;
140 static IDirectDrawSurface
*create_overlay(IDirectDraw2
*ddraw
,
141 unsigned int width
, unsigned int height
, DWORD format
)
143 IDirectDrawSurface
*surface
;
146 memset(&desc
, 0, sizeof(desc
));
147 desc
.dwSize
= sizeof(desc
);
148 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
149 desc
.dwWidth
= width
;
150 desc
.dwHeight
= height
;
151 desc
.ddsCaps
.dwCaps
= DDSCAPS_OVERLAY
;
152 desc
.ddpfPixelFormat
.dwSize
= sizeof(desc
.ddpfPixelFormat
);
153 desc
.ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
154 desc
.ddpfPixelFormat
.dwFourCC
= format
;
156 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &desc
, &surface
, NULL
)))
161 static DWORD WINAPI
create_window_thread_proc(void *param
)
163 struct create_window_thread_param
*p
= param
;
167 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
168 0, 0, 640, 480, 0, 0, 0, 0);
169 ret
= SetEvent(p
->window_created
);
170 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
176 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
177 DispatchMessageA(&msg
);
178 res
= WaitForSingleObject(p
->destroy_window
, 100);
179 if (res
== WAIT_OBJECT_0
)
181 if (res
!= WAIT_TIMEOUT
)
183 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
188 DestroyWindow(p
->window
);
193 static void create_window_thread(struct create_window_thread_param
*p
)
197 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
198 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
199 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
200 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
201 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
202 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
203 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
204 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
207 static void destroy_window_thread(struct create_window_thread_param
*p
)
209 SetEvent(p
->destroy_window
);
210 WaitForSingleObject(p
->thread
, INFINITE
);
211 CloseHandle(p
->destroy_window
);
212 CloseHandle(p
->window_created
);
213 CloseHandle(p
->thread
);
216 static IDirectDrawSurface
*get_depth_stencil(IDirect3DDevice2
*device
)
218 IDirectDrawSurface
*rt
, *ret
;
219 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
222 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
223 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
224 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ret
);
225 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
226 IDirectDrawSurface_Release(rt
);
230 static HRESULT
set_display_mode(IDirectDraw2
*ddraw
, DWORD width
, DWORD height
)
232 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
234 return IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
237 static D3DCOLOR
get_surface_color(IDirectDrawSurface
*surface
, UINT x
, UINT y
)
239 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
240 DDSURFACEDESC surface_desc
;
244 memset(&surface_desc
, 0, sizeof(surface_desc
));
245 surface_desc
.dwSize
= sizeof(surface_desc
);
247 hr
= IDirectDrawSurface_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
248 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
252 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
254 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
255 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
260 static DWORD
get_device_z_depth(IDirect3DDevice2
*device
)
262 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
263 IDirectDrawSurface
*ds
, *rt
;
267 if (FAILED(IDirect3DDevice2_GetRenderTarget(device
, &rt
)))
270 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ds
);
271 IDirectDrawSurface_Release(rt
);
275 desc
.dwSize
= sizeof(desc
);
276 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
277 IDirectDrawSurface_Release(ds
);
281 return U2(desc
).dwZBufferBitDepth
;
284 static IDirectDraw2
*create_ddraw(void)
286 IDirectDraw2
*ddraw2
;
290 if (FAILED(DirectDrawCreate(NULL
, &ddraw1
, NULL
)))
293 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw2
, (void **)&ddraw2
);
294 IDirectDraw_Release(ddraw1
);
301 static IDirect3DDevice2
*create_device(IDirectDraw2
*ddraw
, HWND window
, DWORD coop_level
)
303 static const DWORD z_depths
[] = {32, 24, 16};
304 IDirectDrawSurface
*surface
, *ds
;
305 IDirect3DDevice2
*device
= NULL
;
306 DDSURFACEDESC surface_desc
;
311 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, coop_level
);
312 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
314 memset(&surface_desc
, 0, sizeof(surface_desc
));
315 surface_desc
.dwSize
= sizeof(surface_desc
);
316 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
317 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
318 surface_desc
.dwWidth
= 640;
319 surface_desc
.dwHeight
= 480;
321 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
322 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
324 if (coop_level
& DDSCL_NORMAL
)
326 IDirectDrawClipper
*clipper
;
328 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
329 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
330 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
331 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
332 hr
= IDirectDrawSurface_SetClipper(surface
, clipper
);
333 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
334 IDirectDrawClipper_Release(clipper
);
337 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
340 IDirectDrawSurface_Release(surface
);
344 /* We used to use EnumDevices() for this, but it seems
345 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
346 * relationship with reality. */
347 for (i
= 0; i
< sizeof(z_depths
) / sizeof(*z_depths
); ++i
)
349 memset(&surface_desc
, 0, sizeof(surface_desc
));
350 surface_desc
.dwSize
= sizeof(surface_desc
);
351 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
352 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
353 U2(surface_desc
).dwZBufferBitDepth
= z_depths
[i
];
354 surface_desc
.dwWidth
= 640;
355 surface_desc
.dwHeight
= 480;
356 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
)))
359 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
360 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
361 IDirectDrawSurface_Release(ds
);
365 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
)))
368 IDirectDrawSurface_DeleteAttachedSurface(surface
, 0, ds
);
371 IDirect3D2_Release(d3d
);
372 IDirectDrawSurface_Release(surface
);
376 static IDirect3DViewport2
*create_viewport(IDirect3DDevice2
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
378 IDirect3DViewport2
*viewport
;
383 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
384 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
385 hr
= IDirect3D2_CreateViewport(d3d
, &viewport
, NULL
);
386 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
387 hr
= IDirect3DDevice2_AddViewport(device
, viewport
);
388 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
389 memset(&vp
, 0, sizeof(vp
));
390 vp
.dwSize
= sizeof(vp
);
397 vp
.dvClipWidth
= 2.0f
;
398 vp
.dvClipHeight
= 2.0f
;
401 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp
);
402 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
403 IDirect3D2_Release(d3d
);
408 static void viewport_set_background(IDirect3DDevice2
*device
, IDirect3DViewport2
*viewport
,
409 IDirect3DMaterial2
*material
)
411 D3DMATERIALHANDLE material_handle
;
414 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &material_handle
);
415 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
416 hr
= IDirect3DViewport2_SetBackground(viewport
, material_handle
);
417 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
420 static void destroy_viewport(IDirect3DDevice2
*device
, IDirect3DViewport2
*viewport
)
424 hr
= IDirect3DDevice2_DeleteViewport(device
, viewport
);
425 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
426 IDirect3DViewport2_Release(viewport
);
429 static IDirect3DMaterial2
*create_material(IDirect3DDevice2
*device
, D3DMATERIAL
*mat
)
431 IDirect3DMaterial2
*material
;
435 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
436 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
437 hr
= IDirect3D2_CreateMaterial(d3d
, &material
, NULL
);
438 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
439 hr
= IDirect3DMaterial2_SetMaterial(material
, mat
);
440 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
441 IDirect3D2_Release(d3d
);
446 static IDirect3DMaterial2
*create_diffuse_material(IDirect3DDevice2
*device
, float r
, float g
, float b
, float a
)
450 memset(&mat
, 0, sizeof(mat
));
451 mat
.dwSize
= sizeof(mat
);
452 U1(U(mat
).diffuse
).r
= r
;
453 U2(U(mat
).diffuse
).g
= g
;
454 U3(U(mat
).diffuse
).b
= b
;
455 U4(U(mat
).diffuse
).a
= a
;
457 return create_material(device
, &mat
);
460 static IDirect3DMaterial2
*create_specular_material(IDirect3DDevice2
*device
,
461 float r
, float g
, float b
, float a
, float power
)
465 memset(&mat
, 0, sizeof(mat
));
466 mat
.dwSize
= sizeof(mat
);
467 U1(U2(mat
).specular
).r
= r
;
468 U2(U2(mat
).specular
).g
= g
;
469 U3(U2(mat
).specular
).b
= b
;
470 U4(U2(mat
).specular
).a
= a
;
471 U4(mat
).power
= power
;
473 return create_material(device
, &mat
);
476 static IDirect3DMaterial2
*create_emissive_material(IDirect3DDevice2
*device
, float r
, float g
, float b
, float a
)
480 memset(&mat
, 0, sizeof(mat
));
481 mat
.dwSize
= sizeof(mat
);
482 U1(U3(mat
).emissive
).r
= r
;
483 U2(U3(mat
).emissive
).g
= g
;
484 U3(U3(mat
).emissive
).b
= b
;
485 U4(U3(mat
).emissive
).a
= a
;
487 return create_material(device
, &mat
);
490 static void destroy_material(IDirect3DMaterial2
*material
)
492 IDirect3DMaterial2_Release(material
);
499 WPARAM expect_wparam
;
502 static const struct message
*expect_messages
;
504 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
506 if (expect_messages
&& message
== expect_messages
->message
)
508 if (expect_messages
->check_wparam
)
509 ok (wparam
== expect_messages
->expect_wparam
,
510 "Got unexpected wparam %lx for message %x, expected %lx.\n",
511 wparam
, message
, expect_messages
->expect_wparam
);
516 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
519 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
520 * interface. This prevents subsequent SetCooperativeLevel() calls on a
521 * different window from failing with DDERR_HWNDALREADYSET. */
522 static void fix_wndproc(HWND window
, LONG_PTR proc
)
527 if (!(ddraw
= create_ddraw()))
530 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
531 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
532 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
533 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
534 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
536 IDirectDraw2_Release(ddraw
);
539 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
541 HRESULT hr
= IDirectDrawSurface_Restore(surface
);
542 ok(SUCCEEDED(hr
) || hr
== DDERR_IMPLICITLYCREATED
, "Failed to restore surface, hr %#x.\n", hr
);
543 IDirectDrawSurface_Release(surface
);
548 static HRESULT
restore_surfaces(IDirectDraw2
*ddraw
)
550 return IDirectDraw2_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
551 NULL
, NULL
, restore_callback
);
554 static void test_coop_level_create_device_window(void)
556 HWND focus_window
, device_window
;
560 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
561 0, 0, 640, 480, 0, 0, 0, 0);
562 ddraw
= create_ddraw();
563 ok(!!ddraw
, "Failed to create a ddraw object.\n");
565 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
566 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
567 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
568 ok(!device_window
, "Unexpected device window found.\n");
569 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
570 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
571 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
572 ok(!device_window
, "Unexpected device window found.\n");
573 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
574 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
575 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
576 ok(!device_window
, "Unexpected device window found.\n");
577 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
578 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
579 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
580 ok(!device_window
, "Unexpected device window found.\n");
581 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
582 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
583 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
584 ok(!device_window
, "Unexpected device window found.\n");
586 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
587 if (broken(hr
== DDERR_INVALIDPARAMS
))
589 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
590 IDirectDraw2_Release(ddraw
);
591 DestroyWindow(focus_window
);
595 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
596 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
597 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
598 ok(!device_window
, "Unexpected device window found.\n");
599 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
600 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
601 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
602 ok(!device_window
, "Unexpected device window found.\n");
604 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
605 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
606 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
607 ok(!device_window
, "Unexpected device window found.\n");
608 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
609 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
610 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
611 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
612 ok(!!device_window
, "Device window not found.\n");
614 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
615 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
616 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
617 ok(!device_window
, "Unexpected device window found.\n");
618 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
619 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
620 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
621 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
622 ok(!!device_window
, "Device window not found.\n");
624 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
625 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
626 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
627 ok(!device_window
, "Unexpected device window found.\n");
628 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
629 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
630 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
631 ok(!device_window
, "Unexpected device window found.\n");
632 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
633 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
634 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
635 ok(!device_window
, "Unexpected device window found.\n");
636 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
637 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
638 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
639 ok(!!device_window
, "Device window not found.\n");
641 IDirectDraw2_Release(ddraw
);
642 DestroyWindow(focus_window
);
645 static void test_clipper_blt(void)
647 IDirectDrawSurface
*src_surface
, *dst_surface
;
648 RECT client_rect
, src_rect
;
649 IDirectDrawClipper
*clipper
;
650 DDSURFACEDESC surface_desc
;
651 unsigned int i
, j
, x
, y
;
663 static const DWORD src_data
[] =
665 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
666 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
667 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
669 static const D3DCOLOR expected1
[] =
671 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
672 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
673 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
674 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
676 /* Nvidia on Windows seems to have an off-by-one error
677 * when processing source rectangles. Our left = 1 and
678 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
679 * read as well, but only for the edge pixels on the
680 * output image. The bug happens on the y axis as well,
681 * but we only read one row there, and all source rows
682 * contain the same data. This bug is not dependent on
683 * the presence of a clipper. */
684 static const D3DCOLOR expected1_broken
[] =
686 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
687 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
688 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
689 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
691 static const D3DCOLOR expected2
[] =
693 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
694 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
695 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
696 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
699 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
700 10, 10, 640, 480, 0, 0, 0, 0);
701 ShowWindow(window
, SW_SHOW
);
702 ddraw
= create_ddraw();
703 ok(!!ddraw
, "Failed to create a ddraw object.\n");
705 ret
= GetClientRect(window
, &client_rect
);
706 ok(ret
, "Failed to get client rect.\n");
707 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
708 ok(ret
, "Failed to map client rect.\n");
710 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
711 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
713 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
714 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
715 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
716 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
717 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
718 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
719 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
720 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
721 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
722 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
723 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
724 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
725 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
726 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
727 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
728 "Got unexpected bounding rect %s, expected %s.\n",
729 wine_dbgstr_rect(&rgn_data
->rdh
.rcBound
), wine_dbgstr_rect(&client_rect
));
730 HeapFree(GetProcessHeap(), 0, rgn_data
);
732 r1
= CreateRectRgn(0, 0, 320, 240);
733 ok(!!r1
, "Failed to create region.\n");
734 r2
= CreateRectRgn(320, 240, 640, 480);
735 ok(!!r2
, "Failed to create region.\n");
736 CombineRgn(r1
, r1
, r2
, RGN_OR
);
737 ret
= GetRegionData(r1
, 0, NULL
);
738 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
739 ret
= GetRegionData(r1
, ret
, rgn_data
);
740 ok(!!ret
, "Failed to get region data.\n");
745 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
746 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
747 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
748 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
749 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
750 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
752 HeapFree(GetProcessHeap(), 0, rgn_data
);
754 memset(&surface_desc
, 0, sizeof(surface_desc
));
755 surface_desc
.dwSize
= sizeof(surface_desc
);
756 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
757 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
758 surface_desc
.dwWidth
= 640;
759 surface_desc
.dwHeight
= 480;
760 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
761 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
762 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
763 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
764 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
765 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
767 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
768 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
769 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
770 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
772 memset(&fx
, 0, sizeof(fx
));
773 fx
.dwSize
= sizeof(fx
);
774 hr
= IDirectDrawSurface_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
775 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
776 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
777 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
779 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
780 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
781 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
782 ptr
= surface_desc
.lpSurface
;
783 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
784 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
785 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
786 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
787 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
789 hr
= IDirectDrawSurface_SetClipper(dst_surface
, clipper
);
790 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
792 SetRect(&src_rect
, 1, 1, 5, 2);
793 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
794 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
795 for (i
= 0; i
< 4; ++i
)
797 for (j
= 0; j
< 4; ++j
)
799 x
= 80 * ((2 * j
) + 1);
800 y
= 60 * ((2 * i
) + 1);
801 color
= get_surface_color(dst_surface
, x
, y
);
802 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
803 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
804 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
808 U5(fx
).dwFillColor
= 0xff0000ff;
809 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
810 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
811 for (i
= 0; i
< 4; ++i
)
813 for (j
= 0; j
< 4; ++j
)
815 x
= 80 * ((2 * j
) + 1);
816 y
= 60 * ((2 * i
) + 1);
817 color
= get_surface_color(dst_surface
, x
, y
);
818 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
819 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
823 hr
= IDirectDrawSurface_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
824 ok(hr
== DDERR_BLTFASTCANTCLIP
|| broken(hr
== E_NOTIMPL
/* NT4 */), "Got unexpected hr %#x.\n", hr
);
826 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
827 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
828 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
829 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
830 DestroyWindow(window
);
831 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
832 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
833 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
834 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
835 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
836 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
837 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
838 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
839 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
840 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
841 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
842 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
844 IDirectDrawSurface_Release(dst_surface
);
845 IDirectDrawSurface_Release(src_surface
);
846 refcount
= IDirectDrawClipper_Release(clipper
);
847 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
848 IDirectDraw2_Release(ddraw
);
851 static void test_coop_level_d3d_state(void)
853 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
854 IDirectDrawSurface
*rt
, *surface
;
855 IDirect3DMaterial2
*background
;
856 IDirect3DViewport2
*viewport
;
857 IDirect3DDevice2
*device
;
858 D3DMATERIAL material
;
865 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
866 0, 0, 640, 480, 0, 0, 0, 0);
867 ddraw
= create_ddraw();
868 ok(!!ddraw
, "Failed to create a ddraw object.\n");
869 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
871 skip("Failed to create a 3D device, skipping test.\n");
872 IDirectDraw2_Release(ddraw
);
873 DestroyWindow(window
);
877 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
878 viewport
= create_viewport(device
, 0, 0, 640, 480);
879 viewport_set_background(device
, viewport
, background
);
881 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
882 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
883 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
884 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
885 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
886 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
887 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
888 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
889 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
890 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
891 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
892 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
893 color
= get_surface_color(rt
, 320, 240);
894 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
896 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
897 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
898 hr
= IDirectDrawSurface_IsLost(rt
);
899 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
900 hr
= restore_surfaces(ddraw
);
901 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
903 memset(&material
, 0, sizeof(material
));
904 material
.dwSize
= sizeof(material
);
905 U1(U(material
).diffuse
).r
= 0.0f
;
906 U2(U(material
).diffuse
).g
= 1.0f
;
907 U3(U(material
).diffuse
).b
= 0.0f
;
908 U4(U(material
).diffuse
).a
= 1.0f
;
909 hr
= IDirect3DMaterial2_SetMaterial(background
, &material
);
910 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
912 hr
= IDirect3DDevice2_GetRenderTarget(device
, &surface
);
913 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
914 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
915 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
916 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
917 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
918 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
919 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
920 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
921 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
922 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
923 color
= get_surface_color(rt
, 320, 240);
924 ok(compare_color(color
, 0x0000ff00, 1) || broken(compare_color(color
, 0x00000000, 1)),
925 "Got unexpected color 0x%08x.\n", color
);
927 destroy_viewport(device
, viewport
);
928 destroy_material(background
);
929 IDirectDrawSurface_Release(surface
);
930 IDirectDrawSurface_Release(rt
);
931 IDirect3DDevice2_Release(device
);
932 IDirectDraw2_Release(ddraw
);
933 DestroyWindow(window
);
936 static void test_surface_interface_mismatch(void)
938 IDirectDraw2
*ddraw
= NULL
;
939 IDirect3D2
*d3d
= NULL
;
940 IDirectDrawSurface
*surface
= NULL
, *ds
;
941 IDirectDrawSurface3
*surface3
= NULL
;
942 IDirect3DDevice2
*device
= NULL
;
943 IDirect3DViewport2
*viewport
= NULL
;
944 IDirect3DMaterial2
*background
= NULL
;
945 DDSURFACEDESC surface_desc
;
951 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
953 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
954 0, 0, 640, 480, 0, 0, 0, 0);
955 ddraw
= create_ddraw();
956 ok(!!ddraw
, "Failed to create a ddraw object.\n");
957 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
959 skip("Failed to create a 3D device, skipping test.\n");
960 IDirectDraw2_Release(ddraw
);
961 DestroyWindow(window
);
964 z_depth
= get_device_z_depth(device
);
965 ok(!!z_depth
, "Failed to get device z depth.\n");
966 IDirect3DDevice2_Release(device
);
969 memset(&surface_desc
, 0, sizeof(surface_desc
));
970 surface_desc
.dwSize
= sizeof(surface_desc
);
971 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
972 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
973 surface_desc
.dwWidth
= 640;
974 surface_desc
.dwHeight
= 480;
976 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
977 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
979 hr
= IDirectDrawSurface2_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
982 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
986 if (FAILED(IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
)))
988 skip("D3D interface is not available, skipping test.\n");
992 memset(&surface_desc
, 0, sizeof(surface_desc
));
993 surface_desc
.dwSize
= sizeof(surface_desc
);
994 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
995 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
996 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
997 surface_desc
.dwWidth
= 640;
998 surface_desc
.dwHeight
= 480;
999 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
1000 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
1004 /* Using a different surface interface version still works */
1005 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
1006 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
1007 refcount
= IDirectDrawSurface_Release(ds
);
1008 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1013 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface
*)surface3
, &device
);
1014 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
1018 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1019 viewport
= create_viewport(device
, 0, 0, 640, 480);
1020 viewport_set_background(device
, viewport
, background
);
1022 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1023 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1024 color
= get_surface_color(surface
, 320, 240);
1025 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
1029 destroy_viewport(device
, viewport
);
1031 destroy_material(background
);
1032 if (surface3
) IDirectDrawSurface3_Release(surface3
);
1033 if (surface
) IDirectDrawSurface_Release(surface
);
1034 if (device
) IDirect3DDevice2_Release(device
);
1035 if (d3d
) IDirect3D2_Release(d3d
);
1036 if (ddraw
) IDirectDraw2_Release(ddraw
);
1037 DestroyWindow(window
);
1040 static void test_coop_level_threaded(void)
1042 struct create_window_thread_param p
;
1043 IDirectDraw2
*ddraw
;
1046 ddraw
= create_ddraw();
1047 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1048 create_window_thread(&p
);
1050 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1051 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1053 IDirectDraw2_Release(ddraw
);
1054 destroy_window_thread(&p
);
1057 static void test_depth_blit(void)
1059 static D3DLVERTEX quad1
[] =
1061 {{-1.0}, { 1.0}, {0.50f
}, 0, {0xff00ff00}},
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}},
1066 static const D3DCOLOR expected_colors
[4][4] =
1068 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1069 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1070 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1071 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1073 DDSURFACEDESC ddsd_new
, ddsd_existing
;
1075 IDirect3DDevice2
*device
;
1076 IDirectDrawSurface
*ds1
, *ds2
, *ds3
, *rt
;
1077 IDirect3DViewport2
*viewport
;
1078 RECT src_rect
, dst_rect
;
1082 IDirectDraw2
*ddraw
;
1086 IDirect3DMaterial2
*background
;
1088 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1089 0, 0, 640, 480, 0, 0, 0, 0);
1090 ddraw
= create_ddraw();
1091 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1092 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1094 skip("Failed to create a 3D device, skipping test.\n");
1095 IDirectDraw2_Release(ddraw
);
1096 DestroyWindow(window
);
1100 ds1
= get_depth_stencil(device
);
1102 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1103 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1104 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1105 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1106 hr
= IDirectDrawSurface_GetSurfaceDesc(ds1
, &ddsd_existing
);
1107 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
1108 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1109 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1110 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1111 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1112 ddsd_new
.ddpfPixelFormat
= ddsd_existing
.ddpfPixelFormat
;
1113 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1114 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1115 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1116 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1118 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1119 viewport
= create_viewport(device
, 0, 0, ddsd_existing
.dwWidth
, ddsd_existing
.dwHeight
);
1120 viewport_set_background(device
, viewport
, background
);
1121 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1122 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
1124 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1125 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1126 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1127 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1129 U1(d3drect
).x1
= U2(d3drect
).y1
= 0;
1130 U3(d3drect
).x2
= ddsd_existing
.dwWidth
; U4(d3drect
).y2
= ddsd_existing
.dwHeight
;
1131 hr
= IDirect3DViewport2_Clear(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
);
1132 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1135 SetRect(&src_rect
, 0, 0, 320, 240);
1136 SetRect(&dst_rect
, 0, 0, 320, 240);
1137 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1138 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1139 /* Different locations. */
1140 SetRect(&src_rect
, 0, 0, 320, 240);
1141 SetRect(&dst_rect
, 320, 240, 640, 480);
1142 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1143 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1145 SetRect(&src_rect
, 0, 0, 320, 240);
1146 SetRect(&dst_rect
, 0, 0, 640, 480);
1147 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1148 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1150 SetRect(&src_rect
, 0, 480, 640, 0);
1151 SetRect(&dst_rect
, 0, 0, 640, 480);
1152 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1153 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1154 SetRect(&src_rect
, 0, 0, 640, 480);
1155 SetRect(&dst_rect
, 0, 480, 640, 0);
1156 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1157 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1158 /* Full, explicit. */
1159 SetRect(&src_rect
, 0, 0, 640, 480);
1160 SetRect(&dst_rect
, 0, 0, 640, 480);
1161 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1162 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1163 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1165 /* Depth blit inside a BeginScene / EndScene pair */
1166 hr
= IDirect3DDevice2_BeginScene(device
);
1167 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1168 /* From the current depth stencil */
1169 hr
= IDirectDrawSurface_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1170 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1171 /* To the current depth stencil */
1172 hr
= IDirectDrawSurface_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1173 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1174 /* Between unbound surfaces */
1175 hr
= IDirectDrawSurface_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1176 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1177 hr
= IDirect3DDevice2_EndScene(device
);
1178 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1180 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1181 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1182 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1183 * a reliable result(z = 0.0) */
1184 memset(&fx
, 0, sizeof(fx
));
1185 fx
.dwSize
= sizeof(fx
);
1186 U5(fx
).dwFillDepth
= 0;
1187 hr
= IDirectDrawSurface_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1188 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1190 /* This clears the Z buffer with 1.0 */
1191 hr
= IDirect3DViewport2_Clear(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
);
1192 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1194 SetRect(&dst_rect
, 0, 0, 320, 240);
1195 hr
= IDirectDrawSurface_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1196 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1197 IDirectDrawSurface_Release(ds3
);
1198 IDirectDrawSurface_Release(ds2
);
1199 IDirectDrawSurface_Release(ds1
);
1201 hr
= IDirect3DDevice2_BeginScene(device
);
1202 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1203 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad1
, 4, 0);
1204 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1205 hr
= IDirect3DDevice2_EndScene(device
);
1206 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1208 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1209 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1210 for (i
= 0; i
< 4; ++i
)
1212 for (j
= 0; j
< 4; ++j
)
1214 unsigned int x
= 80 * ((2 * j
) + 1);
1215 unsigned int y
= 60 * ((2 * i
) + 1);
1216 color
= get_surface_color(rt
, x
, y
);
1217 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1218 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1221 IDirectDrawSurface_Release(rt
);
1223 destroy_viewport(device
, viewport
);
1224 destroy_material(background
);
1225 IDirect3DDevice2_Release(device
);
1226 IDirectDraw2_Release(ddraw
);
1227 DestroyWindow(window
);
1230 static void test_texture_load_ckey(void)
1232 IDirectDraw2
*ddraw
= NULL
;
1233 IDirectDrawSurface
*src
= NULL
;
1234 IDirectDrawSurface
*dst
= NULL
;
1235 IDirect3DTexture
*src_tex
= NULL
;
1236 IDirect3DTexture
*dst_tex
= NULL
;
1241 ddraw
= create_ddraw();
1242 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1243 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
1244 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1246 memset(&ddsd
, 0, sizeof(ddsd
));
1247 ddsd
.dwSize
= sizeof(ddsd
);
1248 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1249 ddsd
.dwHeight
= 128;
1251 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1252 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1253 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1254 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1255 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1256 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1258 hr
= IDirectDrawSurface_QueryInterface(src
, &IID_IDirect3DTexture
, (void **)&src_tex
);
1259 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get Direct3DTexture interface, hr %#x.\n", hr
);
1262 /* 64 bit ddraw does not support d3d */
1263 skip("Could not get Direct3DTexture interface, skipping texture::Load color keying tests.\n");
1266 hr
= IDirectDrawSurface_QueryInterface(dst
, &IID_IDirect3DTexture
, (void **)&dst_tex
);
1267 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture interface, hr %#x.\n", hr
);
1269 /* No surface has a color key */
1270 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1271 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDCAPS
), "Got unexpected hr %#x.\n", hr
);
1274 /* Testbot Windows NT VMs */
1275 skip("IDirect3DTexture::Load does not work, skipping color keying tests.\n");
1279 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1280 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1281 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1282 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1283 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1285 /* Source surface has a color key */
1286 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1287 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1288 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1289 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1290 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1291 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1292 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1293 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1294 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1296 /* Both surfaces have a color key: Dest ckey is overwritten */
1297 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1298 hr
= IDirectDrawSurface_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1299 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1300 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1301 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1302 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1303 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1304 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1305 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1307 /* Only the destination has a color key: It is not deleted */
1308 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1309 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1310 hr
= IDirectDrawSurface_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1311 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1312 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1313 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1314 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1315 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1316 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1317 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1320 if (dst_tex
) IDirect3DTexture_Release(dst_tex
);
1321 if (src_tex
) IDirect3DTexture_Release(src_tex
);
1322 if (dst
) IDirectDrawSurface_Release(dst
);
1323 if (src
) IDirectDrawSurface_Release(src
);
1324 if (ddraw
) IDirectDraw2_Release(ddraw
);
1327 static ULONG
get_refcount(IUnknown
*test_iface
)
1329 IUnknown_AddRef(test_iface
);
1330 return IUnknown_Release(test_iface
);
1333 static void test_viewport(void)
1335 IDirectDraw2
*ddraw
;
1338 ULONG ref
, old_d3d_ref
;
1339 IDirect3DViewport
*viewport
;
1340 IDirect3DViewport2
*viewport2
, *another_vp
, *test_vp
;
1341 IDirect3DViewport3
*viewport3
;
1342 IDirectDrawGammaControl
*gamma
;
1344 IDirect3DDevice2
*device
;
1347 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1348 0, 0, 640, 480, 0, 0, 0, 0);
1349 ddraw
= create_ddraw();
1350 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1351 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1353 skip("Failed to create a 3D device, skipping test.\n");
1354 IDirectDraw_Release(ddraw
);
1355 DestroyWindow(window
);
1359 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
1360 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get d3d interface, hr %#x.\n", hr
);
1363 skip("D3D interface is not available, skipping test.\n");
1364 IDirectDraw2_Release(ddraw
);
1367 old_d3d_ref
= get_refcount((IUnknown
*)d3d
);
1369 hr
= IDirect3D2_CreateViewport(d3d
, &viewport2
, NULL
);
1370 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1371 ref
= get_refcount((IUnknown
*)viewport2
);
1372 ok(ref
== 1, "Initial IDirect3DViewport2 refcount is %u\n", ref
);
1373 ref
= get_refcount((IUnknown
*)d3d
);
1374 ok(ref
== old_d3d_ref
, "IDirect3D2 refcount is %u\n", ref
);
1376 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1377 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1378 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
1379 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1380 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1381 /* NULL iid: Segfaults */
1383 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirect3DViewport
, (void **)&viewport
);
1384 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport, hr %#x.\n", hr
);
1387 ref
= get_refcount((IUnknown
*)viewport
);
1388 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1389 ref
= get_refcount((IUnknown
*)viewport2
);
1390 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1391 IDirect3DViewport_Release(viewport
);
1395 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirect3DViewport3
, (void **)&viewport3
);
1396 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1399 ref
= get_refcount((IUnknown
*)viewport2
);
1400 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1401 ref
= get_refcount((IUnknown
*)viewport3
);
1402 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1403 IDirect3DViewport3_Release(viewport3
);
1406 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IUnknown
, (void **)&unknown
);
1407 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1410 ref
= get_refcount((IUnknown
*)viewport2
);
1411 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1412 ref
= get_refcount(unknown
);
1413 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1414 IUnknown_Release(unknown
);
1417 /* AddViewport(NULL): Segfault */
1418 hr
= IDirect3DDevice2_DeleteViewport(device
, NULL
);
1419 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1420 hr
= IDirect3DDevice2_GetCurrentViewport(device
, NULL
);
1421 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1423 hr
= IDirect3D2_CreateViewport(d3d
, &another_vp
, NULL
);
1424 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1426 /* Setting a viewport not in the viewport list fails */
1427 hr
= IDirect3DDevice2_SetCurrentViewport(device
, another_vp
);
1428 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1430 hr
= IDirect3DDevice2_AddViewport(device
, viewport2
);
1431 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1432 ref
= get_refcount((IUnknown
*) viewport2
);
1433 ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1434 hr
= IDirect3DDevice2_AddViewport(device
, another_vp
);
1435 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1436 ref
= get_refcount((IUnknown
*) another_vp
);
1437 ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1439 test_vp
= (IDirect3DViewport2
*) 0xbaadc0de;
1440 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1441 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1442 ok(test_vp
== (IDirect3DViewport2
*) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp
);
1444 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
1445 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1446 ref
= get_refcount((IUnknown
*) viewport2
);
1447 ok(ref
== 3, "viewport2 refcount is %d\n", ref
);
1448 ref
= get_refcount((IUnknown
*) device
);
1449 ok(ref
== 1, "device refcount is %d\n", ref
);
1452 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1453 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1454 ok(test_vp
== viewport2
, "Got unexpected viewport %p\n", test_vp
);
1455 ref
= get_refcount((IUnknown
*) viewport2
);
1456 ok(ref
== 4, "viewport2 refcount is %d\n", ref
);
1457 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1459 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1461 /* Cannot set the viewport to NULL */
1462 hr
= IDirect3DDevice2_SetCurrentViewport(device
, NULL
);
1463 ok(hr
== DDERR_INVALIDPARAMS
, "Failed to set viewport to NULL, hr %#x.\n", hr
);
1465 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1466 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1467 ok(test_vp
== viewport2
, "Got unexpected viewport %p\n", test_vp
);
1468 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1470 /* SetCurrentViewport properly releases the old viewport's reference */
1471 hr
= IDirect3DDevice2_SetCurrentViewport(device
, another_vp
);
1472 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1473 ref
= get_refcount((IUnknown
*) viewport2
);
1474 ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1475 ref
= get_refcount((IUnknown
*) another_vp
);
1476 ok(ref
== 3, "another_vp refcount is %d\n", ref
);
1478 /* Deleting the viewport removes the reference added by AddViewport, but not
1479 * the one added by SetCurrentViewport. */
1480 hr
= IDirect3DDevice2_DeleteViewport(device
, another_vp
);
1481 ok(SUCCEEDED(hr
), "Failed to delete viewport from device, hr %#x.\n", hr
);
1482 ref
= get_refcount((IUnknown
*) another_vp
);
1483 todo_wine
ok(ref
== 2, "IDirect3DViewport2 refcount is %d\n", ref
);
1485 /* GetCurrentViewport fails though */
1487 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1488 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1489 ok(test_vp
== NULL
, "Got unexpected viewport %p\n", test_vp
);
1490 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1492 /* Setting a different viewport does not free the leaked reference. How
1493 * do I get rid of it? Leak the viewport for now. */
1494 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
1495 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1496 ref
= get_refcount((IUnknown
*) viewport2
);
1497 ok(ref
== 3, "viewport2 refcount is %d\n", ref
);
1498 ref
= get_refcount((IUnknown
*) another_vp
);
1499 todo_wine
ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1501 /* Destroying the device removes the viewport, but does not free the reference
1502 * added by SetCurrentViewport. */
1503 IDirect3DDevice2_Release(device
);
1504 ref
= get_refcount((IUnknown
*) viewport2
);
1505 todo_wine
ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1507 IDirect3DViewport2_Release(another_vp
);
1508 IDirect3DViewport2_Release(viewport2
);
1509 IDirect3D2_Release(d3d
);
1510 DestroyWindow(window
);
1511 IDirectDraw2_Release(ddraw
);
1514 static void test_zenable(void)
1516 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1517 static D3DTLVERTEX tquad
[] =
1519 {{ 0.0f
}, {480.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1520 {{ 0.0f
}, { 0.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1521 {{640.0f
}, {480.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1522 {{640.0f
}, { 0.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1524 IDirect3DMaterial2
*background
;
1525 IDirect3DViewport2
*viewport
;
1526 IDirect3DDevice2
*device
;
1527 IDirectDrawSurface
*rt
;
1528 IDirectDraw2
*ddraw
;
1535 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1536 0, 0, 640, 480, 0, 0, 0, 0);
1537 ddraw
= create_ddraw();
1538 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1539 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1541 skip("Failed to create a 3D device, skipping test.\n");
1542 IDirectDraw2_Release(ddraw
);
1543 DestroyWindow(window
);
1547 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1548 viewport
= create_viewport(device
, 0, 0, 640, 480);
1549 viewport_set_background(device
, viewport
, background
);
1550 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1551 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1553 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1554 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1556 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1557 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1558 hr
= IDirect3DDevice2_BeginScene(device
);
1559 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1560 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, tquad
, 4, 0);
1561 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1562 hr
= IDirect3DDevice2_EndScene(device
);
1563 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1565 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1566 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1567 for (i
= 0; i
< 4; ++i
)
1569 for (j
= 0; j
< 4; ++j
)
1571 x
= 80 * ((2 * j
) + 1);
1572 y
= 60 * ((2 * i
) + 1);
1573 color
= get_surface_color(rt
, x
, y
);
1574 ok(compare_color(color
, 0x0000ff00, 1),
1575 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1578 IDirectDrawSurface_Release(rt
);
1580 destroy_viewport(device
, viewport
);
1581 destroy_material(background
);
1582 IDirect3DDevice2_Release(device
);
1583 IDirectDraw2_Release(ddraw
);
1584 DestroyWindow(window
);
1587 static void test_ck_rgba(void)
1589 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1590 static D3DTLVERTEX tquad
[] =
1592 {{ 0.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1593 {{ 0.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1594 {{640.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1595 {{640.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1596 {{ 0.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1597 {{ 0.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1598 {{640.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1599 {{640.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1603 D3DCOLOR fill_color
;
1606 D3DCOLOR result1
, result1_broken
;
1607 D3DCOLOR result2
, result2_broken
;
1611 /* r200 on Windows doesn't check the alpha component when applying the color
1612 * key, so the key matches on every texel. */
1613 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1614 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1615 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1616 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1617 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1618 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1619 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1620 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1623 D3DTEXTUREHANDLE texture_handle
;
1624 IDirect3DMaterial2
*background
;
1625 IDirectDrawSurface
*surface
;
1626 IDirect3DViewport2
*viewport
;
1627 IDirect3DTexture2
*texture
;
1628 DDSURFACEDESC surface_desc
;
1629 IDirect3DDevice2
*device
;
1630 IDirectDrawSurface
*rt
;
1631 IDirectDraw2
*ddraw
;
1638 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1639 0, 0, 640, 480, 0, 0, 0, 0);
1640 ddraw
= create_ddraw();
1641 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1642 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1644 skip("Failed to create a 3D device, skipping test.\n");
1645 IDirectDraw2_Release(ddraw
);
1646 DestroyWindow(window
);
1650 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1651 viewport
= create_viewport(device
, 0, 0, 640, 480);
1652 viewport_set_background(device
, viewport
, background
);
1653 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1654 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1656 memset(&surface_desc
, 0, sizeof(surface_desc
));
1657 surface_desc
.dwSize
= sizeof(surface_desc
);
1658 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1659 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1660 surface_desc
.dwWidth
= 256;
1661 surface_desc
.dwHeight
= 256;
1662 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1663 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1664 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1665 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1666 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1667 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1668 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1669 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1670 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1671 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1672 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1673 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1674 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1675 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
1676 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1677 IDirect3DTexture2_Release(texture
);
1679 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1680 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1681 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1682 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1683 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1684 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1686 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1687 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1689 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1691 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1692 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1693 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1694 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1696 memset(&fx
, 0, sizeof(fx
));
1697 fx
.dwSize
= sizeof(fx
);
1698 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1699 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1700 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1702 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
1703 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1704 hr
= IDirect3DDevice2_BeginScene(device
);
1705 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1706 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1707 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1708 hr
= IDirect3DDevice2_EndScene(device
);
1709 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1711 color
= get_surface_color(rt
, 320, 240);
1712 ok(compare_color(color
, tests
[i
].result1
, 1) || compare_color(color
, tests
[i
].result1_broken
, 1),
1713 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1714 tests
[i
].result1
, i
, color
);
1716 U5(fx
).dwFillColor
= 0xff0000ff;
1717 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1718 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1720 hr
= IDirect3DDevice2_BeginScene(device
);
1721 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1722 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[4], 4, 0);
1723 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1724 hr
= IDirect3DDevice2_EndScene(device
);
1725 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1727 /* This tests that fragments that are masked out by the color key are
1728 * discarded, instead of just fully transparent. */
1729 color
= get_surface_color(rt
, 320, 240);
1730 ok(compare_color(color
, tests
[i
].result2
, 1) || compare_color(color
, tests
[i
].result2_broken
, 1),
1731 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1732 tests
[i
].result2
, i
, color
);
1735 IDirectDrawSurface_Release(rt
);
1736 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1737 ok(SUCCEEDED(hr
), "Failed to unset texture, hr %#x.\n", hr
);
1738 IDirectDrawSurface_Release(surface
);
1739 destroy_viewport(device
, viewport
);
1740 destroy_material(background
);
1741 IDirect3DDevice2_Release(device
);
1742 IDirectDraw2_Release(ddraw
);
1743 DestroyWindow(window
);
1746 static void test_ck_default(void)
1748 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1749 static D3DTLVERTEX tquad
[] =
1751 {{ 0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1752 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1753 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1754 {{640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1756 IDirectDrawSurface
*surface
, *rt
;
1757 D3DTEXTUREHANDLE texture_handle
;
1758 IDirect3DMaterial2
*background
;
1759 IDirect3DViewport2
*viewport
;
1760 DDSURFACEDESC surface_desc
;
1761 IDirect3DTexture2
*texture
;
1762 IDirect3DDevice2
*device
;
1763 IDirectDraw2
*ddraw
;
1770 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1771 0, 0, 640, 480, 0, 0, 0, 0);
1772 ddraw
= create_ddraw();
1773 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1774 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1776 skip("Failed to create a 3D device, skipping test.\n");
1777 IDirectDraw2_Release(ddraw
);
1778 DestroyWindow(window
);
1782 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1783 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1785 background
= create_diffuse_material(device
, 0.0, 1.0f
, 0.0f
, 1.0f
);
1786 viewport
= create_viewport(device
, 0, 0, 640, 480);
1787 viewport_set_background(device
, viewport
, background
);
1788 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1789 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1791 memset(&surface_desc
, 0, sizeof(surface_desc
));
1792 surface_desc
.dwSize
= sizeof(surface_desc
);
1793 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1794 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1795 surface_desc
.dwWidth
= 256;
1796 surface_desc
.dwHeight
= 256;
1797 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1798 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1799 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1800 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1801 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1802 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1803 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1804 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1805 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1806 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1807 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1808 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1809 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
1810 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1811 IDirect3DTexture_Release(texture
);
1813 memset(&fx
, 0, sizeof(fx
));
1814 fx
.dwSize
= sizeof(fx
);
1815 U5(fx
).dwFillColor
= 0x000000ff;
1816 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1817 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1819 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1820 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1821 hr
= IDirect3DDevice2_BeginScene(device
);
1822 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1823 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1824 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
1825 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1826 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1827 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1828 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1829 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1830 hr
= IDirect3DDevice2_EndScene(device
);
1831 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1832 color
= get_surface_color(rt
, 320, 240);
1833 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1835 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1836 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1837 hr
= IDirect3DDevice2_BeginScene(device
);
1838 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1839 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1840 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1841 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1842 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1843 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1844 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1845 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1846 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1847 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
1848 hr
= IDirect3DDevice2_EndScene(device
);
1849 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1850 color
= get_surface_color(rt
, 320, 240);
1851 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1853 IDirectDrawSurface_Release(surface
);
1854 destroy_viewport(device
, viewport
);
1855 destroy_material(background
);
1856 IDirectDrawSurface_Release(rt
);
1857 IDirect3DDevice2_Release(device
);
1858 IDirectDraw2_Release(ddraw
);
1859 DestroyWindow(window
);
1862 static void test_ck_complex(void)
1864 IDirectDrawSurface
*surface
, *mipmap
, *tmp
;
1865 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
1866 DDSURFACEDESC surface_desc
;
1867 IDirect3DDevice2
*device
;
1868 DDCOLORKEY color_key
;
1869 IDirectDraw2
*ddraw
;
1875 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1876 0, 0, 640, 480, 0, 0, 0, 0);
1877 ddraw
= create_ddraw();
1878 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1879 if (!(device
= create_device(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1881 skip("Failed to create a 3D device, skipping test.\n");
1882 DestroyWindow(window
);
1883 IDirectDraw2_Release(ddraw
);
1886 IDirect3DDevice2_Release(device
);
1888 memset(&surface_desc
, 0, sizeof(surface_desc
));
1889 surface_desc
.dwSize
= sizeof(surface_desc
);
1890 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1891 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1892 surface_desc
.dwWidth
= 128;
1893 surface_desc
.dwHeight
= 128;
1894 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1895 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1897 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1898 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1899 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1900 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1901 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1902 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1903 memset(&color_key
, 0, sizeof(color_key
));
1904 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1905 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1906 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1907 color_key
.dwColorSpaceLowValue
);
1908 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1909 color_key
.dwColorSpaceHighValue
);
1912 IDirectDrawSurface_AddRef(mipmap
);
1913 for (i
= 0; i
< 7; ++i
)
1915 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1916 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1918 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1919 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1920 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1921 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1922 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1923 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x, i %u.\n", hr
, i
);
1924 memset(&color_key
, 0, sizeof(color_key
));
1925 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1926 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x, i %u.\n", hr
, i
);
1927 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1928 color_key
.dwColorSpaceLowValue
, i
);
1929 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1930 color_key
.dwColorSpaceHighValue
, i
);
1932 IDirectDrawSurface_Release(mipmap
);
1936 memset(&color_key
, 0, sizeof(color_key
));
1937 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1938 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1939 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1940 color_key
.dwColorSpaceLowValue
);
1941 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1942 color_key
.dwColorSpaceHighValue
);
1944 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1945 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1946 IDirectDrawSurface_Release(mipmap
);
1947 refcount
= IDirectDrawSurface_Release(surface
);
1948 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1950 memset(&surface_desc
, 0, sizeof(surface_desc
));
1951 surface_desc
.dwSize
= sizeof(surface_desc
);
1952 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1953 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1954 surface_desc
.dwBackBufferCount
= 1;
1955 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1956 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1958 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1959 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1960 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1961 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1962 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1963 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1964 memset(&color_key
, 0, sizeof(color_key
));
1965 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1966 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1967 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1968 color_key
.dwColorSpaceLowValue
);
1969 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1970 color_key
.dwColorSpaceHighValue
);
1972 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
1973 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
1975 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1976 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1977 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1978 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1979 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1980 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1981 memset(&color_key
, 0, sizeof(color_key
));
1982 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1983 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1984 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1985 color_key
.dwColorSpaceLowValue
);
1986 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1987 color_key
.dwColorSpaceHighValue
);
1989 IDirectDrawSurface_Release(tmp
);
1991 refcount
= IDirectDrawSurface_Release(surface
);
1992 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1993 refcount
= IDirectDraw2_Release(ddraw
);
1994 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1995 DestroyWindow(window
);
2001 REFIID refcount_iid
;
2005 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
2006 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
2008 ULONG refcount
, expected_refcount
;
2009 IUnknown
*iface1
, *iface2
;
2013 for (i
= 0; i
< entry_count
; ++i
)
2015 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
2016 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
2019 for (j
= 0; j
< entry_count
; ++j
)
2021 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
2022 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
2025 expected_refcount
= 0;
2026 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
2027 ++expected_refcount
;
2028 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
2029 ++expected_refcount
;
2030 refcount
= IUnknown_Release(iface2
);
2031 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2032 refcount
, test_name
, i
, j
, expected_refcount
);
2036 expected_refcount
= 0;
2037 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
2038 ++expected_refcount
;
2039 refcount
= IUnknown_Release(iface1
);
2040 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2041 refcount
, test_name
, i
, expected_refcount
);
2046 static void test_surface_qi(void)
2048 static const struct qi_test tests
[] =
2050 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface
, S_OK
},
2051 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface
, S_OK
},
2052 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
2053 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2054 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
2055 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
2056 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
2057 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
2058 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
2059 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
2060 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
2061 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
2062 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
2063 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
2064 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
2065 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
2066 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
2067 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
2068 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
2069 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
2070 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
2071 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
2072 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
2073 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
2074 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
2075 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
2076 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
2077 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
2078 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
2079 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
2080 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
2081 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
2082 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
2083 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
2084 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
2087 IDirectDrawSurface
*surface
;
2088 DDSURFACEDESC surface_desc
;
2089 IDirect3DDevice2
*device
;
2090 IDirectDraw2
*ddraw
;
2094 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2096 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2100 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2101 0, 0, 640, 480, 0, 0, 0, 0);
2102 ddraw
= create_ddraw();
2103 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2104 /* Try to create a D3D device to see if the ddraw implementation supports
2105 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2106 * doesn't support e.g. the IDirect3DTexture interfaces. */
2107 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
2109 skip("Failed to create a 3D device, skipping test.\n");
2110 IDirectDraw2_Release(ddraw
);
2111 DestroyWindow(window
);
2114 IDirect3DDevice_Release(device
);
2116 memset(&surface_desc
, 0, sizeof(surface_desc
));
2117 surface_desc
.dwSize
= sizeof(surface_desc
);
2118 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2119 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2120 surface_desc
.dwWidth
= 512;
2121 surface_desc
.dwHeight
= 512;
2122 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, (IDirectDrawSurface
**)0xdeadbeef, NULL
);
2123 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
2124 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2125 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2127 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface
, tests
, sizeof(tests
) / sizeof(*tests
));
2129 IDirectDrawSurface_Release(surface
);
2130 IDirectDraw2_Release(ddraw
);
2131 DestroyWindow(window
);
2134 static void test_device_qi(void)
2136 static const struct qi_test tests
[] =
2138 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
2139 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
2140 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
2141 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2142 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
2143 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
2144 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
2145 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
2146 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
2147 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
2148 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
2149 {&IID_IDirect3DDevice2
, &IID_IDirect3DDevice2
, S_OK
},
2150 {&IID_IDirect3DDevice
, &IID_IDirect3DDevice2
, S_OK
},
2151 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
2152 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
2153 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
2154 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
2155 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
2156 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
2157 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
2158 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
2159 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
2160 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
2161 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
2162 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
2163 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
2164 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
2165 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
2166 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
2167 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
2168 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
2169 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
2170 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
2171 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
2172 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
2173 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
2174 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
2175 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
2176 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
2177 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
2178 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
2179 {&IID_IUnknown
, &IID_IDirect3DDevice2
, S_OK
},
2182 IDirect3DDevice2
*device
;
2183 IDirectDraw2
*ddraw
;
2186 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2187 0, 0, 640, 480, 0, 0, 0, 0);
2188 ddraw
= create_ddraw();
2189 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2190 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
2192 skip("Failed to create a 3D device, skipping test.\n");
2193 IDirectDraw2_Release(ddraw
);
2194 DestroyWindow(window
);
2198 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice2
, tests
, sizeof(tests
) / sizeof(*tests
));
2200 IDirect3DDevice2_Release(device
);
2201 IDirectDraw2_Release(ddraw
);
2202 DestroyWindow(window
);
2205 static void test_wndproc(void)
2207 LONG_PTR proc
, ddraw_proc
;
2208 IDirectDraw2
*ddraw
;
2214 static struct message messages
[] =
2216 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2217 {WM_MOVE
, FALSE
, 0},
2218 {WM_SIZE
, FALSE
, 0},
2219 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2220 {WM_ACTIVATE
, FALSE
, 0},
2221 {WM_SETFOCUS
, FALSE
, 0},
2225 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2226 ddraw
= create_ddraw();
2227 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2229 wc
.lpfnWndProc
= test_proc
;
2230 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2231 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2233 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2234 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2236 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2237 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2238 (LONG_PTR
)test_proc
, proc
);
2239 expect_messages
= messages
;
2240 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2241 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2242 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2243 expect_messages
= NULL
;
2244 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2245 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2246 (LONG_PTR
)test_proc
, proc
);
2247 ref
= IDirectDraw2_Release(ddraw
);
2248 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2249 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2250 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2251 (LONG_PTR
)test_proc
, proc
);
2253 /* DDSCL_NORMAL doesn't. */
2254 ddraw
= create_ddraw();
2255 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2256 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2257 (LONG_PTR
)test_proc
, proc
);
2258 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2259 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2260 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2261 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2262 (LONG_PTR
)test_proc
, proc
);
2263 ref
= IDirectDraw2_Release(ddraw
);
2264 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2265 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2266 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2267 (LONG_PTR
)test_proc
, proc
);
2269 /* The original window proc is only restored by ddraw if the current
2270 * window proc matches the one ddraw set. This also affects switching
2271 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2272 ddraw
= create_ddraw();
2273 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2274 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2275 (LONG_PTR
)test_proc
, proc
);
2276 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2277 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2278 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2279 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2280 (LONG_PTR
)test_proc
, proc
);
2282 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2283 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2284 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2285 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2286 (LONG_PTR
)test_proc
, proc
);
2287 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2288 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2289 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2290 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2291 (LONG_PTR
)test_proc
, proc
);
2292 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2293 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2294 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2295 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2296 (LONG_PTR
)DefWindowProcA
, proc
);
2297 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2298 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2299 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2300 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2301 (LONG_PTR
)DefWindowProcA
, proc
);
2302 ref
= IDirectDraw2_Release(ddraw
);
2303 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2304 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2305 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2306 (LONG_PTR
)test_proc
, proc
);
2308 ddraw
= create_ddraw();
2309 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2310 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2311 (LONG_PTR
)test_proc
, proc
);
2312 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2313 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2314 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2315 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2316 (LONG_PTR
)test_proc
, proc
);
2317 ref
= IDirectDraw2_Release(ddraw
);
2318 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2319 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2320 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2321 (LONG_PTR
)DefWindowProcA
, proc
);
2323 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2324 expect_messages
= NULL
;
2325 DestroyWindow(window
);
2326 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2329 static void test_window_style(void)
2331 LONG style
, exstyle
, tmp
, expected_style
;
2332 RECT fullscreen_rect
, r
;
2333 IDirectDraw2
*ddraw
;
2339 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2340 0, 0, 100, 100, 0, 0, 0, 0);
2341 ddraw
= create_ddraw();
2342 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2344 style
= GetWindowLongA(window
, GWL_STYLE
);
2345 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2346 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2348 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2349 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2351 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2352 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2353 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2354 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2356 GetWindowRect(window
, &r
);
2357 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
2358 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
2359 GetClientRect(window
, &r
);
2360 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2362 ret
= SetForegroundWindow(GetDesktopWindow());
2363 ok(ret
, "Failed to set foreground window.\n");
2365 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2366 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2367 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2368 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2370 ret
= SetForegroundWindow(window
);
2371 ok(ret
, "Failed to set foreground window.\n");
2372 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2373 * the next tests expect this. */
2374 ShowWindow(window
, SW_HIDE
);
2376 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2377 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2379 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2380 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2381 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2382 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2384 ShowWindow(window
, SW_SHOW
);
2385 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2386 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2388 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2389 expected_style
= style
| WS_VISIBLE
;
2390 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2391 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2392 expected_style
= exstyle
| WS_EX_TOPMOST
;
2393 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2395 ret
= SetForegroundWindow(GetDesktopWindow());
2396 ok(ret
, "Failed to set foreground window.\n");
2397 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2398 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2399 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2400 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2401 expected_style
= exstyle
| WS_EX_TOPMOST
;
2402 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2404 ref
= IDirectDraw2_Release(ddraw
);
2405 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2407 DestroyWindow(window
);
2410 static void test_redundant_mode_set(void)
2412 DDSURFACEDESC surface_desc
= {0};
2413 IDirectDraw2
*ddraw
;
2419 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2420 0, 0, 100, 100, 0, 0, 0, 0);
2421 ddraw
= create_ddraw();
2422 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2424 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2425 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2427 surface_desc
.dwSize
= sizeof(surface_desc
);
2428 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
2429 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
2431 hr
= IDirectDraw2_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2432 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2433 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2435 GetWindowRect(window
, &r
);
2438 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2439 GetWindowRect(window
, &s
);
2440 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2442 hr
= IDirectDraw2_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2443 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2444 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2446 GetWindowRect(window
, &s
);
2447 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2449 ref
= IDirectDraw2_Release(ddraw
);
2450 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2452 DestroyWindow(window
);
2455 static SIZE screen_size
, screen_size2
;
2457 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2459 if (message
== WM_SIZE
)
2461 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2462 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2465 return test_proc(hwnd
, message
, wparam
, lparam
);
2468 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2470 if (message
== WM_SIZE
)
2472 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2473 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2476 return test_proc(hwnd
, message
, wparam
, lparam
);
2479 struct test_coop_level_mode_set_enum_param
2481 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2484 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC
*surface_desc
, void *context
)
2486 struct test_coop_level_mode_set_enum_param
*param
= context
;
2488 if (U1(surface_desc
->ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2489 return DDENUMRET_OK
;
2490 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2491 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2492 return DDENUMRET_OK
;
2494 if (!param
->ddraw_width
)
2496 param
->ddraw_width
= surface_desc
->dwWidth
;
2497 param
->ddraw_height
= surface_desc
->dwHeight
;
2498 return DDENUMRET_OK
;
2500 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2501 return DDENUMRET_OK
;
2503 param
->user32_width
= surface_desc
->dwWidth
;
2504 param
->user32_height
= surface_desc
->dwHeight
;
2505 return DDENUMRET_CANCEL
;
2508 static void test_coop_level_mode_set(void)
2510 IDirectDrawSurface
*primary
;
2511 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2512 IDirectDraw2
*ddraw
;
2515 HWND window
, window2
;
2519 struct test_coop_level_mode_set_enum_param param
;
2524 static const struct message exclusive_messages
[] =
2526 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2527 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2528 {WM_SIZE
, FALSE
, 0},
2529 {WM_DISPLAYCHANGE
, FALSE
, 0},
2532 static const struct message exclusive_focus_loss_messages
[] =
2534 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2535 {WM_DISPLAYCHANGE
, FALSE
, 0},
2536 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2537 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2538 * SW_MINIMIZED, causing a recursive window activation that does not
2539 * produce the same result in Wine yet. Ignore the difference for now.
2540 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2541 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2542 {WM_MOVE
, FALSE
, 0},
2543 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2544 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2547 static const struct message exclusive_focus_restore_messages
[] =
2549 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2550 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2551 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2552 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2553 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2554 /* Native redundantly sets the window size here. */
2555 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2556 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2557 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2558 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2561 static const struct message sc_restore_messages
[] =
2563 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2564 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2565 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2566 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2569 static const struct message sc_minimize_messages
[] =
2571 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2572 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2573 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2574 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2577 static const struct message sc_maximize_messages
[] =
2579 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2580 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2581 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2582 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2586 static const struct message normal_messages
[] =
2588 {WM_DISPLAYCHANGE
, FALSE
, 0},
2592 ddraw
= create_ddraw();
2593 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2595 memset(¶m
, 0, sizeof(param
));
2596 hr
= IDirectDraw2_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2597 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2598 ref
= IDirectDraw2_Release(ddraw
);
2599 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2601 if (!param
.user32_height
)
2603 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2607 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2608 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2609 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2611 memset(&devmode
, 0, sizeof(devmode
));
2612 devmode
.dmSize
= sizeof(devmode
);
2613 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2614 devmode
.dmPelsWidth
= param
.user32_width
;
2615 devmode
.dmPelsHeight
= param
.user32_height
;
2616 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2617 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2619 ddraw
= create_ddraw();
2620 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2622 wc
.lpfnWndProc
= mode_set_proc
;
2623 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2624 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2625 wc
.lpfnWndProc
= mode_set_proc2
;
2626 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2627 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2629 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2630 0, 0, 100, 100, 0, 0, 0, 0);
2631 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2632 0, 0, 100, 100, 0, 0, 0, 0);
2634 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2635 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2637 GetWindowRect(window
, &r
);
2638 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2639 wine_dbgstr_rect(&r
));
2641 memset(&ddsd
, 0, sizeof(ddsd
));
2642 ddsd
.dwSize
= sizeof(ddsd
);
2643 ddsd
.dwFlags
= DDSD_CAPS
;
2644 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2646 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2647 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2648 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2649 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2650 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2651 param
.user32_width
, ddsd
.dwWidth
);
2652 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2653 param
.user32_height
, ddsd
.dwHeight
);
2655 GetWindowRect(window
, &r
);
2656 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2657 wine_dbgstr_rect(&r
));
2659 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2660 expect_messages
= exclusive_messages
;
2664 hr
= IDirectDrawSurface_IsLost(primary
);
2665 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2666 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2667 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2668 hr
= IDirectDrawSurface_IsLost(primary
);
2669 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2671 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2672 expect_messages
= NULL
;
2673 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2674 "Expected screen size %ux%u, got %ux%u.\n",
2675 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2677 GetWindowRect(window
, &r
);
2678 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2679 wine_dbgstr_rect(&r
));
2681 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2682 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2683 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2684 param
.user32_width
, ddsd
.dwWidth
);
2685 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2686 param
.user32_height
, ddsd
.dwHeight
);
2687 IDirectDrawSurface_Release(primary
);
2689 memset(&ddsd
, 0, sizeof(ddsd
));
2690 ddsd
.dwSize
= sizeof(ddsd
);
2691 ddsd
.dwFlags
= DDSD_CAPS
;
2692 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2694 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2695 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2696 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2697 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2698 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2699 param
.ddraw_width
, ddsd
.dwWidth
);
2700 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2701 param
.ddraw_height
, ddsd
.dwHeight
);
2703 GetWindowRect(window
, &r
);
2704 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2705 wine_dbgstr_rect(&r
));
2707 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2708 expect_messages
= exclusive_messages
;
2712 hr
= IDirectDrawSurface_IsLost(primary
);
2713 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2714 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2715 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2716 hr
= IDirectDrawSurface_IsLost(primary
);
2717 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2719 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2720 expect_messages
= NULL
;
2721 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2722 "Expected screen size %ux%u, got %ux%u.\n",
2723 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2725 GetWindowRect(window
, &r
);
2726 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2727 wine_dbgstr_rect(&r
));
2729 expect_messages
= exclusive_focus_loss_messages
;
2730 ret
= SetForegroundWindow(GetDesktopWindow());
2731 ok(ret
, "Failed to set foreground window.\n");
2732 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2733 memset(&devmode
, 0, sizeof(devmode
));
2734 devmode
.dmSize
= sizeof(devmode
);
2735 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2736 ok(ret
, "Failed to get display mode.\n");
2737 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2738 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2739 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2741 expect_messages
= exclusive_focus_restore_messages
;
2742 ShowWindow(window
, SW_RESTORE
);
2743 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2745 GetWindowRect(window
, &r
);
2746 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2747 wine_dbgstr_rect(&r
));
2748 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2749 ok(ret
, "Failed to get display mode.\n");
2750 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2751 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2752 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2754 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2755 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2756 /* Normally the primary should be restored here. Unfortunately this causes the
2757 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2758 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2759 * the point of the GetSurfaceDesc call. */
2761 expect_messages
= sc_minimize_messages
;
2762 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2763 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2764 expect_messages
= NULL
;
2766 expect_messages
= sc_restore_messages
;
2767 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2768 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2769 expect_messages
= NULL
;
2771 expect_messages
= sc_maximize_messages
;
2772 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2773 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2774 expect_messages
= NULL
;
2776 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2777 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2779 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2780 expect_messages
= exclusive_messages
;
2784 hr
= IDirectDrawSurface_IsLost(primary
);
2785 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2786 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
2787 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2788 hr
= IDirectDrawSurface_IsLost(primary
);
2789 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2791 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2792 expect_messages
= NULL
;
2793 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2794 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2795 "Expected screen size %ux%u, got %ux%u.\n",
2796 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2798 GetWindowRect(window
, &r
);
2799 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2800 wine_dbgstr_rect(&r
));
2802 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2803 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2804 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2805 param
.ddraw_width
, ddsd
.dwWidth
);
2806 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2807 param
.ddraw_height
, ddsd
.dwHeight
);
2808 IDirectDrawSurface_Release(primary
);
2811 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2812 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2814 memset(&ddsd
, 0, sizeof(ddsd
));
2815 ddsd
.dwSize
= sizeof(ddsd
);
2816 ddsd
.dwFlags
= DDSD_CAPS
;
2817 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2819 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2820 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2821 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2822 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2823 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2824 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2825 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2826 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2828 GetWindowRect(window
, &r
);
2829 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2830 wine_dbgstr_rect(&r
));
2832 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2833 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2835 GetWindowRect(window
, &r
);
2836 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2837 wine_dbgstr_rect(&r
));
2839 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2840 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2841 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2842 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2843 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2844 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2845 IDirectDrawSurface_Release(primary
);
2847 memset(&ddsd
, 0, sizeof(ddsd
));
2848 ddsd
.dwSize
= sizeof(ddsd
);
2849 ddsd
.dwFlags
= DDSD_CAPS
;
2850 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2852 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2853 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2854 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2855 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2856 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2857 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2858 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2859 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2861 GetWindowRect(window
, &r
);
2862 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2863 wine_dbgstr_rect(&r
));
2865 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2866 expect_messages
= normal_messages
;
2870 hr
= IDirectDrawSurface_IsLost(primary
);
2871 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2872 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2873 devmode
.dmPelsWidth
= param
.user32_width
;
2874 devmode
.dmPelsHeight
= param
.user32_height
;
2875 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2876 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2877 hr
= IDirectDrawSurface_IsLost(primary
);
2878 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2880 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2881 expect_messages
= NULL
;
2882 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2884 GetWindowRect(window
, &r
);
2885 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2886 wine_dbgstr_rect(&r
));
2888 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2889 expect_messages
= normal_messages
;
2893 hr
= IDirectDrawSurface_Restore(primary
);
2894 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2895 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2896 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
2898 win_skip("Broken SetDisplayMode(), skipping remaining tests.\n");
2899 IDirectDrawSurface_Release(primary
);
2900 IDirectDraw2_Release(ddraw
);
2903 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2904 hr
= IDirectDrawSurface_Restore(primary
);
2905 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2906 hr
= IDirectDrawSurface_IsLost(primary
);
2907 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2909 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2910 expect_messages
= NULL
;
2911 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2913 GetWindowRect(window
, &r
);
2914 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2915 wine_dbgstr_rect(&r
));
2917 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2918 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2919 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2920 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2921 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2922 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2923 IDirectDrawSurface_Release(primary
);
2925 memset(&ddsd
, 0, sizeof(ddsd
));
2926 ddsd
.dwSize
= sizeof(ddsd
);
2927 ddsd
.dwFlags
= DDSD_CAPS
;
2928 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2930 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2931 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2932 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2933 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2934 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2935 param
.ddraw_width
, ddsd
.dwWidth
);
2936 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2937 param
.ddraw_height
, ddsd
.dwHeight
);
2939 GetWindowRect(window
, &r
);
2940 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2941 wine_dbgstr_rect(&r
));
2943 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2944 expect_messages
= normal_messages
;
2948 hr
= IDirectDrawSurface_IsLost(primary
);
2949 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2950 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2951 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2952 hr
= IDirectDrawSurface_IsLost(primary
);
2953 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2955 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2956 expect_messages
= NULL
;
2957 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2959 GetWindowRect(window
, &r
);
2960 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2961 wine_dbgstr_rect(&r
));
2963 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2964 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2965 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2966 param
.ddraw_width
, ddsd
.dwWidth
);
2967 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2968 param
.ddraw_height
, ddsd
.dwHeight
);
2969 IDirectDrawSurface_Release(primary
);
2971 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2972 ok(ret
, "Failed to get display mode.\n");
2973 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2974 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2975 "Expected resolution %ux%u, got %ux%u.\n",
2976 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2977 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2978 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2979 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2981 memset(&ddsd
, 0, sizeof(ddsd
));
2982 ddsd
.dwSize
= sizeof(ddsd
);
2983 ddsd
.dwFlags
= DDSD_CAPS
;
2984 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2986 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2987 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2988 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2989 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2990 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2991 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2992 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2993 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2995 GetWindowRect(window
, &r
);
2996 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2997 wine_dbgstr_rect(&r
));
2999 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
3000 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
3001 * not DDSCL_FULLSCREEN. */
3002 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3003 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3005 GetWindowRect(window
, &r
);
3006 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3007 wine_dbgstr_rect(&r
));
3009 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3010 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3011 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3012 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3013 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3014 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3015 IDirectDrawSurface_Release(primary
);
3017 memset(&ddsd
, 0, sizeof(ddsd
));
3018 ddsd
.dwSize
= sizeof(ddsd
);
3019 ddsd
.dwFlags
= DDSD_CAPS
;
3020 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3022 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3023 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3024 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3025 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3026 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3027 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3028 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3029 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3031 GetWindowRect(window
, &r
);
3032 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3033 wine_dbgstr_rect(&r
));
3035 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3036 expect_messages
= normal_messages
;
3040 hr
= IDirectDrawSurface_IsLost(primary
);
3041 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3042 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
3043 devmode
.dmPelsWidth
= param
.user32_width
;
3044 devmode
.dmPelsHeight
= param
.user32_height
;
3045 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3046 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3047 hr
= IDirectDrawSurface_IsLost(primary
);
3048 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3050 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3051 expect_messages
= NULL
;
3052 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3054 GetWindowRect(window
, &r
);
3055 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3056 wine_dbgstr_rect(&r
));
3058 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3059 expect_messages
= normal_messages
;
3063 hr
= IDirectDrawSurface_Restore(primary
);
3064 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
3065 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3066 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3067 hr
= IDirectDrawSurface_Restore(primary
);
3068 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
3069 hr
= IDirectDrawSurface_IsLost(primary
);
3070 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3072 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3073 expect_messages
= NULL
;
3074 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3076 GetWindowRect(window
, &r
);
3077 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3078 wine_dbgstr_rect(&r
));
3080 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3081 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3082 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3083 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3084 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3085 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3086 IDirectDrawSurface_Release(primary
);
3088 memset(&ddsd
, 0, sizeof(ddsd
));
3089 ddsd
.dwSize
= sizeof(ddsd
);
3090 ddsd
.dwFlags
= DDSD_CAPS
;
3091 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3093 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3094 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3095 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3096 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3097 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3098 param
.ddraw_width
, ddsd
.dwWidth
);
3099 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3100 param
.ddraw_height
, ddsd
.dwHeight
);
3102 GetWindowRect(window
, &r
);
3103 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3104 wine_dbgstr_rect(&r
));
3106 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3107 expect_messages
= normal_messages
;
3111 hr
= IDirectDrawSurface_IsLost(primary
);
3112 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3113 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3114 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3115 hr
= IDirectDrawSurface_IsLost(primary
);
3116 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3118 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3119 expect_messages
= NULL
;
3120 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3122 GetWindowRect(window
, &r
);
3123 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3124 wine_dbgstr_rect(&r
));
3126 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3127 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3128 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3129 param
.ddraw_width
, ddsd
.dwWidth
);
3130 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3131 param
.ddraw_height
, ddsd
.dwHeight
);
3132 IDirectDrawSurface_Release(primary
);
3134 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3135 ok(ret
, "Failed to get display mode.\n");
3136 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3137 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3138 "Expected resolution %ux%u, got %ux%u.\n",
3139 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3140 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3141 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3142 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3144 memset(&ddsd
, 0, sizeof(ddsd
));
3145 ddsd
.dwSize
= sizeof(ddsd
);
3146 ddsd
.dwFlags
= DDSD_CAPS
;
3147 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3149 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3150 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3151 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3152 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3153 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3154 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3155 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3156 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3157 IDirectDrawSurface_Release(primary
);
3159 GetWindowRect(window
, &r
);
3160 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3161 wine_dbgstr_rect(&r
));
3163 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3164 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3165 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3166 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3167 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3169 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3170 expect_messages
= exclusive_messages
;
3174 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3175 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3177 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3178 expect_messages
= NULL
;
3179 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
3180 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
3181 "Expected screen size %ux%u, got %ux%u.\n",
3182 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3183 screen_size
.cx
, screen_size
.cy
);
3185 GetWindowRect(window
, &r
);
3186 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3187 wine_dbgstr_rect(&r
));
3189 memset(&ddsd
, 0, sizeof(ddsd
));
3190 ddsd
.dwSize
= sizeof(ddsd
);
3191 ddsd
.dwFlags
= DDSD_CAPS
;
3192 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3194 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3195 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3196 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3197 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3198 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3199 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3200 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3201 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3202 IDirectDrawSurface_Release(primary
);
3204 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3205 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3206 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3207 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3208 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3210 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3211 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3213 memset(&ddsd
, 0, sizeof(ddsd
));
3214 ddsd
.dwSize
= sizeof(ddsd
);
3215 ddsd
.dwFlags
= DDSD_CAPS
;
3216 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3218 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3219 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3220 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3221 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3222 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3223 param
.ddraw_width
, ddsd
.dwWidth
);
3224 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3225 param
.ddraw_height
, ddsd
.dwHeight
);
3226 IDirectDrawSurface_Release(primary
);
3228 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3229 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3231 /* If the window is changed at the same time, messages are sent to the new window. */
3232 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3233 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3234 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3235 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3237 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3238 expect_messages
= exclusive_messages
;
3241 screen_size2
.cx
= 0;
3242 screen_size2
.cy
= 0;
3244 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3245 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3247 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3248 expect_messages
= NULL
;
3249 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
3250 screen_size
.cx
, screen_size
.cy
);
3251 ok(screen_size2
.cx
== registry_mode
.dmPelsWidth
&& screen_size2
.cy
== registry_mode
.dmPelsHeight
,
3252 "Expected screen size 2 %ux%u, got %ux%u.\n",
3253 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size2
.cx
, screen_size2
.cy
);
3255 GetWindowRect(window
, &r
);
3256 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
3257 wine_dbgstr_rect(&r
));
3258 GetWindowRect(window2
, &r
);
3259 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3260 wine_dbgstr_rect(&r
));
3262 memset(&ddsd
, 0, sizeof(ddsd
));
3263 ddsd
.dwSize
= sizeof(ddsd
);
3264 ddsd
.dwFlags
= DDSD_CAPS
;
3265 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3267 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3268 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3269 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3270 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3271 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3272 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3273 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3274 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3275 IDirectDrawSurface_Release(primary
);
3277 ref
= IDirectDraw2_Release(ddraw
);
3278 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3280 GetWindowRect(window
, &r
);
3281 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
3282 wine_dbgstr_rect(&r
));
3285 expect_messages
= NULL
;
3286 DestroyWindow(window
);
3287 DestroyWindow(window2
);
3288 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3289 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3292 static void test_coop_level_mode_set_multi(void)
3294 IDirectDraw2
*ddraw1
, *ddraw2
;
3300 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3301 0, 0, 100, 100, 0, 0, 0, 0);
3302 ddraw1
= create_ddraw();
3303 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3305 /* With just a single ddraw object, the display mode is restored on
3307 hr
= set_display_mode(ddraw1
, 800, 600);
3308 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
3310 win_skip("Broken SetDisplayMode(), skipping test.\n");
3311 IDirectDraw2_Release(ddraw1
);
3312 DestroyWindow(window
);
3315 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3316 w
= GetSystemMetrics(SM_CXSCREEN
);
3317 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3318 h
= GetSystemMetrics(SM_CYSCREEN
);
3319 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3321 ref
= IDirectDraw2_Release(ddraw1
);
3322 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3323 w
= GetSystemMetrics(SM_CXSCREEN
);
3324 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3325 h
= GetSystemMetrics(SM_CYSCREEN
);
3326 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3328 /* When there are multiple ddraw objects, the display mode is restored to
3329 * the initial mode, before the first SetDisplayMode() call. */
3330 ddraw1
= create_ddraw();
3331 hr
= set_display_mode(ddraw1
, 800, 600);
3332 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3333 w
= GetSystemMetrics(SM_CXSCREEN
);
3334 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3335 h
= GetSystemMetrics(SM_CYSCREEN
);
3336 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3338 ddraw2
= create_ddraw();
3339 hr
= set_display_mode(ddraw2
, 640, 480);
3340 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3341 w
= GetSystemMetrics(SM_CXSCREEN
);
3342 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3343 h
= GetSystemMetrics(SM_CYSCREEN
);
3344 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3346 ref
= IDirectDraw2_Release(ddraw2
);
3347 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3348 w
= GetSystemMetrics(SM_CXSCREEN
);
3349 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3350 h
= GetSystemMetrics(SM_CYSCREEN
);
3351 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3353 ref
= IDirectDraw2_Release(ddraw1
);
3354 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3355 w
= GetSystemMetrics(SM_CXSCREEN
);
3356 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3357 h
= GetSystemMetrics(SM_CYSCREEN
);
3358 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3360 /* Regardless of release ordering. */
3361 ddraw1
= create_ddraw();
3362 hr
= set_display_mode(ddraw1
, 800, 600);
3363 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3364 w
= GetSystemMetrics(SM_CXSCREEN
);
3365 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3366 h
= GetSystemMetrics(SM_CYSCREEN
);
3367 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3369 ddraw2
= create_ddraw();
3370 hr
= set_display_mode(ddraw2
, 640, 480);
3371 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3372 w
= GetSystemMetrics(SM_CXSCREEN
);
3373 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3374 h
= GetSystemMetrics(SM_CYSCREEN
);
3375 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3377 ref
= IDirectDraw2_Release(ddraw1
);
3378 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3379 w
= GetSystemMetrics(SM_CXSCREEN
);
3380 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3381 h
= GetSystemMetrics(SM_CYSCREEN
);
3382 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3384 ref
= IDirectDraw2_Release(ddraw2
);
3385 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3386 w
= GetSystemMetrics(SM_CXSCREEN
);
3387 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3388 h
= GetSystemMetrics(SM_CYSCREEN
);
3389 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3391 /* But only for ddraw objects that called SetDisplayMode(). */
3392 ddraw1
= create_ddraw();
3393 ddraw2
= create_ddraw();
3394 hr
= set_display_mode(ddraw2
, 640, 480);
3395 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3396 w
= GetSystemMetrics(SM_CXSCREEN
);
3397 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3398 h
= GetSystemMetrics(SM_CYSCREEN
);
3399 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3401 ref
= IDirectDraw2_Release(ddraw1
);
3402 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3403 w
= GetSystemMetrics(SM_CXSCREEN
);
3404 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3405 h
= GetSystemMetrics(SM_CYSCREEN
);
3406 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3408 ref
= IDirectDraw2_Release(ddraw2
);
3409 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3410 w
= GetSystemMetrics(SM_CXSCREEN
);
3411 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3412 h
= GetSystemMetrics(SM_CYSCREEN
);
3413 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3415 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3416 * restoring the display mode. */
3417 ddraw1
= create_ddraw();
3418 hr
= set_display_mode(ddraw1
, 800, 600);
3419 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3420 w
= GetSystemMetrics(SM_CXSCREEN
);
3421 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3422 h
= GetSystemMetrics(SM_CYSCREEN
);
3423 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3425 ddraw2
= create_ddraw();
3426 hr
= set_display_mode(ddraw2
, 640, 480);
3427 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3428 w
= GetSystemMetrics(SM_CXSCREEN
);
3429 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3430 h
= GetSystemMetrics(SM_CYSCREEN
);
3431 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3433 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3434 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3436 ref
= IDirectDraw2_Release(ddraw1
);
3437 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3438 w
= GetSystemMetrics(SM_CXSCREEN
);
3439 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3440 h
= GetSystemMetrics(SM_CYSCREEN
);
3441 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3443 ref
= IDirectDraw2_Release(ddraw2
);
3444 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3445 w
= GetSystemMetrics(SM_CXSCREEN
);
3446 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3447 h
= GetSystemMetrics(SM_CYSCREEN
);
3448 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3450 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3451 ddraw1
= create_ddraw();
3452 hr
= set_display_mode(ddraw1
, 800, 600);
3453 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3454 w
= GetSystemMetrics(SM_CXSCREEN
);
3455 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3456 h
= GetSystemMetrics(SM_CYSCREEN
);
3457 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3459 hr
= IDirectDraw2_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3460 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3462 ddraw2
= create_ddraw();
3463 hr
= set_display_mode(ddraw2
, 640, 480);
3464 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3466 ref
= IDirectDraw2_Release(ddraw1
);
3467 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3468 w
= GetSystemMetrics(SM_CXSCREEN
);
3469 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3470 h
= GetSystemMetrics(SM_CYSCREEN
);
3471 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3473 ref
= IDirectDraw2_Release(ddraw2
);
3474 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3475 w
= GetSystemMetrics(SM_CXSCREEN
);
3476 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3477 h
= GetSystemMetrics(SM_CYSCREEN
);
3478 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3480 DestroyWindow(window
);
3483 static void test_initialize(void)
3485 IDirectDraw2
*ddraw
;
3488 ddraw
= create_ddraw();
3489 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3491 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3492 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3493 IDirectDraw2_Release(ddraw
);
3496 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw2
, (void **)&ddraw
);
3497 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw2 instance, hr %#x.\n", hr
);
3498 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3499 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3500 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3501 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3502 IDirectDraw2_Release(ddraw
);
3506 static void test_coop_level_surf_create(void)
3508 IDirectDrawSurface
*surface
;
3509 IDirectDraw2
*ddraw
;
3513 ddraw
= create_ddraw();
3514 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3516 memset(&ddsd
, 0, sizeof(ddsd
));
3517 ddsd
.dwSize
= sizeof(ddsd
);
3518 ddsd
.dwFlags
= DDSD_CAPS
;
3519 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3520 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3521 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3523 IDirectDraw2_Release(ddraw
);
3526 static void test_coop_level_multi_window(void)
3528 HWND window1
, window2
;
3529 IDirectDraw2
*ddraw
;
3532 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3533 0, 0, 640, 480, 0, 0, 0, 0);
3534 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3535 0, 0, 640, 480, 0, 0, 0, 0);
3536 ddraw
= create_ddraw();
3537 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3539 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3540 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3541 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3542 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3543 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3544 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3546 IDirectDraw2_Release(ddraw
);
3547 DestroyWindow(window2
);
3548 DestroyWindow(window1
);
3551 static void test_clear_rect_count(void)
3553 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3554 IDirect3DMaterial2
*white
, *red
, *green
, *blue
;
3555 IDirect3DViewport2
*viewport
;
3556 IDirect3DDevice2
*device
;
3557 IDirectDrawSurface
*rt
;
3558 IDirectDraw2
*ddraw
;
3563 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3564 0, 0, 640, 480, 0, 0, 0, 0);
3565 ddraw
= create_ddraw();
3566 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3567 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3569 skip("Failed to create a 3D device, skipping test.\n");
3570 IDirectDraw2_Release(ddraw
);
3571 DestroyWindow(window
);
3575 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
3576 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3578 white
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
3579 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
3580 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
3581 blue
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
3583 viewport
= create_viewport(device
, 0, 0, 640, 480);
3584 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
3585 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3587 viewport_set_background(device
, viewport
, white
);
3588 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3589 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3590 viewport_set_background(device
, viewport
, red
);
3591 hr
= IDirect3DViewport2_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3592 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3593 viewport_set_background(device
, viewport
, green
);
3594 hr
= IDirect3DViewport2_Clear(viewport
, 0, NULL
, D3DCLEAR_TARGET
);
3595 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3596 viewport_set_background(device
, viewport
, blue
);
3597 hr
= IDirect3DViewport2_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3598 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3600 color
= get_surface_color(rt
, 320, 240);
3601 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x000000ff, 1)),
3602 "Got unexpected color 0x%08x.\n", color
);
3604 IDirectDrawSurface_Release(rt
);
3605 destroy_viewport(device
, viewport
);
3606 destroy_material(white
);
3607 destroy_material(red
);
3608 destroy_material(green
);
3609 destroy_material(blue
);
3610 IDirect3DDevice2_Release(device
);
3611 IDirectDraw2_Release(ddraw
);
3612 DestroyWindow(window
);
3615 static BOOL
test_mode_restored(IDirectDraw2
*ddraw
, HWND window
)
3617 DDSURFACEDESC ddsd1
, ddsd2
;
3620 memset(&ddsd1
, 0, sizeof(ddsd1
));
3621 ddsd1
.dwSize
= sizeof(ddsd1
);
3622 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &ddsd1
);
3623 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3625 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3626 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3627 hr
= set_display_mode(ddraw
, 640, 480);
3628 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3629 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3630 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3632 memset(&ddsd2
, 0, sizeof(ddsd2
));
3633 ddsd2
.dwSize
= sizeof(ddsd2
);
3634 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &ddsd2
);
3635 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3636 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3637 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3639 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
3642 static void test_coop_level_versions(void)
3648 IDirectDrawSurface
*surface
;
3649 IDirectDraw2
*ddraw2
;
3652 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3653 0, 0, 640, 480, 0, 0, 0, 0);
3655 ddraw2
= create_ddraw();
3656 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3657 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3658 restored
= test_mode_restored(ddraw2
, window
);
3659 ok(restored
, "Display mode not restored in new ddraw object\n");
3661 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3662 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3663 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3665 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3666 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3667 restored
= test_mode_restored(ddraw2
, window
);
3668 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3670 /* A successful one does */
3671 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3672 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3673 restored
= test_mode_restored(ddraw2
, window
);
3674 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3676 IDirectDraw_Release(ddraw
);
3677 IDirectDraw2_Release(ddraw2
);
3679 ddraw2
= create_ddraw();
3680 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3681 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3682 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3684 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
3685 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3686 restored
= test_mode_restored(ddraw2
, window
);
3687 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3689 IDirectDraw_Release(ddraw
);
3690 IDirectDraw2_Release(ddraw2
);
3692 /* A failing call does not restore the ddraw2+ behavior */
3693 ddraw2
= create_ddraw();
3694 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3695 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3696 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3698 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3699 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3700 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3701 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3702 restored
= test_mode_restored(ddraw2
, window
);
3703 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3705 IDirectDraw_Release(ddraw
);
3706 IDirectDraw2_Release(ddraw2
);
3708 /* Neither does a sequence of successful calls with the new interface */
3709 ddraw2
= create_ddraw();
3710 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3711 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3712 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3714 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3715 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3716 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3717 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3718 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_NORMAL
);
3719 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3721 restored
= test_mode_restored(ddraw2
, window
);
3722 ok(!restored
, "Display mode restored after ddraw1-ddraw2 SetCooperativeLevel() call sequence\n");
3723 IDirectDraw_Release(ddraw
);
3724 IDirectDraw2_Release(ddraw2
);
3726 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3727 ddraw2
= create_ddraw();
3728 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3729 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3730 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3732 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_NORMAL
);
3733 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3735 memset(&ddsd
, 0, sizeof(ddsd
));
3736 ddsd
.dwSize
= sizeof(ddsd
);
3737 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
3738 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
3739 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
3740 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3741 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
3742 IDirectDrawSurface_Release(surface
);
3743 restored
= test_mode_restored(ddraw2
, window
);
3744 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
3746 IDirectDraw_Release(ddraw
);
3747 IDirectDraw2_Release(ddraw2
);
3748 DestroyWindow(window
);
3751 static void test_lighting_interface_versions(void)
3753 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3754 IDirect3DMaterial2
*emissive
, *background
;
3755 IDirect3DViewport2
*viewport
;
3756 IDirect3DDevice2
*device
;
3757 IDirectDrawSurface
*rt
;
3758 IDirectDraw2
*ddraw
;
3762 D3DMATERIALHANDLE mat_handle
;
3766 static D3DVERTEX quad
[] =
3768 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3769 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3770 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3771 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3773 static D3DLVERTEX lquad
[] =
3775 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3776 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3777 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3778 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3780 static D3DTLVERTEX tlquad
[] =
3782 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3783 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3784 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3785 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3789 D3DVERTEXTYPE vertextype
;
3791 DWORD d3drs_lighting
, d3drs_specular
;
3797 /* Lighting is enabled when D3DVT_VERTEX is used and D3DDP_DONOTLIGHT is not
3798 * set. D3DVT_VERTEX has diffuse = 0xffffffff and specular = 0x00000000, as
3799 * in later d3d versions */
3800 { D3DVT_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x0000ff00},
3801 { D3DVT_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
3802 { D3DVT_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3803 { D3DVT_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3804 { D3DVT_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x0000ff00},
3805 { D3DVT_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
3806 { D3DVT_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3807 { D3DVT_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3809 { D3DVT_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
3810 { D3DVT_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x00ff0000},
3811 { D3DVT_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3812 { D3DVT_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3813 { D3DVT_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
3814 { D3DVT_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x00ff8080},
3815 { D3DVT_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3816 { D3DVT_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3818 { D3DVT_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
3819 { D3DVT_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
3820 { D3DVT_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3821 { D3DVT_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3822 { D3DVT_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
3823 { D3DVT_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
3824 { D3DVT_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3825 { D3DVT_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3828 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3829 0, 0, 640, 480, 0, 0, 0, 0);
3830 ddraw
= create_ddraw();
3831 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3832 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3834 skip("Failed to create a 3D device, skipping test.\n");
3835 IDirectDraw2_Release(ddraw
);
3836 DestroyWindow(window
);
3840 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
3841 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3843 viewport
= create_viewport(device
, 0, 0, 640, 480);
3844 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
3845 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3847 emissive
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
3848 hr
= IDirect3DMaterial2_GetHandle(emissive
, device
, &mat_handle
);
3849 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
3850 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
3851 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
3852 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
3853 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
3855 background
= create_diffuse_material(device
, 0.1f
, 0.1f
, 0.1f
, 0.1f
);
3856 viewport_set_background(device
, viewport
, background
);
3858 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
3859 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
3860 ok(rs
== TRUE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected TRUE.\n", rs
);
3862 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
3864 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3865 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3867 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
3868 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
3869 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
3870 tests
[i
].d3drs_specular
);
3871 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
3873 hr
= IDirect3DDevice2_BeginScene(device
);
3874 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3875 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
3876 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
3877 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3878 hr
= IDirect3DDevice2_EndScene(device
);
3879 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3881 color
= get_surface_color(rt
, 320, 240);
3882 ok(compare_color(color
, tests
[i
].color
, 1),
3883 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3884 color
, tests
[i
].color
, i
);
3887 destroy_material(background
);
3888 destroy_material(emissive
);
3889 IDirectDrawSurface_Release(rt
);
3890 IDirect3DDevice2_Release(device
);
3891 ref
= IDirectDraw2_Release(ddraw
);
3892 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
3893 DestroyWindow(window
);
3899 IDirectDraw2
*ddraw
;
3902 } activateapp_testdata
;
3904 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
3906 if (message
== WM_ACTIVATEAPP
)
3908 if (activateapp_testdata
.ddraw
)
3911 activateapp_testdata
.received
= FALSE
;
3912 hr
= IDirectDraw2_SetCooperativeLevel(activateapp_testdata
.ddraw
,
3913 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
3914 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
3915 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3917 activateapp_testdata
.received
= TRUE
;
3920 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
3923 static void test_coop_level_activateapp(void)
3925 IDirectDraw2
*ddraw
;
3930 IDirectDrawSurface
*surface
;
3932 ddraw
= create_ddraw();
3933 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3935 wc
.lpfnWndProc
= activateapp_test_proc
;
3936 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
3937 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3939 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3940 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3942 /* Exclusive with window already active. */
3943 SetForegroundWindow(window
);
3944 activateapp_testdata
.received
= FALSE
;
3945 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3946 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3947 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
3948 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3949 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3951 /* Exclusive with window not active. */
3952 SetForegroundWindow(GetDesktopWindow());
3953 activateapp_testdata
.received
= FALSE
;
3954 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3955 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3956 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3957 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3958 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3960 /* Normal with window not active, then exclusive with the same window. */
3961 SetForegroundWindow(GetDesktopWindow());
3962 activateapp_testdata
.received
= FALSE
;
3963 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3964 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3965 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3966 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3967 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3968 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3969 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3970 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3972 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3973 SetForegroundWindow(GetDesktopWindow());
3974 activateapp_testdata
.received
= FALSE
;
3975 activateapp_testdata
.ddraw
= ddraw
;
3976 activateapp_testdata
.window
= window
;
3977 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
3978 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3979 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3980 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3981 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3982 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3984 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3985 * succeeding. Another switch to exclusive and back to normal is needed to release the
3986 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3987 * WM_ACTIVATEAPP messages. */
3988 activateapp_testdata
.ddraw
= NULL
;
3989 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3990 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3991 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3992 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3994 /* Setting DDSCL_NORMAL with recursive invocation. */
3995 SetForegroundWindow(GetDesktopWindow());
3996 activateapp_testdata
.received
= FALSE
;
3997 activateapp_testdata
.ddraw
= ddraw
;
3998 activateapp_testdata
.window
= window
;
3999 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
4000 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4001 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4002 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4004 /* DDraw is in exclusive mode now. */
4005 memset(&ddsd
, 0, sizeof(ddsd
));
4006 ddsd
.dwSize
= sizeof(ddsd
);
4007 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4008 ddsd
.dwBackBufferCount
= 1;
4009 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4010 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4011 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4012 IDirectDrawSurface_Release(surface
);
4014 /* Recover again, just to be sure. */
4015 activateapp_testdata
.ddraw
= NULL
;
4016 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4017 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4018 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4019 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4021 DestroyWindow(window
);
4022 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
4023 IDirectDraw2_Release(ddraw
);
4026 struct format_support_check
4028 const DDPIXELFORMAT
*format
;
4032 static HRESULT WINAPI
test_unsupported_formats_cb(DDSURFACEDESC
*desc
, void *ctx
)
4034 struct format_support_check
*format
= ctx
;
4036 if (!memcmp(format
->format
, &desc
->ddpfPixelFormat
, sizeof(*format
->format
)))
4038 format
->supported
= TRUE
;
4039 return DDENUMRET_CANCEL
;
4042 return DDENUMRET_OK
;
4045 static void test_unsupported_formats(void)
4048 BOOL expect_success
;
4050 IDirectDraw2
*ddraw
;
4051 IDirect3DDevice2
*device
;
4052 IDirectDrawSurface
*surface
;
4055 DWORD expected_caps
;
4066 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
4067 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
4073 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4074 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
4078 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
4080 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4081 0, 0, 640, 480, 0, 0, 0, 0);
4082 ddraw
= create_ddraw();
4083 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4084 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4086 skip("Failed to create a 3D device, skipping test.\n");
4087 IDirectDraw2_Release(ddraw
);
4088 DestroyWindow(window
);
4092 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
4094 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
4095 hr
= IDirect3DDevice2_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
4096 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4098 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
4100 memset(&ddsd
, 0, sizeof(ddsd
));
4101 ddsd
.dwSize
= sizeof(ddsd
);
4102 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
4103 ddsd
.ddpfPixelFormat
= formats
[i
].fmt
;
4106 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
4108 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
4109 expect_success
= FALSE
;
4111 expect_success
= TRUE
;
4113 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4114 ok(SUCCEEDED(hr
) == expect_success
,
4115 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4116 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
4120 memset(&ddsd
, 0, sizeof(ddsd
));
4121 ddsd
.dwSize
= sizeof(ddsd
);
4122 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &ddsd
);
4123 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4125 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
4126 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4127 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
4128 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4129 else if (check
.supported
)
4130 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4132 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4134 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
4135 "Expected capability %#x, format %s, input cap %#x.\n",
4136 expected_caps
, formats
[i
].name
, caps
[j
]);
4138 IDirectDrawSurface_Release(surface
);
4142 IDirect3DDevice2_Release(device
);
4143 IDirectDraw2_Release(ddraw
);
4144 DestroyWindow(window
);
4147 static void test_rt_caps(void)
4149 PALETTEENTRY palette_entries
[256];
4150 IDirectDrawPalette
*palette
;
4151 IDirect3DDevice2
*device
;
4152 IDirectDraw2
*ddraw
;
4160 static const DDPIXELFORMAT p8_fmt
=
4162 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4163 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4168 const DDPIXELFORMAT
*pf
;
4171 HRESULT create_device_hr
;
4173 HRESULT alternative_set_rt_hr
;
4174 BOOL create_may_fail
;
4180 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4181 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4189 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4190 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4198 DDSCAPS_OFFSCREENPLAIN
,
4199 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4207 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4208 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4209 D3DERR_SURFACENOTINVIDMEM
,
4216 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4217 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4225 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4226 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4235 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4244 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4252 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4253 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4254 D3DERR_SURFACENOTINVIDMEM
,
4261 DDSCAPS_SYSTEMMEMORY
,
4262 DDSCAPS_SYSTEMMEMORY
,
4271 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4279 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4281 DDERR_NOPALETTEATTACHED
,
4288 DDSCAPS_OFFSCREENPLAIN
,
4289 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4297 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4298 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4299 DDERR_NOPALETTEATTACHED
,
4306 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4307 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4315 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
4316 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4318 DDERR_INVALIDPIXELFORMAT
,
4320 TRUE
/* AMD Evergreen */,
4324 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4325 ~0U /* AMD Evergreen */,
4327 DDERR_INVALIDPIXELFORMAT
,
4334 ~0U /* AMD Evergreen */,
4342 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4343 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4345 DDERR_INVALIDPIXELFORMAT
,
4346 DDERR_INVALIDPIXELFORMAT
,
4347 TRUE
/* Nvidia Kepler */,
4351 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4352 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4356 TRUE
/* Nvidia Kepler */,
4360 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4361 0, 0, 640, 480, 0, 0, 0, 0);
4362 ddraw
= create_ddraw();
4363 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4364 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4366 skip("Failed to create a 3D device, skipping test.\n");
4367 IDirectDraw2_Release(ddraw
);
4368 DestroyWindow(window
);
4371 z_depth
= get_device_z_depth(device
);
4372 ok(!!z_depth
, "Failed to get device z depth.\n");
4373 IDirect3DDevice2_Release(device
);
4375 if (FAILED(IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
)))
4377 skip("D3D interface is not available, skipping test.\n");
4381 memset(palette_entries
, 0, sizeof(palette_entries
));
4382 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
4383 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
4385 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4387 IDirectDrawSurface
*surface
, *rt
, *expected_rt
, *tmp
;
4388 DDSURFACEDESC surface_desc
;
4389 IDirect3DDevice2
*device
;
4391 memset(&surface_desc
, 0, sizeof(surface_desc
));
4392 surface_desc
.dwSize
= sizeof(surface_desc
);
4393 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4394 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4395 if (test_data
[i
].pf
)
4397 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4398 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
4400 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
4402 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4403 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
4405 surface_desc
.dwWidth
= 640;
4406 surface_desc
.dwHeight
= 480;
4407 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4408 ok(SUCCEEDED(hr
) || broken(test_data
[i
].create_may_fail
),
4409 "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4410 i
, test_data
[i
].caps_in
, hr
);
4414 memset(&surface_desc
, 0, sizeof(surface_desc
));
4415 surface_desc
.dwSize
= sizeof(surface_desc
);
4416 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4417 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4418 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
4419 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4420 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4422 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4423 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4424 i
, hr
, test_data
[i
].create_device_hr
);
4427 if (hr
== DDERR_NOPALETTEATTACHED
)
4429 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
4430 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
4431 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4432 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
4433 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4435 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4437 IDirectDrawSurface_Release(surface
);
4439 memset(&surface_desc
, 0, sizeof(surface_desc
));
4440 surface_desc
.dwSize
= sizeof(surface_desc
);
4441 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4442 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
4443 surface_desc
.dwWidth
= 640;
4444 surface_desc
.dwHeight
= 480;
4445 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4446 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
4448 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4449 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
4452 memset(&surface_desc
, 0, sizeof(surface_desc
));
4453 surface_desc
.dwSize
= sizeof(surface_desc
);
4454 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4455 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4456 if (test_data
[i
].pf
)
4458 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4459 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
4461 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
4463 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4464 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
4466 surface_desc
.dwWidth
= 640;
4467 surface_desc
.dwHeight
= 480;
4468 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
4469 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4470 i
, test_data
[i
].caps_in
, hr
);
4472 hr
= IDirect3DDevice2_SetRenderTarget(device
, rt
, 0);
4473 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
4474 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4475 i
, hr
, test_data
[i
].set_rt_hr
);
4476 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
4479 expected_rt
= surface
;
4481 /* It appears the surface is set as render target in this case, but no
4482 * reference is taken. */
4483 if (hr
== DDERR_INVALIDPIXELFORMAT
)
4485 refcount
= IDirectDrawSurface_AddRef(rt
);
4486 ok(refcount
== 2, "Test %u: Got unexpected refcount %u.\n", i
, refcount
);
4489 hr
= IDirect3DDevice2_GetRenderTarget(device
, &tmp
);
4490 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
4491 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
4493 IDirectDrawSurface_Release(tmp
);
4494 IDirectDrawSurface_Release(rt
);
4495 refcount
= IDirect3DDevice2_Release(device
);
4496 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
4497 refcount
= IDirectDrawSurface_Release(surface
);
4498 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
4501 IDirectDrawPalette_Release(palette
);
4502 IDirect3D2_Release(d3d
);
4505 refcount
= IDirectDraw2_Release(ddraw
);
4506 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4507 DestroyWindow(window
);
4510 static void test_primary_caps(void)
4512 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4513 IDirectDrawSurface
*surface
;
4514 DDSURFACEDESC surface_desc
;
4515 IDirectDraw2
*ddraw
;
4525 DWORD back_buffer_count
;
4533 DDSCAPS_PRIMARYSURFACE
,
4536 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
4540 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
4547 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
4554 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
4561 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
4568 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
4575 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4582 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4589 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4591 DDERR_NOEXCLUSIVEMODE
,
4595 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4596 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4602 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4603 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4606 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
4609 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4610 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
4616 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4617 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
4624 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4625 0, 0, 640, 480, 0, 0, 0, 0);
4626 ddraw
= create_ddraw();
4627 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4629 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4631 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
4632 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4634 memset(&surface_desc
, 0, sizeof(surface_desc
));
4635 surface_desc
.dwSize
= sizeof(surface_desc
);
4636 surface_desc
.dwFlags
= DDSD_CAPS
;
4637 if (test_data
[i
].back_buffer_count
!= ~0u)
4638 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4639 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4640 surface_desc
.dwBackBufferCount
= test_data
[i
].back_buffer_count
;
4641 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4642 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
4646 memset(&surface_desc
, 0, sizeof(surface_desc
));
4647 surface_desc
.dwSize
= sizeof(surface_desc
);
4648 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4649 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4650 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
4651 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4652 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4654 IDirectDrawSurface_Release(surface
);
4657 refcount
= IDirectDraw2_Release(ddraw
);
4658 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4659 DestroyWindow(window
);
4662 static void test_surface_lock(void)
4664 IDirectDraw2
*ddraw
;
4665 IDirectDrawSurface
*surface
;
4666 IDirect3DDevice2
*device
;
4681 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
4682 "videomemory offscreenplain"
4685 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4686 "systemmemory offscreenplain"
4689 DDSCAPS_PRIMARYSURFACE
,
4693 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
4694 "videomemory texture"
4697 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
4698 "systemmemory texture"
4701 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4710 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4711 0, 0, 640, 480, 0, 0, 0, 0);
4712 ddraw
= create_ddraw();
4713 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4714 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4716 skip("Failed to create a 3D device, skipping test.\n");
4717 IDirectDraw2_Release(ddraw
);
4718 DestroyWindow(window
);
4721 z_depth
= get_device_z_depth(device
);
4722 ok(!!z_depth
, "Failed to get device z depth.\n");
4723 IDirect3DDevice2_Release(device
);
4725 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4727 memset(&ddsd
, 0, sizeof(ddsd
));
4728 ddsd
.dwSize
= sizeof(ddsd
);
4729 ddsd
.dwFlags
= DDSD_CAPS
;
4730 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4732 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4736 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
4738 ddsd
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4739 U2(ddsd
).dwZBufferBitDepth
= z_depth
;
4741 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4743 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4744 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4746 memset(&ddsd
, 0, sizeof(ddsd
));
4747 ddsd
.dwSize
= sizeof(ddsd
);
4748 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4749 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4752 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4753 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4756 memset(&ddsd
, 0, sizeof(ddsd
));
4757 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4758 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, tests
[i
].name
);
4760 IDirectDrawSurface_Release(surface
);
4763 refcount
= IDirectDraw2_Release(ddraw
);
4764 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4765 DestroyWindow(window
);
4768 static void test_surface_discard(void)
4770 IDirectDraw2
*ddraw
;
4771 IDirect3DDevice2
*device
;
4775 IDirectDrawSurface
*surface
, *target
;
4784 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4785 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4786 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4787 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4791 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4792 0, 0, 640, 480, 0, 0, 0, 0);
4793 ddraw
= create_ddraw();
4794 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4795 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4797 skip("Failed to create a 3D device, skipping test.\n");
4798 DestroyWindow(window
);
4799 IDirectDraw2_Release(ddraw
);
4803 hr
= IDirect3DDevice2_GetRenderTarget(device
, &target
);
4804 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4806 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4810 memset(&ddsd
, 0, sizeof(ddsd
));
4811 ddsd
.dwSize
= sizeof(ddsd
);
4812 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4813 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4816 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4819 skip("Failed to create surface, skipping.\n");
4823 memset(&ddsd
, 0, sizeof(ddsd
));
4824 ddsd
.dwSize
= sizeof(ddsd
);
4825 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4826 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4827 addr
= ddsd
.lpSurface
;
4828 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4829 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4831 memset(&ddsd
, 0, sizeof(ddsd
));
4832 ddsd
.dwSize
= sizeof(ddsd
);
4833 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4834 ok(SUCCEEDED(hr
) , "Failed to lock surface, hr %#x.\n", hr
);
4835 discarded
= ddsd
.lpSurface
!= addr
;
4836 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4837 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4839 hr
= IDirectDrawSurface_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
4840 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
4842 memset(&ddsd
, 0, sizeof(ddsd
));
4843 ddsd
.dwSize
= sizeof(ddsd
);
4844 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4845 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4846 discarded
|= ddsd
.lpSurface
!= addr
;
4847 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4848 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4850 IDirectDrawSurface_Release(surface
);
4852 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4853 * AMD r500, evergreen). Windows XP, at least on AMD r200, never changes the pointer. */
4854 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
4857 IDirectDrawSurface_Release(target
);
4858 IDirect3DDevice2_Release(device
);
4859 IDirectDraw2_Release(ddraw
);
4860 DestroyWindow(window
);
4863 static void test_flip(void)
4865 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4866 IDirectDrawSurface
*frontbuffer
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
4867 DDSCAPS caps
= {DDSCAPS_FLIP
};
4868 DDSURFACEDESC surface_desc
;
4869 BOOL sysmem_primary
;
4870 IDirectDraw2
*ddraw
;
4871 DWORD expected_caps
;
4886 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE
},
4887 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN
},
4888 {"TEXTURE", DDSCAPS_TEXTURE
},
4891 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4892 0, 0, 640, 480, 0, 0, 0, 0);
4893 ddraw
= create_ddraw();
4894 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4896 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4897 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4899 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4901 /* Creating a flippable texture induces a BSoD on some versions of the
4902 * Intel graphics driver. At least Intel GMA 950 with driver version
4903 * 6.14.10.4926 on Windows XP SP3 is affected. */
4904 if ((test_data
[i
].caps
& DDSCAPS_TEXTURE
) && ddraw_is_intel(ddraw
))
4906 win_skip("Skipping flippable texture test.\n");
4910 memset(&surface_desc
, 0, sizeof(surface_desc
));
4911 surface_desc
.dwSize
= sizeof(surface_desc
);
4912 surface_desc
.dwFlags
= DDSD_CAPS
;
4913 if (!(test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4914 surface_desc
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4915 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
4916 surface_desc
.dwWidth
= 512;
4917 surface_desc
.dwHeight
= 512;
4918 surface_desc
.dwBackBufferCount
= 3;
4919 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4920 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4922 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_FLIP
;
4923 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4924 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4925 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4927 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_COMPLEX
;
4928 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_FLIP
;
4929 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4930 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4932 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_COMPLEX
;
4933 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4934 todo_wine_if(test_data
[i
].caps
& DDSCAPS_TEXTURE
)
4935 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
4939 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
4940 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
4941 hr
= IDirectDrawSurface_IsLost(frontbuffer
);
4942 ok(hr
== DD_OK
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4943 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4944 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
4945 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4947 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4948 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4949 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
4950 hr
= IDirectDrawSurface_IsLost(frontbuffer
);
4951 todo_wine
ok(hr
== DDERR_SURFACELOST
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4952 hr
= restore_surfaces(ddraw
);
4953 ok(SUCCEEDED(hr
), "%s: Failed to restore surfaces, hr %#x.\n", test_data
[i
].name
, hr
);
4955 memset(&surface_desc
, 0, sizeof(surface_desc
));
4956 surface_desc
.dwSize
= sizeof(surface_desc
);
4957 hr
= IDirectDrawSurface_GetSurfaceDesc(frontbuffer
, &surface_desc
);
4958 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4959 expected_caps
= DDSCAPS_FRONTBUFFER
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
4960 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
4961 expected_caps
|= DDSCAPS_VISIBLE
;
4962 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4963 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4964 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
4966 hr
= IDirectDrawSurface_GetAttachedSurface(frontbuffer
, &caps
, &backbuffer1
);
4967 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4968 memset(&surface_desc
, 0, sizeof(surface_desc
));
4969 surface_desc
.dwSize
= sizeof(surface_desc
);
4970 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer1
, &surface_desc
);
4971 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4972 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4973 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4974 expected_caps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
);
4975 expected_caps
|= DDSCAPS_BACKBUFFER
;
4976 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4977 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4979 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
4980 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4981 memset(&surface_desc
, 0, sizeof(surface_desc
));
4982 surface_desc
.dwSize
= sizeof(surface_desc
);
4983 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer2
, &surface_desc
);
4984 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4985 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4986 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4987 expected_caps
&= ~DDSCAPS_BACKBUFFER
;
4988 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4989 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4991 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
4992 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4993 memset(&surface_desc
, 0, sizeof(surface_desc
));
4994 surface_desc
.dwSize
= sizeof(surface_desc
);
4995 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer3
, &surface_desc
);
4996 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4997 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4998 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4999 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
5000 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
5002 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
5003 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
5004 ok(surface
== frontbuffer
, "%s: Got unexpected surface %p, expected %p.\n",
5005 test_data
[i
].name
, surface
, frontbuffer
);
5006 IDirectDrawSurface_Release(surface
);
5008 memset(&surface_desc
, 0, sizeof(surface_desc
));
5009 surface_desc
.dwSize
= sizeof(surface_desc
);
5010 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5011 surface_desc
.ddsCaps
.dwCaps
= 0;
5012 surface_desc
.dwWidth
= 640;
5013 surface_desc
.dwHeight
= 480;
5014 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5015 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
5016 hr
= IDirectDrawSurface_Flip(frontbuffer
, surface
, DDFLIP_WAIT
);
5017 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5018 IDirectDrawSurface_Release(surface
);
5020 hr
= IDirectDrawSurface_Flip(frontbuffer
, frontbuffer
, DDFLIP_WAIT
);
5021 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5022 hr
= IDirectDrawSurface_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
5023 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5024 hr
= IDirectDrawSurface_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
5025 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5026 hr
= IDirectDrawSurface_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
5027 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5029 memset(&fx
, 0, sizeof(fx
));
5030 fx
.dwSize
= sizeof(fx
);
5031 U5(fx
).dwFillColor
= 0xffff0000;
5032 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5033 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5034 U5(fx
).dwFillColor
= 0xff00ff00;
5035 hr
= IDirectDrawSurface_Blt(backbuffer2
, 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
= 0xff0000ff;
5038 hr
= IDirectDrawSurface_Blt(backbuffer3
, 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
);
5041 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
5042 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5043 color
= get_surface_color(backbuffer1
, 320, 240);
5044 /* The testbot seems to just copy the contents of one surface to all the
5045 * others, instead of properly flipping. */
5046 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
5047 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5048 color
= get_surface_color(backbuffer2
, 320, 240);
5049 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5050 U5(fx
).dwFillColor
= 0xffff0000;
5051 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5052 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5054 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
5055 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5056 color
= get_surface_color(backbuffer1
, 320, 240);
5057 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
5058 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5059 color
= get_surface_color(backbuffer2
, 320, 240);
5060 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5061 U5(fx
).dwFillColor
= 0xff00ff00;
5062 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5063 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5065 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
5066 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5067 color
= get_surface_color(backbuffer1
, 320, 240);
5068 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
5069 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5070 color
= get_surface_color(backbuffer2
, 320, 240);
5071 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5072 U5(fx
).dwFillColor
= 0xff0000ff;
5073 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5074 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5076 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer1
, DDFLIP_WAIT
);
5077 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5078 color
= get_surface_color(backbuffer2
, 320, 240);
5079 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
5080 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5081 color
= get_surface_color(backbuffer3
, 320, 240);
5082 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5083 U5(fx
).dwFillColor
= 0xffff0000;
5084 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5085 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5087 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer2
, DDFLIP_WAIT
);
5088 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5089 color
= get_surface_color(backbuffer1
, 320, 240);
5090 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5091 color
= get_surface_color(backbuffer3
, 320, 240);
5092 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
5093 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5094 U5(fx
).dwFillColor
= 0xff00ff00;
5095 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5096 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
5098 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer3
, DDFLIP_WAIT
);
5099 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5100 color
= get_surface_color(backbuffer1
, 320, 240);
5101 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
5102 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5103 color
= get_surface_color(backbuffer2
, 320, 240);
5104 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5106 IDirectDrawSurface_Release(backbuffer3
);
5107 IDirectDrawSurface_Release(backbuffer2
);
5108 IDirectDrawSurface_Release(backbuffer1
);
5109 IDirectDrawSurface_Release(frontbuffer
);
5112 refcount
= IDirectDraw2_Release(ddraw
);
5113 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5114 DestroyWindow(window
);
5117 static void reset_ddsd(DDSURFACEDESC
*ddsd
)
5119 memset(ddsd
, 0, sizeof(*ddsd
));
5120 ddsd
->dwSize
= sizeof(*ddsd
);
5123 static void test_set_surface_desc(void)
5125 IDirectDraw2
*ddraw
;
5129 IDirectDrawSurface
*surface
;
5130 IDirectDrawSurface3
*surface3
;
5140 invalid_caps_tests
[] =
5142 {DDSCAPS_VIDEOMEMORY
, FALSE
, "videomemory plain"},
5143 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, TRUE
, "systemmemory texture"},
5144 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, FALSE
, "systemmemory primary"},
5147 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5148 0, 0, 640, 480, 0, 0, 0, 0);
5149 ddraw
= create_ddraw();
5150 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5151 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5152 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5155 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5158 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5159 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5160 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5161 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5162 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5163 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5164 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5166 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5167 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5169 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5170 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5171 IDirectDrawSurface_Release(surface
);
5174 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5175 ddsd
.lpSurface
= data
;
5176 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5177 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5179 /* Redundantly setting the same lpSurface is not an error. */
5180 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5181 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5182 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5183 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5184 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5185 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
5187 hr
= IDirectDrawSurface3_Lock(surface3
, NULL
, &ddsd
, 0, NULL
);
5188 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5189 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5190 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
5191 hr
= IDirectDrawSurface3_Unlock(surface3
, NULL
);
5192 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5195 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5196 ddsd
.lpSurface
= data
;
5197 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 1);
5198 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
5200 ddsd
.lpSurface
= NULL
;
5201 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5202 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
5204 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, NULL
, 0);
5205 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
5207 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5208 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5209 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5210 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5212 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5213 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5214 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
5216 ddsd
.dwFlags
= DDSD_CAPS
;
5217 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5218 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5220 /* dwCaps = 0 is allowed, but ignored. */
5221 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
5222 ddsd
.lpSurface
= data
;
5223 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5224 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5225 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5226 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5227 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5228 ddsd
.ddsCaps
.dwCaps
= 0;
5229 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5230 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5232 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5233 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5234 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5235 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5237 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5239 ddsd
.dwFlags
= DDSD_HEIGHT
;
5241 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5242 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
5244 ddsd
.lpSurface
= data
;
5245 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
5246 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5247 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5250 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5251 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
5254 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5255 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
5256 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5257 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5259 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
5261 ddsd
.dwFlags
= DDSD_PITCH
;
5262 U1(ddsd
).lPitch
= 8 * 4;
5263 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5264 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
5266 ddsd
.dwFlags
= DDSD_WIDTH
;
5268 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5269 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
5271 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
5272 ddsd
.lpSurface
= data
;
5273 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5274 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
5276 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
5277 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5278 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
5280 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5281 U1(ddsd
).lPitch
= 16 * 4;
5283 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5284 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5287 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5288 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5289 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5290 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5291 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
5293 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5295 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5296 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5297 U1(ddsd
).lPitch
= 4 * 4;
5298 ddsd
.lpSurface
= data
;
5299 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5300 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5302 U1(ddsd
).lPitch
= 4;
5303 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5304 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5306 U1(ddsd
).lPitch
= 16 * 4 + 1;
5307 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5308 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5310 U1(ddsd
).lPitch
= 16 * 4 + 3;
5311 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5312 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5314 U1(ddsd
).lPitch
= -4;
5315 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5316 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
5318 U1(ddsd
).lPitch
= 16 * 4;
5319 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5320 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5323 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5324 U1(ddsd
).lPitch
= 0;
5326 ddsd
.lpSurface
= data
;
5327 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5328 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
5330 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5331 U1(ddsd
).lPitch
= 16 * 4;
5333 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5334 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
5336 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5337 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
5338 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5339 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5340 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5341 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5342 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5343 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5344 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5345 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
5347 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
5348 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5349 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5351 /* Can't set color keys. */
5353 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
5354 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
5355 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
5356 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5357 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5359 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
5360 ddsd
.lpSurface
= data
;
5361 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5362 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5364 IDirectDrawSurface3_Release(surface3
);
5366 /* SetSurfaceDesc needs systemmemory surfaces.
5368 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5369 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
5372 ddsd
.dwFlags
= DDSD_CAPS
;
5373 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
5374 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5376 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5379 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5380 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5381 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5382 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5383 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5384 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5387 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5388 ok(SUCCEEDED(hr
) || hr
== DDERR_NODIRECTDRAWHW
, "Failed to create surface, hr %#x.\n", hr
);
5391 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5392 invalid_caps_tests
[i
].name
);
5395 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5396 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5397 IDirectDrawSurface_Release(surface
);
5400 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5401 ddsd
.lpSurface
= data
;
5402 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5403 if (invalid_caps_tests
[i
].supported
)
5405 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5409 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5410 invalid_caps_tests
[i
].name
, hr
);
5412 /* Check priority of error conditions. */
5413 ddsd
.dwFlags
= DDSD_WIDTH
;
5414 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5415 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5416 invalid_caps_tests
[i
].name
, hr
);
5419 IDirectDrawSurface3_Release(surface3
);
5423 ref
= IDirectDraw2_Release(ddraw
);
5424 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5425 DestroyWindow(window
);
5428 static void test_user_memory_getdc(void)
5430 IDirectDraw2
*ddraw
;
5434 IDirectDrawSurface
*surface
;
5435 IDirectDrawSurface3
*surface3
;
5444 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5445 0, 0, 640, 480, 0, 0, 0, 0);
5446 ddraw
= create_ddraw();
5447 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5449 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5450 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5453 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5456 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5457 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5458 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5459 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5460 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5461 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5462 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5463 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5464 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5466 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5467 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5468 IDirectDrawSurface_Release(surface
);
5470 memset(data
, 0xaa, sizeof(data
));
5472 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5473 ddsd
.lpSurface
= data
;
5474 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5475 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5477 hr
= IDirectDrawSurface3_GetDC(surface3
, &dc
);
5478 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5479 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
5480 ok(!!bitmap
, "Failed to get bitmap.\n");
5481 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
5482 ok(size
== sizeof(dib
), "Got unexpected size %d.\n", size
);
5483 ok(dib
.dsBm
.bmBits
== data
, "Got unexpected bits %p, expected %p.\n", dib
.dsBm
.bmBits
, data
);
5484 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
5485 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
5486 hr
= IDirectDrawSurface3_ReleaseDC(surface3
, dc
);
5487 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5489 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
5490 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
5492 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
5493 ddsd
.lpSurface
= data
;
5496 U1(ddsd
).lPitch
= sizeof(*data
);
5497 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5498 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5500 memset(data
, 0xaa, sizeof(data
));
5501 hr
= IDirectDrawSurface3_GetDC(surface3
, &dc
);
5502 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5503 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
5504 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
5505 hr
= IDirectDrawSurface3_ReleaseDC(surface3
, dc
);
5506 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5508 for (y
= 0; y
< 4; y
++)
5510 for (x
= 0; x
< 4; x
++)
5512 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
5513 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5516 ok(data
[y
][x
] == 0x00000000, "Expected color 0xaaaaaaaa on position %ux%u, got %#x.\n",
5520 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5522 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5524 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5526 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5529 IDirectDrawSurface3_Release(surface3
);
5530 ref
= IDirectDraw2_Release(ddraw
);
5531 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5532 DestroyWindow(window
);
5535 static void test_sysmem_overlay(void)
5537 IDirectDraw2
*ddraw
;
5541 IDirectDrawSurface
*surface
;
5544 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5545 0, 0, 640, 480, 0, 0, 0, 0);
5546 ddraw
= create_ddraw();
5547 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5549 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5550 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5553 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
5556 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
5557 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5558 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5559 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5560 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5561 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5562 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5563 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5564 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
5566 ref
= IDirectDraw2_Release(ddraw
);
5567 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5568 DestroyWindow(window
);
5571 static void test_primary_palette(void)
5573 DDSCAPS surface_caps
= {DDSCAPS_FLIP
};
5574 IDirectDrawSurface
*primary
, *backbuffer
;
5575 PALETTEENTRY palette_entries
[256];
5576 IDirectDrawPalette
*palette
, *tmp
;
5577 DDSURFACEDESC surface_desc
;
5578 IDirectDraw2
*ddraw
;
5584 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5585 0, 0, 640, 480, 0, 0, 0, 0);
5586 ddraw
= create_ddraw();
5587 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5588 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
5590 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5591 IDirectDraw2_Release(ddraw
);
5592 DestroyWindow(window
);
5595 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5596 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5598 memset(&surface_desc
, 0, sizeof(surface_desc
));
5599 surface_desc
.dwSize
= sizeof(surface_desc
);
5600 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
5601 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
5602 surface_desc
.dwBackBufferCount
= 1;
5603 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
5604 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5605 hr
= IDirectDrawSurface_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
5606 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5608 memset(palette_entries
, 0, sizeof(palette_entries
));
5609 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
5610 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5611 refcount
= get_refcount((IUnknown
*)palette
);
5612 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5614 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5615 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5616 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5618 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5619 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5621 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
5622 * and is generally somewhat broken with respect to 8 bpp / palette
5624 if (SUCCEEDED(IDirectDrawSurface_GetPalette(backbuffer
, &tmp
)))
5626 win_skip("Broken palette handling detected, skipping tests.\n");
5627 IDirectDrawPalette_Release(tmp
);
5628 IDirectDrawPalette_Release(palette
);
5629 /* The Windows 8 testbot keeps extra references to the primary and
5630 * backbuffer while in 8 bpp mode. */
5631 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
5632 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
5636 refcount
= get_refcount((IUnknown
*)palette
);
5637 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5639 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5640 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5641 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
5642 "Got unexpected palette caps %#x.\n", palette_caps
);
5644 hr
= IDirectDrawSurface_SetPalette(primary
, NULL
);
5645 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5646 refcount
= get_refcount((IUnknown
*)palette
);
5647 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5649 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5650 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5651 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5653 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5654 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5655 refcount
= get_refcount((IUnknown
*)palette
);
5656 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5658 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
5659 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
5660 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
5661 IDirectDrawPalette_Release(tmp
);
5662 hr
= IDirectDrawSurface_GetPalette(backbuffer
, &tmp
);
5663 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5665 refcount
= IDirectDrawPalette_Release(palette
);
5666 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5667 refcount
= IDirectDrawPalette_Release(palette
);
5668 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5670 /* Note that this only seems to work when the palette is attached to the
5671 * primary surface. When attached to a regular surface, attempting to get
5672 * the palette here will cause an access violation. */
5673 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
5674 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5676 hr
= IDirectDrawSurface_IsLost(primary
);
5677 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
5679 memset(&surface_desc
, 0, sizeof(surface_desc
));
5680 surface_desc
.dwSize
= sizeof(surface_desc
);
5681 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
5682 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5683 ok(surface_desc
.dwWidth
== 640, "Got unexpected surface width %u.\n", surface_desc
.dwWidth
);
5684 ok(surface_desc
.dwHeight
== 480, "Got unexpected surface height %u.\n", surface_desc
.dwHeight
);
5685 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 8, "Got unexpected bit count %u.\n",
5686 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
5688 hr
= set_display_mode(ddraw
, 640, 480);
5689 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
5691 memset(&surface_desc
, 0, sizeof(surface_desc
));
5692 surface_desc
.dwSize
= sizeof(surface_desc
);
5693 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
5694 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5695 ok(surface_desc
.dwWidth
== 640, "Got unexpected surface width %u.\n", surface_desc
.dwWidth
);
5696 ok(surface_desc
.dwHeight
== 480, "Got unexpected surface height %u.\n", surface_desc
.dwHeight
);
5697 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 32
5698 || U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 24,
5699 "Got unexpected bit count %u.\n", U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
5701 hr
= IDirectDrawSurface_IsLost(primary
);
5702 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
5703 hr
= IDirectDrawSurface_Restore(primary
);
5704 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
5705 hr
= IDirectDrawSurface_IsLost(primary
);
5706 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
5708 memset(&surface_desc
, 0, sizeof(surface_desc
));
5709 surface_desc
.dwSize
= sizeof(surface_desc
);
5710 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
5711 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5712 ok(surface_desc
.dwWidth
== 640, "Got unexpected surface width %u.\n", surface_desc
.dwWidth
);
5713 ok(surface_desc
.dwHeight
== 480, "Got unexpected surface height %u.\n", surface_desc
.dwHeight
);
5714 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 32
5715 || U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 24,
5716 "Got unexpected bit count %u.\n", U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
5719 refcount
= IDirectDrawSurface_Release(backbuffer
);
5720 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5721 refcount
= IDirectDrawSurface_Release(primary
);
5722 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5723 refcount
= IDirectDraw2_Release(ddraw
);
5724 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5725 DestroyWindow(window
);
5728 static HRESULT WINAPI
surface_counter(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
5730 UINT
*surface_count
= context
;
5733 IDirectDrawSurface_Release(surface
);
5735 return DDENUMRET_OK
;
5738 static void test_surface_attachment(void)
5740 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
5741 DDSCAPS caps
= {DDSCAPS_TEXTURE
};
5742 DDSURFACEDESC surface_desc
;
5743 IDirectDraw2
*ddraw
;
5749 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5750 0, 0, 640, 480, 0, 0, 0, 0);
5751 ddraw
= create_ddraw();
5752 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5753 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5754 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5756 memset(&surface_desc
, 0, sizeof(surface_desc
));
5757 surface_desc
.dwSize
= sizeof(surface_desc
);
5758 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
5759 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
5760 U2(surface_desc
).dwMipMapCount
= 3;
5761 surface_desc
.dwWidth
= 128;
5762 surface_desc
.dwHeight
= 128;
5763 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5764 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5766 hr
= IDirectDrawSurface_GetAttachedSurface(surface1
, &caps
, &surface2
);
5767 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5768 hr
= IDirectDrawSurface_GetAttachedSurface(surface2
, &caps
, &surface3
);
5769 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5770 hr
= IDirectDrawSurface_GetAttachedSurface(surface3
, &caps
, &surface4
);
5771 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5774 IDirectDrawSurface_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
5775 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5777 IDirectDrawSurface_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
5778 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5780 IDirectDrawSurface_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
5781 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
5783 memset(&surface_desc
, 0, sizeof(surface_desc
));
5784 surface_desc
.dwSize
= sizeof(surface_desc
);
5785 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5786 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
5787 surface_desc
.dwWidth
= 16;
5788 surface_desc
.dwHeight
= 16;
5789 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5790 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5792 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
5793 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5794 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5795 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5796 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
5797 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5798 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
5799 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5800 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
5801 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5802 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
5803 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5805 IDirectDrawSurface_Release(surface4
);
5807 memset(&surface_desc
, 0, sizeof(surface_desc
));
5808 surface_desc
.dwSize
= sizeof(surface_desc
);
5809 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5810 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5811 surface_desc
.dwWidth
= 16;
5812 surface_desc
.dwHeight
= 16;
5813 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5814 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5816 if (SUCCEEDED(hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
)))
5818 skip("Running on refrast, skipping some tests.\n");
5819 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface4
);
5820 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5824 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5825 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5826 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5827 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
5828 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5829 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
5830 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5831 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
5832 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5833 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
5834 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5837 IDirectDrawSurface_Release(surface4
);
5838 IDirectDrawSurface_Release(surface3
);
5839 IDirectDrawSurface_Release(surface2
);
5840 IDirectDrawSurface_Release(surface1
);
5842 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5843 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5845 /* Try a single primary and two offscreen plain surfaces. */
5846 memset(&surface_desc
, 0, sizeof(surface_desc
));
5847 surface_desc
.dwSize
= sizeof(surface_desc
);
5848 surface_desc
.dwFlags
= DDSD_CAPS
;
5849 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
5850 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5851 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5853 memset(&surface_desc
, 0, sizeof(surface_desc
));
5854 surface_desc
.dwSize
= sizeof(surface_desc
);
5855 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5856 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5857 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
5858 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
5859 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5860 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5862 memset(&surface_desc
, 0, sizeof(surface_desc
));
5863 surface_desc
.dwSize
= sizeof(surface_desc
);
5864 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5865 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5866 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
5867 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
5868 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5869 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5871 /* This one has a different size. */
5872 memset(&surface_desc
, 0, sizeof(surface_desc
));
5873 surface_desc
.dwSize
= sizeof(surface_desc
);
5874 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5875 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5876 surface_desc
.dwWidth
= 128;
5877 surface_desc
.dwHeight
= 128;
5878 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5879 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5881 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5882 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5883 /* Try the reverse without detaching first. */
5884 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
5885 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5886 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5887 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5889 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
5890 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5891 /* Try to detach reversed. */
5892 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5893 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5894 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
5895 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5897 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
);
5898 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5899 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
5900 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5902 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
5903 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5904 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5905 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5907 IDirectDrawSurface_Release(surface4
);
5908 IDirectDrawSurface_Release(surface3
);
5909 IDirectDrawSurface_Release(surface2
);
5910 IDirectDrawSurface_Release(surface1
);
5912 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
5913 memset(&surface_desc
, 0, sizeof(surface_desc
));
5914 surface_desc
.dwSize
= sizeof(surface_desc
);
5915 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5916 surface_desc
.dwWidth
= 64;
5917 surface_desc
.dwHeight
= 64;
5918 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5919 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5920 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
5921 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
5922 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
5923 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
5924 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
5925 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5926 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5927 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5928 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5930 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
5931 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
5932 U1(surface_desc
.ddpfPixelFormat
).dwZBufferBitDepth
= 16;
5933 U3(surface_desc
.ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
5934 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5935 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5937 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5938 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5939 refcount
= get_refcount((IUnknown
*)surface2
);
5940 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5941 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5942 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5944 /* Attaching while already attached to other surface. */
5945 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface2
);
5946 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5947 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface3
, 0, surface2
);
5948 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5949 IDirectDrawSurface_Release(surface3
);
5951 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5952 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5953 refcount
= get_refcount((IUnknown
*)surface2
);
5954 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5956 /* Automatic detachment on release. */
5957 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5958 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5959 refcount
= get_refcount((IUnknown
*)surface2
);
5960 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5961 refcount
= IDirectDrawSurface_Release(surface1
);
5962 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5963 refcount
= IDirectDrawSurface_Release(surface2
);
5964 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5965 refcount
= IDirectDraw2_Release(ddraw
);
5966 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5967 DestroyWindow(window
);
5970 static void test_pixel_format(void)
5972 HWND window
, window2
= NULL
;
5973 HDC hdc
, hdc2
= NULL
;
5975 int format
, test_format
;
5976 PIXELFORMATDESCRIPTOR pfd
;
5977 IDirectDraw2
*ddraw
= NULL
;
5978 IDirectDrawClipper
*clipper
= NULL
;
5980 IDirectDrawSurface
*primary
= NULL
;
5984 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
5985 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
5988 skip("Failed to create window\n");
5992 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
5993 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
5995 hdc
= GetDC(window
);
5998 skip("Failed to get DC\n");
6003 hdc2
= GetDC(window2
);
6005 gl
= LoadLibraryA("opengl32.dll");
6006 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6008 format
= GetPixelFormat(hdc
);
6009 ok(format
== 0, "new window has pixel format %d\n", format
);
6011 ZeroMemory(&pfd
, sizeof(pfd
));
6012 pfd
.nSize
= sizeof(pfd
);
6014 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
6015 pfd
.iPixelType
= PFD_TYPE_RGBA
;
6016 pfd
.iLayerType
= PFD_MAIN_PLANE
;
6017 format
= ChoosePixelFormat(hdc
, &pfd
);
6020 skip("no pixel format available\n");
6024 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
6026 skip("failed to set pixel format\n");
6030 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
6032 skip("failed to set pixel format on second window\n");
6035 ReleaseDC(window2
, hdc2
);
6040 ddraw
= create_ddraw();
6041 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6043 test_format
= GetPixelFormat(hdc
);
6044 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6046 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6049 skip("Failed to set cooperative level, hr %#x.\n", hr
);
6053 test_format
= GetPixelFormat(hdc
);
6054 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6058 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
6059 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
6060 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
6061 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
6063 test_format
= GetPixelFormat(hdc
);
6064 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6066 test_format
= GetPixelFormat(hdc2
);
6067 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6070 memset(&ddsd
, 0, sizeof(ddsd
));
6071 ddsd
.dwSize
= sizeof(ddsd
);
6072 ddsd
.dwFlags
= DDSD_CAPS
;
6073 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6075 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
6076 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
6078 test_format
= GetPixelFormat(hdc
);
6079 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6083 test_format
= GetPixelFormat(hdc2
);
6084 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6089 hr
= IDirectDrawSurface2_SetClipper(primary
, clipper
);
6090 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
6092 test_format
= GetPixelFormat(hdc
);
6093 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6095 test_format
= GetPixelFormat(hdc2
);
6096 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6099 memset(&fx
, 0, sizeof(fx
));
6100 fx
.dwSize
= sizeof(fx
);
6101 hr
= IDirectDrawSurface2_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6102 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
6104 test_format
= GetPixelFormat(hdc
);
6105 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6109 test_format
= GetPixelFormat(hdc2
);
6110 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6114 if (primary
) IDirectDrawSurface2_Release(primary
);
6115 if (clipper
) IDirectDrawClipper_Release(clipper
);
6116 if (ddraw
) IDirectDraw2_Release(ddraw
);
6117 if (gl
) FreeLibrary(gl
);
6118 if (hdc
) ReleaseDC(window
, hdc
);
6119 if (hdc2
) ReleaseDC(window2
, hdc2
);
6120 if (window
) DestroyWindow(window
);
6121 if (window2
) DestroyWindow(window2
);
6124 static void test_create_surface_pitch(void)
6126 IDirectDrawSurface
*surface
;
6127 DDSURFACEDESC surface_desc
;
6128 IDirectDraw2
*ddraw
;
6148 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6150 DDSD_PITCH
, 0x100, 0x100},
6151 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6152 DDSD_PITCH
, 0x104, DD_OK
,
6153 DDSD_PITCH
, 0x100, 0x100},
6154 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6155 DDSD_PITCH
, 0x0f8, DD_OK
,
6156 DDSD_PITCH
, 0x100, 0x100},
6157 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6158 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
6160 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6162 DDSD_PITCH
, 0x100, 0x0fc},
6164 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6165 DDSD_PITCH
, 0x104, DD_OK
,
6166 DDSD_PITCH
, 0x100, 0x0fc},
6167 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6168 DDSD_PITCH
, 0x0f8, DD_OK
,
6169 DDSD_PITCH
, 0x100, 0x0fc},
6170 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6171 DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
6172 DDSD_PITCH
, 0x100, 0x0fc},
6173 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6174 DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
6176 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6177 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
6180 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
6181 0, 0, DDERR_INVALIDCAPS
,
6183 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6185 DDSD_PITCH
, 0x100, 0 },
6186 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6187 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
6189 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
6190 0, 0, DDERR_INVALIDCAPS
,
6192 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6194 DDSD_PITCH
, 0x100, 0 },
6196 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6197 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
6200 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
6202 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6203 0, 0, 640, 480, 0, 0, 0, 0);
6204 ddraw
= create_ddraw();
6205 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6206 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6207 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6209 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
6211 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6213 memset(&surface_desc
, 0, sizeof(surface_desc
));
6214 surface_desc
.dwSize
= sizeof(surface_desc
);
6215 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
6216 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
6217 surface_desc
.dwWidth
= 63;
6218 surface_desc
.dwHeight
= 63;
6219 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
6220 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6221 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6222 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6223 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6224 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6225 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6226 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6227 if (test_data
[i
].flags_in
& DDSD_LPSURFACE
)
6229 HRESULT expected_hr
= SUCCEEDED(test_data
[i
].hr
) ? DDERR_INVALIDPARAMS
: test_data
[i
].hr
;
6230 ok(hr
== expected_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, expected_hr
);
6231 surface_desc
.lpSurface
= mem
;
6232 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6234 if ((test_data
[i
].caps
& DDSCAPS_VIDEOMEMORY
) && hr
== DDERR_NODIRECTDRAWHW
)
6236 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
6240 memset(&surface_desc
, 0, sizeof(surface_desc
));
6241 surface_desc
.dwSize
= sizeof(surface_desc
);
6242 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
6243 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
6244 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
6245 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6246 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
6247 /* The pitch for textures seems to be implementation specific. */
6248 if (!(test_data
[i
].caps
& DDSCAPS_TEXTURE
))
6250 if (is_ddraw64
&& test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
6251 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
6252 "Test %u: Got unexpected pitch %u, expected %u.\n",
6253 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
6255 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
6256 "Test %u: Got unexpected pitch %u, expected %u.\n",
6257 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
6259 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
6261 IDirectDrawSurface_Release(surface
);
6264 HeapFree(GetProcessHeap(), 0, mem
);
6265 refcount
= IDirectDraw2_Release(ddraw
);
6266 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6267 DestroyWindow(window
);
6270 static void test_mipmap(void)
6272 IDirectDrawSurface
*surface1
;
6273 IDirectDrawSurface2
*surface
, *surface2
;
6274 DDSURFACEDESC surface_desc
;
6275 IDirectDraw2
*ddraw
;
6280 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
6289 DWORD mipmap_count_in
;
6291 DWORD mipmap_count_out
;
6295 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 3, DD_OK
, 3},
6296 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDPARAMS
, 0},
6297 {0, DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 1},
6298 {0, DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDCAPS
, 0},
6299 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 6},
6300 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 32, 64, 0, DD_OK
, 6},
6303 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6304 0, 0, 640, 480, 0, 0, 0, 0);
6305 ddraw
= create_ddraw();
6306 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6307 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6308 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6310 memset(&hal_caps
, 0, sizeof(hal_caps
));
6311 hal_caps
.dwSize
= sizeof(hal_caps
);
6312 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
6313 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6314 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6316 skip("Mipmapped textures not supported, skipping tests.\n");
6317 IDirectDraw2_Release(ddraw
);
6318 DestroyWindow(window
);
6322 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
6324 memset(&surface_desc
, 0, sizeof(surface_desc
));
6325 surface_desc
.dwSize
= sizeof(surface_desc
);
6326 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| tests
[i
].flags
;
6327 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
6328 surface_desc
.dwWidth
= tests
[i
].width
;
6329 surface_desc
.dwHeight
= tests
[i
].height
;
6330 if (tests
[i
].flags
& DDSD_MIPMAPCOUNT
)
6331 U2(surface_desc
).dwMipMapCount
= tests
[i
].mipmap_count_in
;
6332 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6333 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
6337 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
6338 ok(SUCCEEDED(hr
), "Test %u: Failed to get IDirectDrawSurface2 interface, hr %#x.\n", i
, hr
);
6339 IDirectDrawSurface_Release(surface1
);
6341 memset(&surface_desc
, 0, sizeof(surface_desc
));
6342 surface_desc
.dwSize
= sizeof(surface_desc
);
6343 hr
= IDirectDrawSurface2_GetSurfaceDesc(surface
, &surface_desc
);
6344 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
6345 ok(surface_desc
.dwFlags
& DDSD_MIPMAPCOUNT
,
6346 "Test %u: Got unexpected flags %#x.\n", i
, surface_desc
.dwFlags
);
6347 ok(U2(surface_desc
).dwMipMapCount
== tests
[i
].mipmap_count_out
,
6348 "Test %u: Got unexpected mipmap count %u.\n", i
, U2(surface_desc
).dwMipMapCount
);
6350 if (U2(surface_desc
).dwMipMapCount
> 1)
6352 hr
= IDirectDrawSurface2_GetAttachedSurface(surface
, &caps
, &surface2
);
6353 ok(SUCCEEDED(hr
), "Test %u: Failed to get attached surface, hr %#x.\n", i
, hr
);
6355 memset(&surface_desc
, 0, sizeof(surface_desc
));
6356 surface_desc
.dwSize
= sizeof(surface_desc
);
6357 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
6358 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
6359 memset(&surface_desc
, 0, sizeof(surface_desc
));
6360 surface_desc
.dwSize
= sizeof(surface_desc
);
6361 hr
= IDirectDrawSurface2_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
6362 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
6363 IDirectDrawSurface2_Unlock(surface2
, NULL
);
6364 IDirectDrawSurface2_Unlock(surface
, NULL
);
6366 IDirectDrawSurface2_Release(surface2
);
6369 IDirectDrawSurface2_Release(surface
);
6372 refcount
= IDirectDraw2_Release(ddraw
);
6373 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6374 DestroyWindow(window
);
6377 static void test_palette_complex(void)
6379 IDirectDrawSurface
*surface1
;
6380 IDirectDrawSurface2
*surface
, *mipmap
, *tmp
;
6381 DDSURFACEDESC surface_desc
;
6382 IDirectDraw2
*ddraw
;
6383 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
6387 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
6389 PALETTEENTRY palette_entries
[256];
6395 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6396 0, 0, 640, 480, 0, 0, 0, 0);
6397 ddraw
= create_ddraw();
6398 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6399 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6400 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6402 memset(&hal_caps
, 0, sizeof(hal_caps
));
6403 hal_caps
.dwSize
= sizeof(hal_caps
);
6404 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
6405 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6406 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6408 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
6409 IDirectDraw2_Release(ddraw
);
6410 DestroyWindow(window
);
6414 memset(&surface_desc
, 0, sizeof(surface_desc
));
6415 surface_desc
.dwSize
= sizeof(surface_desc
);
6416 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6417 surface_desc
.dwWidth
= 128;
6418 surface_desc
.dwHeight
= 128;
6419 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6420 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6421 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6422 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6423 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6424 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6425 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
6426 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
6427 IDirectDrawSurface_Release(surface1
);
6429 memset(palette_entries
, 0, sizeof(palette_entries
));
6430 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6431 palette_entries
, &palette
, NULL
);
6432 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6434 memset(palette_entries
, 0, sizeof(palette_entries
));
6435 palette_entries
[1].peRed
= 0xff;
6436 palette_entries
[1].peGreen
= 0x80;
6437 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6438 palette_entries
, &palette_mipmap
, NULL
);
6439 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6441 palette2
= (void *)0xdeadbeef;
6442 hr
= IDirectDrawSurface2_GetPalette(surface
, &palette2
);
6443 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6444 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
6445 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
6446 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6447 hr
= IDirectDrawSurface2_GetPalette(surface
, &palette2
);
6448 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6449 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
6450 IDirectDrawPalette_Release(palette2
);
6453 IDirectDrawSurface2_AddRef(mipmap
);
6454 for (i
= 0; i
< 7; ++i
)
6456 hr
= IDirectDrawSurface2_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6457 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
6458 palette2
= (void *)0xdeadbeef;
6459 hr
= IDirectDrawSurface2_GetPalette(tmp
, &palette2
);
6460 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
6461 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
6463 hr
= IDirectDrawSurface2_SetPalette(tmp
, palette_mipmap
);
6464 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
6466 hr
= IDirectDrawSurface2_GetPalette(tmp
, &palette2
);
6467 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
6468 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
6469 IDirectDrawPalette_Release(palette2
);
6471 hr
= IDirectDrawSurface2_GetDC(tmp
, &dc
);
6472 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
6473 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
6474 ok(count
== 1, "Expected count 1, got %u.\n", count
);
6475 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
6476 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
6477 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
6478 hr
= IDirectDrawSurface2_ReleaseDC(tmp
, dc
);
6479 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
6481 IDirectDrawSurface2_Release(mipmap
);
6485 hr
= IDirectDrawSurface2_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6486 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6487 IDirectDrawSurface2_Release(mipmap
);
6488 refcount
= IDirectDrawSurface2_Release(surface
);
6489 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6490 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
6491 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6492 refcount
= IDirectDrawPalette_Release(palette
);
6493 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6495 refcount
= IDirectDraw2_Release(ddraw
);
6496 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6497 DestroyWindow(window
);
6500 static void test_p8_blit(void)
6502 IDirectDrawSurface
*src
, *dst
, *dst_p8
;
6503 DDSURFACEDESC surface_desc
;
6504 IDirectDraw2
*ddraw
;
6505 IDirectDrawPalette
*palette
, *palette2
;
6509 PALETTEENTRY palette_entries
[256];
6513 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
6514 static const BYTE src_data2
[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
6515 static const BYTE expected_p8
[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
6516 static const D3DCOLOR expected
[] =
6518 0x00101010, 0x00010101, 0x00020202, 0x00030303,
6519 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
6523 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6524 0, 0, 640, 480, 0, 0, 0, 0);
6525 ddraw
= create_ddraw();
6526 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6527 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6528 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6529 is_warp
= ddraw_is_warp(ddraw
);
6531 memset(palette_entries
, 0, sizeof(palette_entries
));
6532 palette_entries
[1].peGreen
= 0xff;
6533 palette_entries
[2].peBlue
= 0xff;
6534 palette_entries
[3].peFlags
= 0xff;
6535 palette_entries
[4].peRed
= 0xff;
6536 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6537 palette_entries
, &palette
, NULL
);
6538 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6539 palette_entries
[1].peBlue
= 0xff;
6540 palette_entries
[2].peGreen
= 0xff;
6541 palette_entries
[3].peRed
= 0xff;
6542 palette_entries
[4].peFlags
= 0x0;
6543 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6544 palette_entries
, &palette2
, NULL
);
6545 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6547 memset(&surface_desc
, 0, sizeof(surface_desc
));
6548 surface_desc
.dwSize
= sizeof(surface_desc
);
6549 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6550 surface_desc
.dwWidth
= 8;
6551 surface_desc
.dwHeight
= 1;
6552 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6553 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6554 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6555 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6556 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
6557 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6558 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst_p8
, NULL
);
6559 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6560 hr
= IDirectDrawSurface_SetPalette(dst_p8
, palette2
);
6561 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6563 memset(&surface_desc
, 0, sizeof(surface_desc
));
6564 surface_desc
.dwSize
= sizeof(surface_desc
);
6565 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6566 surface_desc
.dwWidth
= 8;
6567 surface_desc
.dwHeight
= 1;
6568 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6569 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6570 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6571 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6572 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6573 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6574 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6575 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6576 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
6577 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6579 memset(&surface_desc
, 0, sizeof(surface_desc
));
6580 surface_desc
.dwSize
= sizeof(surface_desc
);
6581 hr
= IDirectDrawSurface_Lock(src
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
6582 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
6583 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
6584 hr
= IDirectDrawSurface_Unlock(src
, NULL
);
6585 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
6587 hr
= IDirectDrawSurface_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
6588 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
6589 memcpy(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
));
6590 hr
= IDirectDrawSurface_Unlock(dst_p8
, NULL
);
6591 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
6593 hr
= IDirectDrawSurface_SetPalette(src
, palette
);
6594 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6595 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
6596 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
6597 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
6598 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
6599 "Failed to blit, hr %#x.\n", hr
);
6603 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
6605 color
= get_surface_color(dst
, x
, 0);
6606 todo_wine
ok(compare_color(color
, expected
[x
], 0),
6607 "Pixel %u: Got color %#x, expected %#x.\n",
6608 x
, color
, expected
[x
]);
6612 memset(&fx
, 0, sizeof(fx
));
6613 fx
.dwSize
= sizeof(fx
);
6614 fx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 0x2;
6615 fx
.ddckSrcColorkey
.dwColorSpaceLowValue
= 0x2;
6616 hr
= IDirectDrawSurface7_Blt(dst_p8
, NULL
, src
, NULL
, DDBLT_WAIT
| DDBLT_KEYSRCOVERRIDE
, &fx
);
6617 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
6619 hr
= IDirectDrawSurface_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
6620 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
6621 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
6622 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
6623 * for example) also works as expected.
6625 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
6626 * the display mode set to P8 doesn't help either. */
6627 ok(!memcmp(surface_desc
.lpSurface
, expected_p8
, sizeof(expected_p8
))
6628 || broken(is_warp
&& !memcmp(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
))),
6629 "Got unexpected P8 color key blit result.\n");
6630 hr
= IDirectDrawSurface_Unlock(dst_p8
, NULL
);
6631 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
6633 IDirectDrawSurface_Release(src
);
6634 IDirectDrawSurface_Release(dst
);
6635 IDirectDrawSurface_Release(dst_p8
);
6636 IDirectDrawPalette_Release(palette
);
6637 IDirectDrawPalette_Release(palette2
);
6639 refcount
= IDirectDraw2_Release(ddraw
);
6640 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6641 DestroyWindow(window
);
6644 static void test_material(void)
6646 IDirect3DMaterial2
*background
, *material
;
6647 D3DMATERIALHANDLE mat_handle
, tmp
;
6648 IDirect3DViewport2
*viewport
;
6649 IDirect3DDevice2
*device
;
6650 IDirectDrawSurface
*rt
;
6651 IDirectDraw2
*ddraw
;
6659 static D3DVERTEX quad
[] =
6661 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6662 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6663 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6664 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6669 D3DCOLOR expected_color
;
6674 {FALSE
, 0x00ffffff},
6676 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6678 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6679 0, 0, 640, 480, 0, 0, 0, 0);
6680 ddraw
= create_ddraw();
6681 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6682 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6684 skip("Failed to create a 3D device, skipping test.\n");
6685 DestroyWindow(window
);
6689 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6690 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6692 background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
6693 viewport
= create_viewport(device
, 0, 0, 640, 480);
6694 viewport_set_background(device
, viewport
, background
);
6695 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6696 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6698 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
6699 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6700 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6702 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6703 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6704 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6705 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6706 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6707 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6708 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6709 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6710 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, 0);
6711 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6712 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6713 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6714 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6716 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6718 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
6719 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6721 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
6722 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6724 hr
= IDirect3DDevice2_BeginScene(device
);
6725 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6726 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_VERTEX
, quad
, 4, 0);
6727 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6728 hr
= IDirect3DDevice2_EndScene(device
);
6729 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6730 color
= get_surface_color(rt
, 320, 240);
6731 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
6732 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
6735 destroy_material(material
);
6736 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
6737 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6738 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6740 hr
= IDirect3DViewport2_SetBackground(viewport
, mat_handle
);
6741 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
6742 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6743 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6744 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6745 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6746 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6747 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6748 color
= get_surface_color(rt
, 320, 240);
6749 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6751 hr
= IDirect3DViewport2_SetBackground(viewport
, 0);
6752 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6753 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6754 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6755 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6756 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6757 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6758 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6759 color
= get_surface_color(rt
, 320, 240);
6760 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6762 destroy_viewport(device
, viewport
);
6763 viewport
= create_viewport(device
, 0, 0, 640, 480);
6765 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6766 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6767 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6768 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
6769 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6770 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6771 color
= get_surface_color(rt
, 320, 240);
6772 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
6774 destroy_viewport(device
, viewport
);
6775 destroy_material(background
);
6776 destroy_material(material
);
6777 IDirectDrawSurface_Release(rt
);
6778 refcount
= IDirect3DDevice2_Release(device
);
6779 ok(!refcount
, "Device has %u references left.\n", refcount
);
6780 refcount
= IDirectDraw2_Release(ddraw
);
6781 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
6782 DestroyWindow(window
);
6785 static void test_lighting(void)
6787 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6788 static D3DMATRIX mat
=
6790 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6791 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6792 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6793 0.0f
, 0.0f
, 0.0f
, 1.0f
,
6797 1.0f
, 0.0f
, 1.0f
, 0.0f
,
6798 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6799 1.0f
, 0.0f
, 1.0f
, 0.0f
,
6800 0.0f
, 0.0f
, 0.5f
, 1.0f
,
6804 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6805 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6806 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
6807 10.f
, 10.0f
, 10.0f
, 1.0f
,
6811 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6812 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6813 0.0f
, 0.0f
, 1.0f
, -1.0f
,
6814 10.f
, 10.0f
, 10.0f
, 0.0f
,
6816 static D3DLVERTEX unlitquad
[] =
6818 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6819 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6820 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6821 {{ 0.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6825 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6826 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6827 {{ 0.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6828 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6830 static D3DVERTEX unlitnquad
[] =
6832 {{0.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6833 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6834 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6835 {{1.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6839 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6840 {{0.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6841 {{1.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6842 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6846 {{-1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6847 {{-1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6848 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6849 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6853 {{-10.0f
}, {-11.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6854 {{-10.0f
}, { -9.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6855 {{-10.0f
}, { -9.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6856 {{-10.0f
}, {-11.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6860 {{-11.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6861 {{-11.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6862 {{ -9.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6863 {{ -9.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6865 static WORD indices
[] = {0, 1, 2, 2, 3, 0};
6868 D3DMATRIX
*world_matrix
;
6871 const char *message
;
6875 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
6876 {&mat_singular
, nquad
, 0x000000b4, "Lit quad with singular world matrix"},
6877 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
6878 {&mat_nonaffine
, translatedquad
, 0x000000ff, "Lit quad with non-affine matrix"},
6883 IDirect3DDevice2
*device
;
6884 IDirectDraw2
*ddraw
;
6885 IDirectDrawSurface
*rt
;
6886 IDirect3DViewport2
*viewport
;
6887 IDirect3DMaterial2
*material
;
6888 IDirect3DLight
*light
;
6889 D3DMATERIALHANDLE mat_handle
;
6890 D3DLIGHT2 light_desc
;
6896 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6897 0, 0, 640, 480, 0, 0, 0, 0);
6898 ddraw
= create_ddraw();
6899 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6900 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6902 skip("Failed to create a 3D device, skipping test.\n");
6903 DestroyWindow(window
);
6907 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
6908 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
6910 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6911 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6913 viewport
= create_viewport(device
, 0, 0, 640, 480);
6914 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6915 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6917 material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
6918 viewport_set_background(device
, viewport
, material
);
6920 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6921 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6923 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
6924 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
6925 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
6926 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
6927 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
6928 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
6929 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
6930 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
6931 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
6932 ok(SUCCEEDED(hr
), "Failed to disable zbuffer, hr %#x.\n", hr
);
6933 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
6934 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
6935 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
6936 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
6938 hr
= IDirect3DDevice2_BeginScene(device
);
6939 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6941 /* There is no D3DRENDERSTATE_LIGHTING on ddraw < 7. */
6942 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
6943 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6944 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_LVERTEX
, unlitquad
,
6946 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6948 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
6949 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
6950 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_LVERTEX
, litquad
,
6952 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6954 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
6955 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6956 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, unlitnquad
,
6958 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6960 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
6961 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6962 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, litnquad
,
6964 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6966 hr
= IDirect3DDevice2_EndScene(device
);
6967 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6969 color
= get_surface_color(rt
, 160, 360);
6970 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color
);
6971 color
= get_surface_color(rt
, 160, 120);
6972 ok(color
== 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color
);
6973 color
= get_surface_color(rt
, 480, 360);
6974 ok(color
== 0x00ffffff, "Unlit quad with normals has color 0x%08x.\n", color
);
6975 color
= get_surface_color(rt
, 480, 120);
6976 ok(color
== 0x00ffffff, "Lit quad with normals has color 0x%08x.\n", color
);
6978 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6979 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6980 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6981 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6983 hr
= IDirect3D2_CreateLight(d3d
, &light
, NULL
);
6984 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
6985 memset(&light_desc
, 0, sizeof(light_desc
));
6986 light_desc
.dwSize
= sizeof(light_desc
);
6987 light_desc
.dltType
= D3DLIGHT_DIRECTIONAL
;
6988 U1(light_desc
.dcvColor
).r
= 0.0f
;
6989 U2(light_desc
.dcvColor
).g
= 0.0f
;
6990 U3(light_desc
.dcvColor
).b
= 1.0f
;
6991 U4(light_desc
.dcvColor
).a
= 1.0f
;
6992 U3(light_desc
.dvDirection
).z
= 1.0f
;
6993 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
6994 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
6995 hr
= IDirect3DViewport2_AddLight(viewport
, light
);
6996 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
6998 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6999 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7001 hr
= IDirect3DDevice2_BeginScene(device
);
7002 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7004 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, nquad
,
7006 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7008 hr
= IDirect3DDevice2_EndScene(device
);
7009 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7011 color
= get_surface_color(rt
, 320, 240);
7012 ok(color
== 0x00000000, "Lit quad with no light has color 0x%08x.\n", color
);
7014 light_desc
.dwFlags
= D3DLIGHT_ACTIVE
;
7015 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
7016 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
7018 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
7020 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, tests
[i
].world_matrix
);
7021 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
7023 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7024 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7026 hr
= IDirect3DDevice2_BeginScene(device
);
7027 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7029 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
,
7030 tests
[i
].quad
, 4, indices
, 6, 0);
7031 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7033 hr
= IDirect3DDevice2_EndScene(device
);
7034 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7036 color
= get_surface_color(rt
, 320, 240);
7037 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
7040 hr
= IDirect3DViewport2_DeleteLight(viewport
, light
);
7041 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
7042 IDirect3DLight_Release(light
);
7043 destroy_material(material
);
7044 destroy_viewport(device
, viewport
);
7045 IDirectDrawSurface2_Release(rt
);
7046 refcount
= IDirect3DDevice2_Release(device
);
7047 ok(!refcount
, "Device has %u references left.\n", refcount
);
7048 IDirect3D2_Release(d3d
);
7049 refcount
= IDirectDraw2_Release(ddraw
);
7050 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
7051 DestroyWindow(window
);
7054 static void test_specular_lighting(void)
7056 static const unsigned int vertices_side
= 5;
7057 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
7058 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7059 static D3DMATRIX mat
=
7061 1.0f
, 0.0f
, 0.0f
, 0.0f
,
7062 0.0f
, 1.0f
, 0.0f
, 0.0f
,
7063 0.0f
, 0.0f
, 1.0f
, 0.0f
,
7064 0.0f
, 0.0f
, 0.0f
, 1.0f
,
7066 static D3DLIGHT2 directional
=
7069 D3DLIGHT_DIRECTIONAL
,
7070 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7071 {{0.0f
}, {0.0f
}, {0.0f
}},
7072 {{0.0f
}, {0.0f
}, {1.0f
}},
7078 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7079 {{0.0f
}, {0.0f
}, {0.0f
}},
7080 {{0.0f
}, {0.0f
}, {0.0f
}},
7089 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7090 {{0.0f
}, {0.0f
}, {0.0f
}},
7091 {{0.0f
}, {0.0f
}, {1.0f
}},
7095 M_PI
/ 12.0f
, M_PI
/ 3.0f
7100 D3DLIGHT_PARALLELPOINT
,
7101 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7102 {{0.5f
}, {0.0f
}, {-1.0f
}},
7103 {{0.0f
}, {0.0f
}, {0.0f
}},
7105 static const struct expected_color
7110 expected_directional_local
[] =
7112 {160, 120, 0x003c3c3c},
7113 {320, 120, 0x00717171},
7114 {480, 120, 0x003c3c3c},
7115 {160, 240, 0x00717171},
7116 {320, 240, 0x00ffffff},
7117 {480, 240, 0x00717171},
7118 {160, 360, 0x003c3c3c},
7119 {320, 360, 0x00717171},
7120 {480, 360, 0x003c3c3c},
7122 expected_point_local
[] =
7124 {160, 120, 0x00000000},
7125 {320, 120, 0x00090909},
7126 {480, 120, 0x00000000},
7127 {160, 240, 0x00090909},
7128 {320, 240, 0x00fafafa},
7129 {480, 240, 0x00090909},
7130 {160, 360, 0x00000000},
7131 {320, 360, 0x00090909},
7132 {480, 360, 0x00000000},
7134 expected_spot_local
[] =
7136 {160, 120, 0x00000000},
7137 {320, 120, 0x00020202},
7138 {480, 120, 0x00000000},
7139 {160, 240, 0x00020202},
7140 {320, 240, 0x00fafafa},
7141 {480, 240, 0x00020202},
7142 {160, 360, 0x00000000},
7143 {320, 360, 0x00020202},
7144 {480, 360, 0x00000000},
7146 expected_parallelpoint
[] =
7148 {160, 120, 0x00050505},
7149 {320, 120, 0x002c2c2c},
7150 {480, 120, 0x006e6e6e},
7151 {160, 240, 0x00090909},
7152 {320, 240, 0x00717171},
7153 {480, 240, 0x00ffffff},
7154 {160, 360, 0x00050505},
7155 {320, 360, 0x002c2c2c},
7156 {480, 360, 0x006e6e6e},
7161 const struct expected_color
*expected
;
7162 unsigned int expected_count
;
7166 {&directional
, expected_directional_local
,
7167 sizeof(expected_directional_local
) / sizeof(expected_directional_local
[0])},
7168 {&point
, expected_point_local
,
7169 sizeof(expected_point_local
) / sizeof(expected_point_local
[0])},
7170 {&spot
, expected_spot_local
,
7171 sizeof(expected_spot_local
) / sizeof(expected_spot_local
[0])},
7172 {¶llelpoint
, expected_parallelpoint
,
7173 sizeof(expected_parallelpoint
) / sizeof(expected_parallelpoint
[0])},
7176 IDirect3DDevice2
*device
;
7177 IDirectDraw2
*ddraw
;
7178 IDirectDrawSurface
*rt
;
7179 IDirect3DViewport2
*viewport
;
7180 IDirect3DMaterial2
*material
, *background_material
;
7181 IDirect3DLight
*light
;
7182 D3DMATERIALHANDLE mat_handle
;
7187 unsigned int i
, j
, x
, y
;
7191 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7192 0, 0, 640, 480, 0, 0, 0, 0);
7193 ddraw
= create_ddraw();
7194 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7195 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
7197 skip("Failed to create a 3D device, skipping test.\n");
7198 DestroyWindow(window
);
7202 quad
= HeapAlloc(GetProcessHeap(), 0, vertices_side
* vertices_side
* sizeof(*quad
));
7203 indices
= HeapAlloc(GetProcessHeap(), 0, indices_count
* sizeof(*indices
));
7204 for (i
= 0, y
= 0; y
< vertices_side
; ++y
)
7206 for (x
= 0; x
< vertices_side
; ++x
)
7208 U1(quad
[i
]).x
= x
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
7209 U2(quad
[i
]).y
= y
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
7210 U3(quad
[i
]).z
= 1.0f
;
7211 U4(quad
[i
]).nx
= 0.0f
;
7212 U5(quad
[i
]).ny
= 0.0f
;
7213 U6(quad
[i
]).nz
= -1.0f
;
7214 U7(quad
[i
]).tu
= 0.0f
;
7215 U8(quad
[i
++]).tv
= 0.0f
;
7218 for (i
= 0, y
= 0; y
< (vertices_side
- 1); ++y
)
7220 for (x
= 0; x
< (vertices_side
- 1); ++x
)
7222 indices
[i
++] = y
* vertices_side
+ x
+ 1;
7223 indices
[i
++] = y
* vertices_side
+ x
;
7224 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
7225 indices
[i
++] = y
* vertices_side
+ x
+ 1;
7226 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
7227 indices
[i
++] = (y
+ 1) * vertices_side
+ x
+ 1;
7231 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
7232 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
7234 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
7235 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
7237 viewport
= create_viewport(device
, 0, 0, 640, 480);
7238 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
7239 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
7241 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
7242 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
7243 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
7244 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
7245 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
7246 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
7247 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
7248 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
7249 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
7250 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
7251 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
7252 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
7254 background_material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
7255 viewport_set_background(device
, viewport
, background_material
);
7257 material
= create_specular_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 30.0f
);
7258 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
7259 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
7260 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
7261 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
7263 hr
= IDirect3D2_CreateLight(d3d
, &light
, NULL
);
7264 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
7265 hr
= IDirect3DViewport2_AddLight(viewport
, light
);
7266 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
7268 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, TRUE
);
7269 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
7271 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
7273 tests
[i
].light
->dwFlags
= D3DLIGHT_ACTIVE
;
7274 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)tests
[i
].light
);
7275 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
7277 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7278 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7280 hr
= IDirect3DDevice2_BeginScene(device
);
7281 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7283 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
,
7284 quad
, vertices_side
* vertices_side
, indices
, indices_count
, 0);
7285 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7287 hr
= IDirect3DDevice2_EndScene(device
);
7288 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7290 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
7292 color
= get_surface_color(rt
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
7293 ok(compare_color(color
, tests
[i
].expected
[j
].color
, 1),
7294 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
7295 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
7296 tests
[i
].expected
[j
].y
, color
, i
);
7300 hr
= IDirect3DViewport2_DeleteLight(viewport
, light
);
7301 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
7302 IDirect3DLight_Release(light
);
7303 destroy_material(material
);
7304 destroy_material(background_material
);
7305 destroy_viewport(device
, viewport
);
7306 IDirectDrawSurface2_Release(rt
);
7307 refcount
= IDirect3DDevice2_Release(device
);
7308 ok(!refcount
, "Device has %u references left.\n", refcount
);
7309 IDirect3D2_Release(d3d
);
7310 refcount
= IDirectDraw2_Release(ddraw
);
7311 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
7312 DestroyWindow(window
);
7313 HeapFree(GetProcessHeap(), 0, indices
);
7314 HeapFree(GetProcessHeap(), 0, quad
);
7317 static void test_palette_gdi(void)
7319 IDirectDrawSurface
*surface
, *primary
;
7320 DDSURFACEDESC surface_desc
;
7321 IDirectDraw2
*ddraw
;
7322 IDirectDrawPalette
*palette
, *palette2
;
7326 PALETTEENTRY palette_entries
[256];
7332 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7333 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7334 * not the point of this test. */
7335 static const RGBQUAD expected1
[] =
7337 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7338 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7340 static const RGBQUAD expected2
[] =
7342 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7343 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7345 static const RGBQUAD expected3
[] =
7347 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7348 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7350 HPALETTE ddraw_palette_handle
;
7351 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7352 RGBQUAD rgbquad
[255];
7353 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
7355 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7356 0, 0, 640, 480, 0, 0, 0, 0);
7357 ddraw
= create_ddraw();
7358 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7359 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7360 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7362 memset(&surface_desc
, 0, sizeof(surface_desc
));
7363 surface_desc
.dwSize
= sizeof(surface_desc
);
7364 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7365 surface_desc
.dwWidth
= 16;
7366 surface_desc
.dwHeight
= 16;
7367 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7368 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7369 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7370 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
7371 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7372 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7374 /* Avoid colors from the Windows default palette. */
7375 memset(palette_entries
, 0, sizeof(palette_entries
));
7376 palette_entries
[1].peRed
= 0x01;
7377 palette_entries
[2].peGreen
= 0x02;
7378 palette_entries
[3].peBlue
= 0x03;
7379 palette_entries
[4].peRed
= 0x13;
7380 palette_entries
[4].peGreen
= 0x14;
7381 palette_entries
[4].peBlue
= 0x15;
7382 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7383 palette_entries
, &palette
, NULL
);
7384 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7386 /* If there is no palette assigned and the display mode is not 8 bpp, some
7387 * drivers refuse to create a DC while others allow it. If a DC is created,
7388 * the DIB color table is uninitialized and contains random colors. No error
7389 * is generated when trying to read pixels and random garbage is returned.
7391 * The most likely explanation is that if the driver creates a DC, it (or
7392 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7393 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7394 * contains uninitialized garbage. See comments below for the P8 case. */
7396 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
7397 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7398 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7399 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7400 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7401 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7402 "Got unexpected palette %p, expected %p.\n",
7403 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7405 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7406 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7407 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
7409 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
7410 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7411 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7412 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
7414 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7416 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7417 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7418 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7421 /* Update the palette while the DC is in use. This does not modify the DC. */
7422 palette_entries
[4].peRed
= 0x23;
7423 palette_entries
[4].peGreen
= 0x24;
7424 palette_entries
[4].peBlue
= 0x25;
7425 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
7426 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
7428 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7429 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7430 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7431 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7432 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7433 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7435 /* Neither does re-setting the palette. */
7436 hr
= IDirectDrawSurface_SetPalette(surface
, NULL
);
7437 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7438 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
7439 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7441 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7442 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7443 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7444 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7445 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7446 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7448 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7449 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7451 /* Refresh the DC. This updates the palette. */
7452 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7453 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7454 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7455 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7456 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7458 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7459 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7460 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7461 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7463 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7465 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7466 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7467 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7469 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7470 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7472 refcount
= IDirectDrawSurface_Release(surface
);
7473 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7475 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
7476 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7477 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7479 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7480 IDirectDrawPalette_Release(palette
);
7481 IDirectDraw2_Release(ddraw
);
7482 DestroyWindow(window
);
7485 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
7487 memset(&surface_desc
, 0, sizeof(surface_desc
));
7488 surface_desc
.dwSize
= sizeof(surface_desc
);
7489 surface_desc
.dwFlags
= DDSD_CAPS
;
7490 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7491 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
7492 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7494 memset(&fx
, 0, sizeof(fx
));
7495 fx
.dwSize
= sizeof(fx
);
7496 U5(fx
).dwFillColor
= 3;
7497 SetRect(&r
, 0, 0, 319, 479);
7498 hr
= IDirectDrawSurface_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7499 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
7500 SetRect(&r
, 320, 0, 639, 479);
7501 U5(fx
).dwFillColor
= 4;
7502 hr
= IDirectDrawSurface_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7503 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
7505 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
7506 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7507 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
7508 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7510 color
= GetPixel(dc
, 160, 240);
7511 ok(color
== 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color
);
7512 color
= GetPixel(dc
, 480, 240);
7513 ok(color
== 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color
);
7515 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7516 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7517 "Got unexpected palette %p, expected %p.\n",
7518 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7519 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
7521 /* The primary uses the system palette. In exclusive mode, the system palette matches
7522 * the ddraw palette attached to the primary, so the result is what you would expect
7523 * from a regular surface. Tests for the interaction between the ddraw palette and
7524 * the system palette are not included pending an application that depends on this.
7525 * The relation between those causes problems on Windows Vista and newer for games
7526 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
7527 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7528 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7529 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7531 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7532 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7533 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7534 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7536 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7538 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7539 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7540 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7542 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
7543 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7545 memset(&surface_desc
, 0, sizeof(surface_desc
));
7546 surface_desc
.dwSize
= sizeof(surface_desc
);
7547 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7548 surface_desc
.dwWidth
= 16;
7549 surface_desc
.dwHeight
= 16;
7550 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7551 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7552 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7554 /* Here the offscreen surface appears to use the primary's palette,
7555 * but in all likelihood it is actually the system palette. */
7556 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7557 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7558 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7559 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7560 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7562 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7563 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7564 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7565 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7567 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7569 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7570 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7571 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7573 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7574 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7576 /* On real hardware a change to the primary surface's palette applies immediately,
7577 * even on device contexts from offscreen surfaces that do not have their own
7578 * palette. On the testbot VMs this is not the case. Don't test this until we
7579 * know of an application that depends on this. */
7581 memset(palette_entries
, 0, sizeof(palette_entries
));
7582 palette_entries
[1].peBlue
= 0x40;
7583 palette_entries
[2].peRed
= 0x40;
7584 palette_entries
[3].peGreen
= 0x40;
7585 palette_entries
[4].peRed
= 0x12;
7586 palette_entries
[4].peGreen
= 0x34;
7587 palette_entries
[4].peBlue
= 0x56;
7588 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7589 palette_entries
, &palette2
, NULL
);
7590 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7591 hr
= IDirectDrawSurface_SetPalette(surface
, palette2
);
7592 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7594 /* A palette assigned to the offscreen surface overrides the primary / system
7596 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7597 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7598 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7599 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7600 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
7602 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
7603 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7604 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7605 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
7607 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7609 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7610 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7611 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7613 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7614 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7616 refcount
= IDirectDrawSurface_Release(surface
);
7617 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7619 /* The Windows 8 testbot keeps extra references to the primary and
7620 * backbuffer while in 8 bpp mode. */
7621 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
7622 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7624 refcount
= IDirectDrawSurface_Release(primary
);
7625 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7626 refcount
= IDirectDrawPalette_Release(palette2
);
7627 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7628 refcount
= IDirectDrawPalette_Release(palette
);
7629 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7630 refcount
= IDirectDraw2_Release(ddraw
);
7631 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7632 DestroyWindow(window
);
7635 static void test_palette_alpha(void)
7637 IDirectDrawSurface
*surface1
;
7638 IDirectDrawSurface2
*surface
;
7639 DDSURFACEDESC surface_desc
;
7640 IDirectDraw2
*ddraw
;
7641 IDirectDrawPalette
*palette
;
7645 PALETTEENTRY palette_entries
[256];
7650 BOOL attach_allowed
;
7655 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
7656 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
7657 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
7660 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7661 0, 0, 640, 480, 0, 0, 0, 0);
7662 ddraw
= create_ddraw();
7663 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7664 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7666 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7667 IDirectDraw2_Release(ddraw
);
7668 DestroyWindow(window
);
7671 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7672 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7674 memset(palette_entries
, 0, sizeof(palette_entries
));
7675 palette_entries
[1].peFlags
= 0x42;
7676 palette_entries
[2].peFlags
= 0xff;
7677 palette_entries
[3].peFlags
= 0x80;
7678 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
7679 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7681 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7682 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7683 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7684 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7685 palette_entries
[0].peFlags
);
7686 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7687 palette_entries
[1].peFlags
);
7688 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7689 palette_entries
[2].peFlags
);
7690 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7691 palette_entries
[3].peFlags
);
7693 IDirectDrawPalette_Release(palette
);
7695 memset(palette_entries
, 0, sizeof(palette_entries
));
7696 palette_entries
[1].peFlags
= 0x42;
7697 palette_entries
[1].peRed
= 0xff;
7698 palette_entries
[2].peFlags
= 0xff;
7699 palette_entries
[3].peFlags
= 0x80;
7700 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
7701 palette_entries
, &palette
, NULL
);
7702 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7704 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7705 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7706 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7707 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7708 palette_entries
[0].peFlags
);
7709 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7710 palette_entries
[1].peFlags
);
7711 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7712 palette_entries
[2].peFlags
);
7713 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7714 palette_entries
[3].peFlags
);
7716 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
7718 memset(&surface_desc
, 0, sizeof(surface_desc
));
7719 surface_desc
.dwSize
= sizeof(surface_desc
);
7720 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
7721 surface_desc
.dwWidth
= 128;
7722 surface_desc
.dwHeight
= 128;
7723 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
7724 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7725 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7726 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
7727 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
7728 IDirectDrawSurface_Release(surface1
);
7730 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
7731 if (test_data
[i
].attach_allowed
)
7732 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7734 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7742 hr
= IDirectDrawSurface2_GetDC(surface
, &dc
);
7743 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_CANTCREATEDC
) /* Win2k testbot */,
7744 "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7747 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
7748 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
7749 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
7750 rgbquad
.rgbRed
, test_data
[i
].name
);
7751 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
7752 rgbquad
.rgbGreen
, test_data
[i
].name
);
7753 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
7754 rgbquad
.rgbBlue
, test_data
[i
].name
);
7755 ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
7756 rgbquad
.rgbReserved
, test_data
[i
].name
);
7757 hr
= IDirectDrawSurface2_ReleaseDC(surface
, dc
);
7758 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7761 IDirectDrawSurface2_Release(surface
);
7764 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
7765 memset(&surface_desc
, 0, sizeof(surface_desc
));
7766 surface_desc
.dwSize
= sizeof(surface_desc
);
7767 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7768 surface_desc
.dwWidth
= 128;
7769 surface_desc
.dwHeight
= 128;
7770 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7771 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7772 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7773 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7774 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7775 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7776 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7777 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7778 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7779 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
7780 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
7781 IDirectDrawSurface_Release(surface1
);
7783 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
7784 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
7785 IDirectDrawSurface2_Release(surface
);
7787 /* The Windows 8 testbot keeps extra references to the primary
7788 * while in 8 bpp mode. */
7789 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
7790 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7792 refcount
= IDirectDrawPalette_Release(palette
);
7793 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7794 refcount
= IDirectDraw2_Release(ddraw
);
7795 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7796 DestroyWindow(window
);
7799 static void test_lost_device(void)
7801 IDirectDrawSurface
*surface
;
7802 DDSURFACEDESC surface_desc
;
7803 HWND window1
, window2
;
7804 IDirectDraw2
*ddraw
;
7809 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7810 0, 0, 640, 480, 0, 0, 0, 0);
7811 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7812 0, 0, 640, 480, 0, 0, 0, 0);
7813 ddraw
= create_ddraw();
7814 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7815 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7816 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7818 memset(&surface_desc
, 0, sizeof(surface_desc
));
7819 surface_desc
.dwSize
= sizeof(surface_desc
);
7820 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
7821 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
7822 surface_desc
.dwBackBufferCount
= 1;
7823 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7824 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7826 hr
= IDirectDrawSurface_IsLost(surface
);
7827 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7828 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7829 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7831 ret
= SetForegroundWindow(GetDesktopWindow());
7832 ok(ret
, "Failed to set foreground window.\n");
7833 hr
= IDirectDrawSurface_IsLost(surface
);
7834 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7835 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7836 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7838 ret
= SetForegroundWindow(window1
);
7839 ok(ret
, "Failed to set foreground window.\n");
7840 hr
= IDirectDrawSurface_IsLost(surface
);
7841 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7842 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7843 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7845 hr
= restore_surfaces(ddraw
);
7846 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7847 hr
= IDirectDrawSurface_IsLost(surface
);
7848 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7849 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7850 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7852 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
7853 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7854 hr
= IDirectDrawSurface_IsLost(surface
);
7855 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7856 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7857 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7859 /* Trying to restore the primary will crash, probably because flippable
7860 * surfaces can't exist in DDSCL_NORMAL. */
7861 IDirectDrawSurface_Release(surface
);
7862 memset(&surface_desc
, 0, sizeof(surface_desc
));
7863 surface_desc
.dwSize
= sizeof(surface_desc
);
7864 surface_desc
.dwFlags
= DDSD_CAPS
;
7865 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7866 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7867 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7869 hr
= IDirectDrawSurface_IsLost(surface
);
7870 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7872 ret
= SetForegroundWindow(GetDesktopWindow());
7873 ok(ret
, "Failed to set foreground window.\n");
7874 hr
= IDirectDrawSurface_IsLost(surface
);
7875 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7877 ret
= SetForegroundWindow(window1
);
7878 ok(ret
, "Failed to set foreground window.\n");
7879 hr
= IDirectDrawSurface_IsLost(surface
);
7880 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7882 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7883 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7884 hr
= IDirectDrawSurface_IsLost(surface
);
7885 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7887 hr
= restore_surfaces(ddraw
);
7888 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7889 hr
= IDirectDrawSurface_IsLost(surface
);
7890 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7892 IDirectDrawSurface_Release(surface
);
7893 memset(&surface_desc
, 0, sizeof(surface_desc
));
7894 surface_desc
.dwSize
= sizeof(surface_desc
);
7895 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
7896 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
7897 surface_desc
.dwBackBufferCount
= 1;
7898 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7899 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7901 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7902 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7903 hr
= IDirectDrawSurface_IsLost(surface
);
7904 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7905 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7906 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7908 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
7909 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7910 hr
= IDirectDrawSurface_IsLost(surface
);
7911 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7912 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7913 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7915 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
7916 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7917 hr
= IDirectDrawSurface_IsLost(surface
);
7918 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7919 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7920 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7922 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
7923 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7924 hr
= IDirectDrawSurface_IsLost(surface
);
7925 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7926 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7927 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7929 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
7930 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7931 hr
= IDirectDrawSurface_IsLost(surface
);
7932 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7933 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7934 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7936 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7937 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7938 hr
= IDirectDrawSurface_IsLost(surface
);
7939 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7940 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7941 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7943 IDirectDrawSurface_Release(surface
);
7944 refcount
= IDirectDraw2_Release(ddraw
);
7945 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7946 DestroyWindow(window2
);
7947 DestroyWindow(window1
);
7950 static void test_surface_desc_lock(void)
7952 IDirectDrawSurface
*surface
;
7953 DDSURFACEDESC surface_desc
;
7954 IDirectDraw2
*ddraw
;
7959 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7960 0, 0, 640, 480, 0, 0, 0, 0);
7961 ddraw
= create_ddraw();
7962 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7963 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7964 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7966 memset(&surface_desc
, 0, sizeof(surface_desc
));
7967 surface_desc
.dwSize
= sizeof(surface_desc
);
7968 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7969 surface_desc
.dwWidth
= 16;
7970 surface_desc
.dwHeight
= 16;
7971 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7972 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7973 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7975 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7976 surface_desc
.dwSize
= sizeof(surface_desc
);
7977 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7978 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7979 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7981 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7982 surface_desc
.dwSize
= sizeof(surface_desc
);
7983 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7984 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7985 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7986 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7987 surface_desc
.dwSize
= sizeof(surface_desc
);
7988 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7989 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7990 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
7991 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
7992 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7994 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
7995 surface_desc
.dwSize
= sizeof(surface_desc
);
7996 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
7997 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
7998 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8000 IDirectDrawSurface_Release(surface
);
8001 refcount
= IDirectDraw2_Release(ddraw
);
8002 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8003 DestroyWindow(window
);
8006 static void test_texturemapblend(void)
8011 static RECT rect
= {0, 0, 64, 128};
8012 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8014 IDirectDrawSurface
*surface
, *rt
;
8015 IDirect3DTexture2
*texture
;
8016 D3DTEXTUREHANDLE texture_handle
;
8018 IDirectDraw2
*ddraw
;
8019 IDirect3DDevice2
*device
;
8020 IDirect3DMaterial2
*material
;
8021 IDirect3DViewport2
*viewport
;
8025 static D3DTLVERTEX test1_quads
[] =
8027 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {0.0f
}},
8028 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {1.0f
}},
8029 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {0.0f
}},
8030 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {1.0f
}},
8031 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {0.0f
}},
8032 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {1.0f
}},
8033 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {0.0f
}},
8034 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {1.0f
}},
8038 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {0.0f
}},
8039 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {1.0f
}},
8040 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {0.0f
}},
8041 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {1.0f
}},
8042 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {0.0f
}},
8043 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {1.0f
}},
8044 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {0.0f
}},
8045 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {1.0f
}},
8048 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8049 0, 0, 640, 480, 0, 0, 0, 0);
8050 ddraw
= create_ddraw();
8051 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8052 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8054 skip("Failed to create a 3D device, skipping test.\n");
8055 DestroyWindow(window
);
8056 IDirectDraw2_Release(ddraw
);
8060 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8061 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8063 material
= create_diffuse_material(device
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
8064 viewport
= create_viewport(device
, 0, 0, 640, 480);
8065 viewport_set_background(device
, viewport
, material
);
8066 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
8067 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
8069 /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel.
8071 * The vertex alpha is completely ignored in this case, so case 1 and 2 combined are not
8072 * a D3DTOP_MODULATE with texture alpha = 0xff in case 2 (no alpha in texture). */
8073 memset(&ddsd
, 0, sizeof(ddsd
));
8074 ddsd
.dwSize
= sizeof(ddsd
);
8075 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8076 ddsd
.dwHeight
= 128;
8078 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8079 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8080 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
8081 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8082 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8083 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8084 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8085 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
8086 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8087 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8089 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8090 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8091 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8092 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8093 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8094 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8096 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8097 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8099 memset(&fx
, 0, sizeof(fx
));
8100 fx
.dwSize
= sizeof(fx
);
8101 U5(fx
).dwFillColor
= 0xff0000ff;
8102 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8103 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8104 U5(fx
).dwFillColor
= 0x800000ff;
8105 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8106 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8108 /* Note that the ddraw1 version of this test runs tests 1-3 with D3DRENDERSTATE_COLORKEYENABLE
8109 * enabled, whereas this version only runs test 4 with color keying on. Because no color key
8110 * is set on the texture this should not result in different behavior. */
8111 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
8112 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8113 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8114 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8115 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
8116 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8117 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
8118 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8119 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
8120 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8121 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
);
8122 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8124 hr
= IDirect3DDevice2_BeginScene(device
);
8125 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8126 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8127 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8128 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8129 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8130 hr
= IDirect3DDevice2_EndScene(device
);
8131 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8133 color
= get_surface_color(rt
, 5, 5);
8134 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8135 color
= get_surface_color(rt
, 400, 5);
8136 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8137 color
= get_surface_color(rt
, 5, 245);
8138 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8139 color
= get_surface_color(rt
, 400, 245);
8140 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8142 IDirect3DTexture2_Release(texture
);
8143 ref
= IDirectDrawSurface_Release(surface
);
8144 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8146 /* Test alpha with texture that has no alpha channel - alpha should be taken from diffuse vertex color. */
8147 memset(&ddsd
, 0, sizeof(ddsd
));
8148 ddsd
.dwSize
= sizeof(ddsd
);
8149 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8150 ddsd
.dwHeight
= 128;
8152 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8153 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8154 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8155 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8156 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8157 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8158 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8160 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8161 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8163 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8164 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8165 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8166 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8167 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8168 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8170 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8171 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8173 U5(fx
).dwFillColor
= 0xff0000ff;
8174 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8175 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8176 U5(fx
).dwFillColor
= 0x800000ff;
8177 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8178 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8180 hr
= IDirect3DDevice2_BeginScene(device
);
8181 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8182 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8183 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8184 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8185 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8186 hr
= IDirect3DDevice2_EndScene(device
);
8187 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8189 color
= get_surface_color(rt
, 5, 5);
8190 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8191 color
= get_surface_color(rt
, 400, 5);
8192 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8193 color
= get_surface_color(rt
, 5, 245);
8194 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8195 color
= get_surface_color(rt
, 400, 245);
8196 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8198 IDirect3DTexture2_Release(texture
);
8199 ref
= IDirectDrawSurface_Release(surface
);
8200 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8202 /* Test RGB - should multiply color components from diffuse vertex color and texture. */
8203 memset(&ddsd
, 0, sizeof(ddsd
));
8204 ddsd
.dwSize
= sizeof(ddsd
);
8205 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8206 ddsd
.dwHeight
= 128;
8208 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8209 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8210 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
8211 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8212 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8213 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8214 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8215 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
8216 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8217 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8219 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8220 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8221 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8222 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8223 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8224 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8226 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8227 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8229 U5(fx
).dwFillColor
= 0x00ffffff;
8230 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8231 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8232 U5(fx
).dwFillColor
= 0x00ffff80;
8233 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8234 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8236 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
8237 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8239 hr
= IDirect3DDevice2_BeginScene(device
);
8240 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8241 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test2_quads
[0], 4, 0);
8242 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8243 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test2_quads
[4], 4, 0);
8244 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8245 hr
= IDirect3DDevice2_EndScene(device
);
8246 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8248 color
= get_surface_color(rt
, 5, 5);
8249 ok(compare_color(color
, 0x00ff0040, 2), "Got unexpected color 0x%08x.\n", color
);
8250 color
= get_surface_color(rt
, 400, 5);
8251 ok(compare_color(color
, 0x00ff0080, 2), "Got unexpected color 0x%08x.\n", color
);
8252 color
= get_surface_color(rt
, 5, 245);
8253 ok(compare_color(color
, 0x00800080, 2), "Got unexpected color 0x%08x.\n", color
);
8254 color
= get_surface_color(rt
, 400, 245);
8255 ok(compare_color(color
, 0x008000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8257 IDirect3DTexture2_Release(texture
);
8258 ref
= IDirectDrawSurface_Release(surface
);
8259 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8261 /* Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere). */
8262 memset(&ddsd
, 0, sizeof(ddsd
));
8263 ddsd
.dwSize
= sizeof(ddsd
);
8264 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8265 ddsd
.dwHeight
= 128;
8267 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8268 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8269 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8270 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 16;
8271 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
8272 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
8273 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
8275 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8276 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8278 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8279 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8280 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8281 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8282 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8283 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8285 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8286 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8288 U5(fx
).dwFillColor
= 0xf800;
8289 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8290 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8291 U5(fx
).dwFillColor
= 0x001f;
8292 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8293 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8295 ckey
.dwColorSpaceLowValue
= 0x001f;
8296 ckey
.dwColorSpaceHighValue
= 0x001f;
8297 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8298 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8300 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
8301 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8302 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
8303 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8305 hr
= IDirect3DDevice2_BeginScene(device
);
8306 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8307 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8308 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8309 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8310 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8311 hr
= IDirect3DDevice2_EndScene(device
);
8312 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8314 color
= get_surface_color(rt
, 5, 5);
8315 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
8316 color
= get_surface_color(rt
, 400, 5);
8317 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
8318 color
= get_surface_color(rt
, 5, 245);
8319 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
8320 color
= get_surface_color(rt
, 400, 245);
8321 ok(compare_color(color
, 0x00800000, 2), "Got unexpected color 0x%08x.\n", color
);
8323 IDirect3DTexture2_Release(texture
);
8324 ref
= IDirectDrawSurface_Release(surface
);
8325 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8327 destroy_viewport(device
, viewport
);
8328 ref
= IDirect3DMaterial2_Release(material
);
8329 ok(ref
== 0, "Material not properly released, refcount %u.\n", ref
);
8330 IDirectDrawSurface_Release(rt
);
8331 IDirect3DDevice2_Release(device
);
8332 ref
= IDirectDraw2_Release(ddraw
);
8333 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
8334 DestroyWindow(window
);
8337 static void test_viewport_clear_rect(void)
8340 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8341 static D3DRECT clear_rect2
= {{90}, {90}, {110}, {110}};
8342 IDirectDrawSurface
*rt
;
8344 IDirectDraw2
*ddraw
;
8345 IDirect3DDevice2
*device
;
8346 IDirect3DMaterial2
*red
, *green
;
8347 IDirect3DViewport2
*viewport
, *viewport2
;
8351 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8352 0, 0, 640, 480, 0, 0, 0, 0);
8353 ddraw
= create_ddraw();
8354 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8355 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8357 skip("Failed to create a 3D device, skipping test.\n");
8358 DestroyWindow(window
);
8359 IDirectDraw2_Release(ddraw
);
8363 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8364 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8366 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
8367 viewport
= create_viewport(device
, 0, 0, 640, 480);
8368 viewport_set_background(device
, viewport
, red
);
8369 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8370 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8372 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
8373 viewport2
= create_viewport(device
, 100, 100, 20, 20);
8374 viewport_set_background(device
, viewport2
, green
);
8375 hr
= IDirect3DViewport2_Clear(viewport2
, 1, &clear_rect2
, D3DCLEAR_TARGET
);
8376 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8378 color
= get_surface_color(rt
, 85, 85); /* Outside both. */
8379 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8380 color
= get_surface_color(rt
, 95, 95); /* Outside vp, inside rect. */
8381 /* AMD GPUs ignore the viewport dimensions and only care about the rectangle. */
8382 ok(compare_color(color
, 0x00ff0000, 1) || broken(compare_color(color
, 0x0000ff00, 1)),
8383 "Got unexpected color 0x%08x.\n", color
);
8384 color
= get_surface_color(rt
, 105, 105); /* Inside both. */
8385 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
8386 color
= get_surface_color(rt
, 115, 115); /* Inside vp, outside rect. */
8387 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8388 color
= get_surface_color(rt
, 125, 125); /* Outside both. */
8389 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8391 destroy_viewport(device
, viewport2
);
8392 destroy_material(green
);
8393 destroy_viewport(device
, viewport
);
8394 destroy_material(red
);
8395 IDirectDrawSurface_Release(rt
);
8396 IDirect3DDevice2_Release(device
);
8397 ref
= IDirectDraw2_Release(ddraw
);
8398 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
8399 DestroyWindow(window
);
8402 static void test_color_fill(void)
8405 IDirect3DDevice2
*device
;
8406 IDirectDraw2
*ddraw
;
8407 IDirectDrawSurface
*surface
, *surface2
;
8408 DDSURFACEDESC surface_desc
;
8413 RECT rect
= {5, 5, 7, 7};
8415 DWORD num_fourcc_codes
, *fourcc_codes
;
8417 BOOL support_uyvy
= FALSE
, support_yuy2
= FALSE
;
8421 HRESULT colorfill_hr
, depthfill_hr
;
8426 DDPIXELFORMAT format
;
8431 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8432 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8434 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8435 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8439 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
8440 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8442 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8443 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8447 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
8448 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
8450 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8451 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8455 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
8456 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
8458 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8459 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8463 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
,
8464 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
8465 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
8468 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
8469 * different afterwards. DX9+ GPUs set one of the two luminance values
8470 * in each block, but AMD and Nvidia GPUs disagree on which luminance
8471 * value they set. r200 (dx8) just sets the entire block to the clear
8473 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8474 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
8476 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8477 {0}, {0}, {0}, {0}, {0}
8481 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8482 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
8484 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8485 {0}, {0}, {0}, {0}, {0}
8489 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
8490 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
8492 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8493 {0}, {0}, {0}, {0}, {0}
8497 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
8498 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
8500 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8501 {0}, {0}, {0}, {0}, {0}
8505 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
8506 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
8508 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8509 {0}, {0}, {0}, {0}, {0}
8513 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
8514 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
8516 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8517 {0}, {0}, {0}, {0}, {0}
8521 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
8522 * surface works, presumably because it is handled by the runtime instead of
8524 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8525 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
8527 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
8528 {8}, {0}, {0}, {0}, {0}
8532 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
8533 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
8535 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
8536 {8}, {0}, {0}, {0}, {0}
8548 {SRCCOPY
, "SRCCOPY", DD_OK
},
8549 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
8550 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
8551 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
8552 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
8553 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
8554 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
8555 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
8556 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
8557 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
8558 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
8559 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
8560 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
8561 {BLACKNESS
, "BLACKNESS", DD_OK
},
8562 {WHITENESS
, "WHITENESS", DD_OK
},
8563 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
8566 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8567 0, 0, 640, 480, 0, 0, 0, 0);
8568 ddraw
= create_ddraw();
8569 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8570 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8572 skip("Failed to create a 3D device, skipping test.\n");
8573 DestroyWindow(window
);
8574 IDirectDraw2_Release(ddraw
);
8578 hr
= IDirectDraw2_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
8579 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
8580 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
8581 num_fourcc_codes
* sizeof(*fourcc_codes
));
8584 hr
= IDirectDraw2_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
8585 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
8586 for (i
= 0; i
< num_fourcc_codes
; i
++)
8588 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
8589 support_yuy2
= TRUE
;
8590 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
8591 support_uyvy
= TRUE
;
8593 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
8595 memset(&hal_caps
, 0, sizeof(hal_caps
));
8596 hal_caps
.dwSize
= sizeof(hal_caps
);
8597 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
8598 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
8600 if ((!support_yuy2
&& !support_uyvy
) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
8601 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
8603 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
8605 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
8606 memset(&fx
, 0, sizeof(fx
));
8607 fx
.dwSize
= sizeof(fx
);
8608 U5(fx
).dwFillColor
= 0xdeadbeef;
8610 memset(&surface_desc
, 0, sizeof(surface_desc
));
8611 surface_desc
.dwSize
= sizeof(surface_desc
);
8612 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8613 surface_desc
.dwWidth
= 64;
8614 surface_desc
.dwHeight
= 64;
8615 surface_desc
.ddpfPixelFormat
= tests
[i
].format
;
8616 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
8618 if (tests
[i
].caps
& DDSCAPS_TEXTURE
)
8620 struct format_support_check check
= {&tests
[i
].format
, FALSE
};
8621 hr
= IDirect3DDevice2_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
8622 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
8623 if (!check
.supported
)
8627 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !support_yuy2
)
8629 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !support_uyvy
)
8631 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
8634 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
8636 surface_desc
.dwFlags
&= ~DDSD_PIXELFORMAT
;
8637 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
8638 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
8641 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8642 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8644 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8645 todo_wine_if (tests
[i
].format
.dwFourCC
)
8646 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8647 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8649 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8650 todo_wine_if (tests
[i
].format
.dwFourCC
)
8651 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8652 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8654 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8656 memset(&surface_desc
, 0, sizeof(surface_desc
));
8657 surface_desc
.dwSize
= sizeof(surface_desc
);
8658 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8659 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8660 color
= surface_desc
.lpSurface
;
8661 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
8662 *color
, tests
[i
].result
, tests
[i
].name
);
8663 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8664 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8667 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8668 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8669 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
8670 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8671 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8672 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
8674 U5(fx
).dwFillColor
= 0xdeadbeef;
8675 fx
.dwROP
= BLACKNESS
;
8676 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8677 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
8678 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
8679 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8680 U5(fx
).dwFillColor
, tests
[i
].name
);
8682 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8684 memset(&surface_desc
, 0, sizeof(surface_desc
));
8685 surface_desc
.dwSize
= sizeof(surface_desc
);
8686 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8687 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8688 color
= surface_desc
.lpSurface
;
8689 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
8690 *color
, tests
[i
].name
);
8691 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8692 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8695 fx
.dwROP
= WHITENESS
;
8696 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8697 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
8698 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
8699 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8700 U5(fx
).dwFillColor
, tests
[i
].name
);
8702 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8704 memset(&surface_desc
, 0, sizeof(surface_desc
));
8705 surface_desc
.dwSize
= sizeof(surface_desc
);
8706 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8707 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8708 color
= surface_desc
.lpSurface
;
8709 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
8710 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
8711 *color
, tests
[i
].name
);
8712 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8713 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8716 IDirectDrawSurface_Release(surface
);
8719 memset(&fx
, 0, sizeof(fx
));
8720 fx
.dwSize
= sizeof(fx
);
8721 U5(fx
).dwFillColor
= 0xdeadbeef;
8722 fx
.dwROP
= WHITENESS
;
8724 memset(&surface_desc
, 0, sizeof(surface_desc
));
8725 surface_desc
.dwSize
= sizeof(surface_desc
);
8726 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8727 surface_desc
.dwWidth
= 64;
8728 surface_desc
.dwHeight
= 64;
8729 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
8730 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8731 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8732 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8733 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8734 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8735 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
8736 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8737 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8738 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
8739 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8742 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
8743 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8744 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
8745 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8747 /* Unused source rectangle. */
8748 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8749 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8750 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8751 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8753 /* Unused source surface. */
8754 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8755 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8756 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8757 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8758 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8759 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8760 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8761 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8763 /* Inverted destination or source rectangle. */
8764 SetRect(&rect
, 5, 7, 7, 5);
8765 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8766 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8767 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8768 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8769 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8770 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8771 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8772 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8773 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8774 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8776 /* Negative rectangle. */
8777 SetRect(&rect
, -1, -1, 5, 5);
8778 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8779 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8780 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8781 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8782 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8783 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8784 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8785 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8786 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8787 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8789 /* Out of bounds rectangle. */
8790 SetRect(&rect
, 0, 0, 65, 65);
8791 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8792 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8793 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8794 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8796 /* Combine multiple flags. */
8797 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8798 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8799 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8800 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8801 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8802 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8804 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
8806 fx
.dwROP
= rops
[i
].rop
;
8807 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8808 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
8811 IDirectDrawSurface_Release(surface2
);
8812 IDirectDrawSurface_Release(surface
);
8814 memset(&surface_desc
, 0, sizeof(surface_desc
));
8815 surface_desc
.dwSize
= sizeof(surface_desc
);
8816 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_ZBUFFERBITDEPTH
;
8817 surface_desc
.dwWidth
= 64;
8818 surface_desc
.dwHeight
= 64;
8819 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
8820 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
8821 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8822 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8823 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
8824 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8827 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
8828 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8830 /* Unused source rectangle. */
8831 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8832 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8834 /* Unused source surface. */
8835 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8836 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8837 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8838 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8840 /* Inverted destination or source rectangle. */
8841 SetRect(&rect
, 5, 7, 7, 5);
8842 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8843 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8844 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8845 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8846 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8847 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8848 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8849 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8851 /* Negative rectangle. */
8852 SetRect(&rect
, -1, -1, 5, 5);
8853 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8854 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8855 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8856 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8857 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8858 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8859 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8860 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8862 /* Out of bounds rectangle. */
8863 SetRect(&rect
, 0, 0, 65, 65);
8864 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8865 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8867 /* Combine multiple flags. */
8868 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8869 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8871 IDirectDrawSurface_Release(surface2
);
8872 IDirectDrawSurface_Release(surface
);
8875 IDirect3DDevice2_Release(device
);
8876 refcount
= IDirectDraw2_Release(ddraw
);
8877 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
8878 DestroyWindow(window
);
8881 static void test_colorkey_precision(void)
8883 static D3DLVERTEX quad
[] =
8885 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {0.0f
}, {0.0f
}},
8886 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {0.0f
}, {1.0f
}},
8887 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {1.0f
}, {0.0f
}},
8888 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {1.0f
}, {1.0f
}},
8890 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8891 IDirect3DDevice2
*device
;
8892 IDirectDraw2
*ddraw
;
8893 IDirectDrawSurface
*rt
;
8894 IDirect3DViewport2
*viewport
;
8897 IDirectDrawSurface
*src
, *dst
, *texture
;
8898 D3DTEXTUREHANDLE handle
;
8899 IDirect3DTexture2
*d3d_texture
;
8900 IDirect3DMaterial2
*green
;
8901 DDSURFACEDESC surface_desc
, lock_desc
;
8907 DWORD data
[4] = {0}, color_mask
;
8908 BOOL is_nvidia
, is_warp
;
8911 unsigned int max
, shift
, bpp
, clear
;
8919 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE
,
8921 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8922 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
8927 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE
,
8929 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8930 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
8935 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE
,
8937 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8938 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
8943 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE
,
8945 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8946 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
8951 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8952 0, 0, 640, 480, 0, 0, 0, 0);
8953 ddraw
= create_ddraw();
8954 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8955 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8957 skip("Failed to create a 3D device, skipping test.\n");
8958 DestroyWindow(window
);
8959 IDirectDraw2_Release(ddraw
);
8962 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8963 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8965 is_nvidia
= ddraw_is_nvidia(ddraw
);
8966 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
8967 * (color key doesn't match although the values are equal), and a false
8968 * positive when the color key is 0 and the texture contains the value 1.
8969 * I don't want to mark this broken unconditionally since this would
8970 * essentially disable the test on Windows. Also on random occasions
8971 * 254 == 255 and 255 != 255.*/
8972 is_warp
= ddraw_is_warp(ddraw
);
8974 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
8975 viewport
= create_viewport(device
, 0, 0, 640, 480);
8976 viewport_set_background(device
, viewport
, green
);
8977 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
8978 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
8980 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8981 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
8982 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
8983 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
8984 /* There's no way to ignore the texture color in d3d2, so multiply the texture color
8985 * with a black vertex color. */
8986 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATEALPHA
);
8987 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8989 memset(&fx
, 0, sizeof(fx
));
8990 fx
.dwSize
= sizeof(fx
);
8991 memset(&lock_desc
, 0, sizeof(lock_desc
));
8992 lock_desc
.dwSize
= sizeof(lock_desc
);
8994 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
8996 if (is_nvidia
&& tests
[t
].skip_nv
)
8998 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests
[t
].name
);
9002 memset(&surface_desc
, 0, sizeof(surface_desc
));
9003 surface_desc
.dwSize
= sizeof(surface_desc
);
9004 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9005 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9006 surface_desc
.dwWidth
= 4;
9007 surface_desc
.dwHeight
= 1;
9008 surface_desc
.ddpfPixelFormat
= tests
[t
].fmt
;
9009 /* Windows XP (at least with the r200 driver, other drivers untested) produces
9010 * garbage when doing color keyed texture->texture blits. */
9011 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
9012 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9013 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
9014 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9016 U5(fx
).dwFillColor
= tests
[t
].clear
;
9017 /* On the w8 testbot (WARP driver) the blit result has different values in the
9019 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
9020 | U3(tests
[t
].fmt
).dwGBitMask
9021 | U4(tests
[t
].fmt
).dwBBitMask
;
9023 for (c
= 0; c
<= tests
[t
].max
; ++c
)
9025 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
9026 * texture after it has been set once... */
9027 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
9028 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9029 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9030 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9031 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
9032 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9034 hr
= IDirectDrawSurface4_QueryInterface(texture
, &IID_IDirect3DTexture2
, (void **)&d3d_texture
);
9035 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9036 hr
= IDirect3DTexture2_GetHandle(d3d_texture
, device
, &handle
);
9037 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
9038 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, handle
);
9039 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
9040 IDirect3DTexture2_Release(d3d_texture
);
9042 hr
= IDirectDrawSurface_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9043 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
9045 hr
= IDirectDrawSurface_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9046 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9047 switch (tests
[t
].bpp
)
9050 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9051 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9052 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9053 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
9057 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9058 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9059 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9060 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
9063 hr
= IDirectDrawSurface_Unlock(src
, 0);
9064 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9065 hr
= IDirectDrawSurface_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
9066 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9068 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9069 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9070 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
9071 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9073 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
9074 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9076 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
9077 hr
= IDirectDrawSurface_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9078 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9079 switch (tests
[t
].bpp
)
9082 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9083 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9084 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9085 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
9089 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9090 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9091 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9092 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
9095 hr
= IDirectDrawSurface_Unlock(dst
, 0);
9096 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9100 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9101 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
9103 if (data
[3] == tests
[t
].clear
)
9105 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
9106 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
9107 * even when a different surface is used. The blit itself doesn't draw anything,
9108 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
9109 * never be masked out by the key.
9111 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
9112 * test is disabled entirely.
9114 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
9115 * terrible on WARP. */
9116 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
9117 IDirectDrawSurface_Release(texture
);
9118 IDirectDrawSurface_Release(src
);
9119 IDirectDrawSurface_Release(dst
);
9124 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9125 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
9127 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9128 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
9130 if (c
== tests
[t
].max
)
9131 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9132 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
9134 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9135 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
9137 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
9138 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9140 hr
= IDirect3DDevice2_BeginScene(device
);
9141 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9142 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
9143 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9144 hr
= IDirect3DDevice2_EndScene(device
);
9145 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9147 color
= get_surface_color(rt
, 80, 240);
9149 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9150 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9151 color
, tests
[t
].name
, c
);
9153 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
9154 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9155 color
, tests
[t
].name
, c
);
9157 color
= get_surface_color(rt
, 240, 240);
9158 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9159 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9160 color
, tests
[t
].name
, c
);
9162 color
= get_surface_color(rt
, 400, 240);
9163 if (c
== tests
[t
].max
)
9164 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9165 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9166 color
, tests
[t
].name
, c
);
9168 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
9169 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9170 color
, tests
[t
].name
, c
);
9172 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
9173 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
9174 IDirectDrawSurface_Release(texture
);
9176 IDirectDrawSurface_Release(src
);
9177 IDirectDrawSurface_Release(dst
);
9181 destroy_viewport(device
, viewport
);
9182 destroy_material(green
);
9183 IDirectDrawSurface_Release(rt
);
9184 IDirect3DDevice2_Release(device
);
9185 refcount
= IDirectDraw2_Release(ddraw
);
9186 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
9187 DestroyWindow(window
);
9190 static void test_range_colorkey(void)
9192 IDirectDraw2
*ddraw
;
9195 IDirectDrawSurface
*surface
;
9196 DDSURFACEDESC surface_desc
;
9200 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9201 0, 0, 640, 480, 0, 0, 0, 0);
9202 ddraw
= create_ddraw();
9203 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9204 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9205 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9207 memset(&surface_desc
, 0, sizeof(surface_desc
));
9208 surface_desc
.dwSize
= sizeof(surface_desc
);
9209 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
9210 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9211 surface_desc
.dwWidth
= 1;
9212 surface_desc
.dwHeight
= 1;
9213 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9214 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
9215 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9216 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9217 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9218 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
9220 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
9221 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9222 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
9223 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9224 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9226 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
9227 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9228 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9229 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9231 /* Same for DDSCAPS_OFFSCREENPLAIN. */
9232 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9233 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9234 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
9235 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9236 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9238 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
9239 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9240 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9241 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9243 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9244 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9245 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9246 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9248 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
9249 ckey
.dwColorSpaceLowValue
= 0x00000000;
9250 ckey
.dwColorSpaceHighValue
= 0x00000001;
9251 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9252 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9254 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9255 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9256 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9257 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9259 ckey
.dwColorSpaceLowValue
= 0x00000001;
9260 ckey
.dwColorSpaceHighValue
= 0x00000000;
9261 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9262 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9264 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9265 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9266 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9267 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9269 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
9270 ckey
.dwColorSpaceLowValue
= 0x00000000;
9271 ckey
.dwColorSpaceHighValue
= 0x00000000;
9272 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9273 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9275 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
9276 ckey
.dwColorSpaceLowValue
= 0x00000001;
9277 ckey
.dwColorSpaceHighValue
= 0x00000000;
9278 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9279 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9280 ckey
.dwColorSpaceLowValue
= 0x00000000;
9281 ckey
.dwColorSpaceHighValue
= 0x00000001;
9282 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9283 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9284 /* Range destination keys don't work either. */
9285 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
9286 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9288 /* Just to show it's not because of A, R, and G having equal values. */
9289 ckey
.dwColorSpaceLowValue
= 0x00000000;
9290 ckey
.dwColorSpaceHighValue
= 0x01010101;
9291 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9292 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9294 /* None of these operations modified the key. */
9295 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9296 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9297 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9298 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9300 IDirectDrawSurface_Release(surface
),
9301 refcount
= IDirectDraw2_Release(ddraw
);
9302 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
9303 DestroyWindow(window
);
9306 static void test_shademode(void)
9308 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9309 IDirect3DMaterial2
*background
;
9310 IDirect3DViewport2
*viewport
;
9311 IDirect3DDevice2
*device
;
9312 IDirectDrawSurface
*rt
;
9313 DWORD color0
, color1
;
9314 IDirectDraw2
*ddraw
;
9320 static D3DLVERTEX quad_strip
[] =
9322 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
9323 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9324 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9325 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
9329 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
9330 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9331 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9333 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9334 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9335 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
9341 DWORD color0
, color1
;
9345 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
9346 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
9347 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
9348 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
9349 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
9350 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
9353 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9354 0, 0, 640, 480, 0, 0, 0, 0);
9355 ddraw
= create_ddraw();
9356 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9357 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9359 skip("Failed to create a 3D device, skipping test.\n");
9360 IDirectDraw2_Release(ddraw
);
9361 DestroyWindow(window
);
9365 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9366 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9368 background
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
9369 viewport
= create_viewport(device
, 0, 0, 640, 480);
9370 viewport_set_background(device
, viewport
, background
);
9371 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
9372 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
9374 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
9375 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
9377 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
9378 * the color fixups we have to do for FLAT shading will be dependent on that. */
9380 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
9382 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
9383 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
9385 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
9386 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
9388 hr
= IDirect3DDevice2_BeginScene(device
);
9389 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9390 quad
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? quad_strip
: quad_list
;
9391 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
9392 hr
= IDirect3DDevice2_DrawPrimitive(device
, tests
[i
].primtype
, D3DVT_LVERTEX
, quad
, count
, 0);
9393 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9394 hr
= IDirect3DDevice2_EndScene(device
);
9395 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9397 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
9398 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
9400 /* For D3DSHADE_FLAT it should take the color of the first vertex of
9401 * each triangle. This requires EXT_provoking_vertex or similar
9402 * functionality being available. */
9403 /* PHONG should be the same as GOURAUD, since no hardware implements
9405 ok(compare_color(color0
, tests
[i
].color0
, 1), "Test %u shading has color0 %08x, expected %08x.\n",
9406 i
, color0
, tests
[i
].color0
);
9407 ok(compare_color(color1
, tests
[i
].color1
, 1), "Test %u shading has color1 %08x, expected %08x.\n",
9408 i
, color1
, tests
[i
].color1
);
9411 destroy_viewport(device
, viewport
);
9412 destroy_material(background
);
9413 IDirectDrawSurface_Release(rt
);
9414 refcount
= IDirect3DDevice2_Release(device
);
9415 ok(!refcount
, "Device has %u references left.\n", refcount
);
9416 IDirectDraw_Release(ddraw
);
9417 DestroyWindow(window
);
9420 static void test_lockrect_invalid(void)
9423 IDirectDraw2
*ddraw
;
9424 IDirectDrawSurface
*surface1
;
9425 IDirectDrawSurface2
*surface
;
9428 DDSURFACEDESC surface_desc
;
9430 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
9431 static RECT valid
[] =
9439 static RECT invalid
[] =
9441 {68, 60, 60, 68}, /* left > right */
9442 {60, 68, 68, 60}, /* top > bottom */
9443 {-8, 60, 0, 68}, /* left < surface */
9444 {60, -8, 68, 0}, /* top < surface */
9445 {-16, 60, -8, 68}, /* right < surface */
9446 {60, -16, 68, -8}, /* bottom < surface */
9447 {60, 60, 136, 68}, /* right > surface */
9448 {60, 60, 68, 136}, /* bottom > surface */
9449 {136, 60, 144, 68}, /* left > surface */
9450 {60, 136, 68, 144}, /* top > surface */
9460 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, "sysmem offscreenplain", DDERR_INVALIDPARAMS
},
9461 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, "vidmem offscreenplain", DDERR_INVALIDPARAMS
},
9462 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, "sysmem texture", DDERR_INVALIDPARAMS
},
9463 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, "vidmem texture", DDERR_INVALIDPARAMS
},
9466 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9467 0, 0, 640, 480, 0, 0, 0, 0);
9468 ddraw
= create_ddraw();
9469 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9470 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9471 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9473 memset(&hal_caps
, 0, sizeof(hal_caps
));
9474 hal_caps
.dwSize
= sizeof(hal_caps
);
9475 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
9476 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9477 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
9479 skip("Required surface types not supported, skipping test.\n");
9483 for (r
= 0; r
< sizeof(resources
) / sizeof(*resources
); ++r
)
9485 memset(&surface_desc
, 0, sizeof(surface_desc
));
9486 surface_desc
.dwSize
= sizeof(surface_desc
);
9487 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9488 surface_desc
.ddsCaps
.dwCaps
= resources
[r
].caps
;
9489 surface_desc
.dwWidth
= 128;
9490 surface_desc
.dwHeight
= 128;
9491 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
9492 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9493 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
9494 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xff0000;
9495 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x00ff00;
9496 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x0000ff;
9498 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
9499 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9500 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
9501 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface2 interface, hr %#x.\n", hr
);
9502 IDirectDrawSurface_Release(surface1
);
9504 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, NULL
, DDLOCK_WAIT
, NULL
);
9505 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
9507 for (i
= 0; i
< sizeof(valid
) / sizeof(*valid
); ++i
)
9509 RECT
*rect
= &valid
[i
];
9511 memset(&surface_desc
, 0, sizeof(surface_desc
));
9512 surface_desc
.dwSize
= sizeof(surface_desc
);
9514 hr
= IDirectDrawSurface2_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9515 ok(SUCCEEDED(hr
), "Lock failed (%#x) for rect %s, type %s.\n",
9516 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
9518 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9519 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9522 for (i
= 0; i
< sizeof(invalid
) / sizeof(*invalid
); ++i
)
9524 RECT
*rect
= &invalid
[i
];
9526 memset(&surface_desc
, 1, sizeof(surface_desc
));
9527 surface_desc
.dwSize
= sizeof(surface_desc
);
9529 hr
= IDirectDrawSurface2_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9530 ok(hr
== resources
[r
].hr
, "Lock returned %#x for rect %s, type %s.\n",
9531 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
9534 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9535 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9538 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
9541 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9542 ok(SUCCEEDED(hr
), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
9543 hr
, resources
[r
].name
);
9544 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9545 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned %#x, type %s.\n",
9546 hr
, resources
[r
].name
);
9547 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9548 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9550 hr
= IDirectDrawSurface2_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
9551 ok(SUCCEEDED(hr
), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid
[0]), hr
);
9552 hr
= IDirectDrawSurface2_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
9553 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = %s) failed (%#x).\n",
9554 wine_dbgstr_rect(&valid
[0]), hr
);
9556 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
9557 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
9559 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9560 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9562 IDirectDrawSurface2_Release(surface
);
9566 IDirectDraw2_Release(ddraw
);
9567 DestroyWindow(window
);
9570 static void test_yv12_overlay(void)
9572 IDirectDrawSurface
*src_surface
, *dst_surface
;
9573 RECT rect
= {13, 17, 14, 18};
9574 unsigned int offset
, y
;
9575 unsigned char *base
;
9576 IDirectDraw2
*ddraw
;
9581 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9582 0, 0, 640, 480, 0, 0, 0, 0);
9583 ddraw
= create_ddraw();
9584 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9585 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9586 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9588 if (!(src_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
9590 skip("Failed to create a YV12 overlay, skipping test.\n");
9594 memset(&desc
, 0, sizeof(desc
));
9595 desc
.dwSize
= sizeof(desc
);
9596 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
9597 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9599 ok(desc
.dwFlags
== (DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_PITCH
),
9600 "Got unexpected flags %#x.\n", desc
.dwFlags
);
9601 ok(desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_HWCODEC
)
9602 || desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
9603 "Got unexpected caps %#x.\n", desc
.ddsCaps
.dwCaps
);
9604 ok(desc
.dwWidth
== 256, "Got unexpected width %u.\n", desc
.dwWidth
);
9605 ok(desc
.dwHeight
== 256, "Got unexpected height %u.\n", desc
.dwHeight
);
9606 /* The overlay pitch seems to have 256 byte alignment. */
9607 ok(!(U1(desc
).lPitch
& 0xff), "Got unexpected pitch %u.\n", U1(desc
).lPitch
);
9609 /* Fill the surface with some data for the blit test. */
9610 base
= desc
.lpSurface
;
9612 for (y
= 0; y
< desc
.dwHeight
; ++y
)
9614 memset(base
+ U1(desc
).lPitch
* y
, 0x10, desc
.dwWidth
);
9617 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 4; ++y
)
9619 memset(base
+ U1(desc
).lPitch
* y
, 0x20, desc
.dwWidth
);
9622 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 2; ++y
)
9624 memset(base
+ U1(desc
).lPitch
* y
, 0x30, desc
.dwWidth
);
9627 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
9628 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9630 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
9631 * other block-based formats like DXT the entire Y channel is stored in
9632 * one big chunk of memory, followed by the chroma channels. So partial
9633 * locks do not really make sense. Show that they are allowed nevertheless
9634 * and the offset points into the luminance data. */
9635 hr
= IDirectDrawSurface_Lock(src_surface
, &rect
, &desc
, DDLOCK_WAIT
, NULL
);
9636 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9637 offset
= ((const unsigned char *)desc
.lpSurface
- base
);
9638 ok(offset
== rect
.top
* U1(desc
).lPitch
+ rect
.left
, "Got unexpected offset %u, expected %u.\n",
9639 offset
, rect
.top
* U1(desc
).lPitch
+ rect
.left
);
9640 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
9641 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9643 if (!(dst_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
9645 /* Windows XP with a Radeon X1600 GPU refuses to create a second
9646 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
9647 skip("Failed to create a second YV12 surface, skipping blit test.\n");
9648 IDirectDrawSurface_Release(src_surface
);
9652 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, NULL
, DDBLT_WAIT
, NULL
);
9653 /* VMware rejects YV12 blits. This behavior has not been seen on real
9654 * hardware yet, so mark it broken. */
9655 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
), "Failed to blit, hr %#x.\n", hr
);
9659 memset(&desc
, 0, sizeof(desc
));
9660 desc
.dwSize
= sizeof(desc
);
9661 hr
= IDirectDrawSurface_Lock(dst_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
9662 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9664 base
= desc
.lpSurface
;
9665 ok(base
[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base
[0]);
9666 base
+= desc
.dwHeight
* U1(desc
).lPitch
;
9667 todo_wine
ok(base
[0] == 0x20, "Got unexpected V data 0x%02x.\n", base
[0]);
9668 base
+= desc
.dwHeight
/ 4 * U1(desc
).lPitch
;
9669 todo_wine
ok(base
[0] == 0x30, "Got unexpected U data 0x%02x.\n", base
[0]);
9671 hr
= IDirectDrawSurface_Unlock(dst_surface
, NULL
);
9672 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9675 IDirectDrawSurface_Release(dst_surface
);
9676 IDirectDrawSurface_Release(src_surface
);
9678 IDirectDraw2_Release(ddraw
);
9679 DestroyWindow(window
);
9682 static BOOL
dwm_enabled(void)
9686 if (!strcmp(winetest_platform
, "wine"))
9688 if (!pDwmIsCompositionEnabled
)
9690 if (FAILED(pDwmIsCompositionEnabled(&ret
)))
9695 static void test_offscreen_overlay(void)
9697 IDirectDrawSurface
*overlay
, *offscreen
, *primary
;
9698 DDSURFACEDESC surface_desc
;
9699 IDirectDraw2
*ddraw
;
9704 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9705 0, 0, 640, 480, 0, 0, 0, 0);
9706 ddraw
= create_ddraw();
9707 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9708 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9709 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9711 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
9713 skip("Failed to create a UYVY overlay, skipping test.\n");
9717 memset(&surface_desc
, 0, sizeof(surface_desc
));
9718 surface_desc
.dwSize
= sizeof(surface_desc
);
9719 surface_desc
.dwFlags
= DDSD_CAPS
;
9720 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
9721 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
9722 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9724 /* On Windows 7, and probably Vista, UpdateOverlay() will return
9725 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
9726 * surface prevents this by disabling the dwm. */
9727 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
9728 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
9729 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
9730 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
9732 /* Try to overlay a NULL surface. */
9733 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_SHOW
, NULL
);
9734 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9735 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_HIDE
, NULL
);
9736 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9738 /* Try to overlay an offscreen surface. */
9739 memset(&surface_desc
, 0, sizeof(surface_desc
));
9740 surface_desc
.dwSize
= sizeof(surface_desc
);
9741 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
9742 surface_desc
.dwWidth
= 64;
9743 surface_desc
.dwHeight
= 64;
9744 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9745 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
9746 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9747 surface_desc
.ddpfPixelFormat
.dwFourCC
= 0;
9748 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
9749 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
9750 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
9751 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
9752 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
9753 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9755 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, offscreen
, NULL
, DDOVER_SHOW
, NULL
);
9756 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_OUTOFCAPS
&& dwm_enabled()),
9757 "Failed to update overlay, hr %#x.\n", hr
);
9759 /* Try to overlay the primary with a non-overlay surface. */
9760 hr
= IDirectDrawSurface_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
9761 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
9762 hr
= IDirectDrawSurface_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
9763 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
9765 IDirectDrawSurface_Release(offscreen
);
9766 IDirectDrawSurface_Release(primary
);
9767 IDirectDrawSurface_Release(overlay
);
9769 IDirectDraw2_Release(ddraw
);
9770 DestroyWindow(window
);
9773 static void test_overlay_rect(void)
9775 IDirectDrawSurface
*overlay
, *primary
= NULL
;
9776 DDSURFACEDESC surface_desc
;
9777 RECT rect
= {0, 0, 64, 64};
9778 IDirectDraw2
*ddraw
;
9784 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9785 0, 0, 640, 480, 0, 0, 0, 0);
9786 ddraw
= create_ddraw();
9787 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9788 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9789 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9791 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
9793 skip("Failed to create a UYVY overlay, skipping test.\n");
9797 memset(&surface_desc
, 0, sizeof(surface_desc
));
9798 surface_desc
.dwSize
= sizeof(surface_desc
);
9799 surface_desc
.dwFlags
= DDSD_CAPS
;
9800 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
9801 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
9802 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9804 /* On Windows 7, and probably Vista, UpdateOverlay() will return
9805 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
9806 * surface prevents this by disabling the dwm. */
9807 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
9808 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
9809 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
9810 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
9812 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
9815 win_skip("Cannot disable DWM, skipping overlay test.\n");
9819 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
9820 * used. This is not true in Windows Vista and earlier, but changed in
9822 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
9823 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9824 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
9825 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9826 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
9827 ok(hr
== DD_OK
|| hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9829 /* Show that the overlay position is the (top, left) coordinate of the
9830 * destination rectangle. */
9831 OffsetRect(&rect
, 32, 16);
9832 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
9833 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9834 pos_x
= -1; pos_y
= -1;
9835 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9836 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
9837 ok(pos_x
== rect
.left
, "Got unexpected pos_x %d, expected %d.\n", pos_x
, rect
.left
);
9838 ok(pos_y
== rect
.top
, "Got unexpected pos_y %d, expected %d.\n", pos_y
, rect
.top
);
9840 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
9841 * seen that the overlay overlays the whole primary(==screen). */
9842 hr2
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, 0, NULL
);
9843 ok(hr2
== DD_OK
|| hr2
== DDERR_INVALIDPARAMS
|| hr2
== DDERR_OUTOFCAPS
, "Got unexpected hr %#x.\n", hr2
);
9844 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9845 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
9848 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
9849 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
9853 ok(pos_x
== 32, "Got unexpected pos_x %d.\n", pos_x
);
9854 ok(pos_y
== 16, "Got unexpected pos_y %d.\n", pos_y
);
9857 /* The position cannot be retrieved when the overlay is not shown. */
9858 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_HIDE
, NULL
);
9859 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9860 pos_x
= -1; pos_y
= -1;
9861 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9862 ok(hr
== DDERR_OVERLAYNOTVISIBLE
, "Got unexpected hr %#x.\n", hr
);
9863 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
9864 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
9866 IDirectDrawSurface_Release(overlay
);
9869 IDirectDrawSurface_Release(primary
);
9870 IDirectDraw2_Release(ddraw
);
9871 DestroyWindow(window
);
9874 static void test_blt(void)
9876 IDirectDrawSurface
*surface
, *rt
;
9877 DDSURFACEDESC surface_desc
;
9878 IDirect3DDevice2
*device
;
9879 IDirectDraw2
*ddraw
;
9893 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit. */
9894 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, flipped source. */
9895 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, mirrored source. */
9896 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched x. */
9897 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched y. */
9898 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK
}, /* Full surface blit. */
9899 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT
}, /* Full surface, flipped destination. */
9900 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored destination. */
9901 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, flipped source. */
9902 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored source. */
9905 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9906 0, 0, 640, 480, 0, 0, 0, 0);
9907 ddraw
= create_ddraw();
9908 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9909 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9911 skip("Failed to create a 3D device, skipping test.\n");
9912 IDirectDraw2_Release(ddraw
);
9913 DestroyWindow(window
);
9917 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9918 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9920 memset(&surface_desc
, 0, sizeof(surface_desc
));
9921 surface_desc
.dwSize
= sizeof(surface_desc
);
9922 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
9923 surface_desc
.dwWidth
= 640;
9924 surface_desc
.dwHeight
= 480;
9925 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9926 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9927 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9929 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface
, NULL
, 0, NULL
);
9930 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9932 hr
= IDirectDrawSurface_Blt(surface
, NULL
, rt
, NULL
, 0, NULL
);
9933 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9935 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
9937 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
9938 surface
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
9939 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
9941 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
9942 rt
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
9943 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
9946 IDirectDrawSurface_Release(surface
);
9947 IDirectDrawSurface_Release(rt
);
9948 refcount
= IDirect3DDevice2_Release(device
);
9949 ok(!refcount
, "Device has %u references left.\n", refcount
);
9950 IDirectDraw2_Release(ddraw
);
9951 DestroyWindow(window
);
9954 static void test_getdc(void)
9956 IDirectDrawSurface
*surface
, *surface2
, *tmp
;
9957 DDSURFACEDESC surface_desc
, map_desc
;
9958 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
9959 IDirectDraw2
*ddraw
;
9968 DDPIXELFORMAT format
;
9969 BOOL getdc_supported
;
9974 {"D3DFMT_A8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
9975 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE
},
9976 {"D3DFMT_X8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
9977 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE
},
9978 {"D3DFMT_R5G6B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
9979 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE
},
9980 {"D3DFMT_X1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
9981 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE
},
9982 {"D3DFMT_A1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
9983 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE
},
9984 {"D3DFMT_A4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
9985 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
9986 {"D3DFMT_X4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
9987 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
9988 {"D3DFMT_A2R10G10B10", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
9989 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE
},
9990 {"D3DFMT_A8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
9991 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
9992 {"D3DFMT_X8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
9993 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
9994 {"D3DFMT_R3G3B2", {sizeof(test_data
->format
), DDPF_RGB
, 0, {8},
9995 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE
},
9996 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
9997 * This is not implemented in wine yet, so disable the test for now.
9998 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
9999 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
10000 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
10002 {"D3DFMT_L8", {sizeof(test_data
->format
), DDPF_LUMINANCE
, 0, {8},
10003 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10004 {"D3DFMT_A8L8", {sizeof(test_data
->format
), DDPF_ALPHAPIXELS
| DDPF_LUMINANCE
, 0, {16},
10005 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE
},
10006 {"D3DFMT_DXT1", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','1'), {0},
10007 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10008 {"D3DFMT_DXT2", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','2'), {0},
10009 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10010 {"D3DFMT_DXT3", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','3'), {0},
10011 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10012 {"D3DFMT_DXT4", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','4'), {0},
10013 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10014 {"D3DFMT_DXT5", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','5'), {0},
10015 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10018 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10019 0, 0, 640, 480, 0, 0, 0, 0);
10020 ddraw
= create_ddraw();
10021 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10022 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10023 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10025 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
10027 memset(&surface_desc
, 0, sizeof(surface_desc
));
10028 surface_desc
.dwSize
= sizeof(surface_desc
);
10029 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10030 surface_desc
.dwWidth
= 64;
10031 surface_desc
.dwHeight
= 64;
10032 surface_desc
.ddpfPixelFormat
= test_data
[i
].format
;
10033 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10035 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
10037 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10038 if (FAILED(hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
10040 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data
[i
].name
, hr
);
10045 dc
= (void *)0x1234;
10046 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10047 if (test_data
[i
].getdc_supported
)
10048 ok(SUCCEEDED(hr
) || (test_data
[i
].alt_result
&& hr
== test_data
[i
].alt_result
),
10049 "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10051 ok(FAILED(hr
), "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10055 unsigned int width_bytes
;
10061 type
= GetObjectType(dc
);
10062 ok(type
== OBJ_MEMDC
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
10063 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
10064 type
= GetObjectType(bitmap
);
10065 ok(type
== OBJ_BITMAP
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
10067 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
10068 ok(size
== sizeof(dib
), "Got unexpected size %d for format %s.\n", size
, test_data
[i
].name
);
10069 ok(!dib
.dsBm
.bmType
, "Got unexpected type %#x for format %s.\n",
10070 dib
.dsBm
.bmType
, test_data
[i
].name
);
10071 ok(dib
.dsBm
.bmWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
10072 dib
.dsBm
.bmWidth
, test_data
[i
].name
);
10073 ok(dib
.dsBm
.bmHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
10074 dib
.dsBm
.bmHeight
, test_data
[i
].name
);
10075 width_bytes
= ((dib
.dsBm
.bmWidth
* U1(test_data
[i
].format
).dwRGBBitCount
+ 31) >> 3) & ~3;
10076 ok(dib
.dsBm
.bmWidthBytes
== width_bytes
, "Got unexpected width bytes %d for format %s.\n",
10077 dib
.dsBm
.bmWidthBytes
, test_data
[i
].name
);
10078 ok(dib
.dsBm
.bmPlanes
== 1, "Got unexpected plane count %d for format %s.\n",
10079 dib
.dsBm
.bmPlanes
, test_data
[i
].name
);
10080 ok(dib
.dsBm
.bmBitsPixel
== U1(test_data
[i
].format
).dwRGBBitCount
,
10081 "Got unexpected bit count %d for format %s.\n",
10082 dib
.dsBm
.bmBitsPixel
, test_data
[i
].name
);
10083 ok(!!dib
.dsBm
.bmBits
, "Got unexpected bits %p for format %s.\n",
10084 dib
.dsBm
.bmBits
, test_data
[i
].name
);
10086 ok(dib
.dsBmih
.biSize
== sizeof(dib
.dsBmih
), "Got unexpected size %u for format %s.\n",
10087 dib
.dsBmih
.biSize
, test_data
[i
].name
);
10088 ok(dib
.dsBmih
.biWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
10089 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
10090 ok(dib
.dsBmih
.biHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
10091 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
10092 ok(dib
.dsBmih
.biPlanes
== 1, "Got unexpected plane count %u for format %s.\n",
10093 dib
.dsBmih
.biPlanes
, test_data
[i
].name
);
10094 ok(dib
.dsBmih
.biBitCount
== U1(test_data
[i
].format
).dwRGBBitCount
,
10095 "Got unexpected bit count %u for format %s.\n",
10096 dib
.dsBmih
.biBitCount
, test_data
[i
].name
);
10097 ok(dib
.dsBmih
.biCompression
== (U1(test_data
[i
].format
).dwRGBBitCount
== 16 ? BI_BITFIELDS
: BI_RGB
)
10098 || broken(U1(test_data
[i
].format
).dwRGBBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_BITFIELDS
),
10099 "Got unexpected compression %#x for format %s.\n",
10100 dib
.dsBmih
.biCompression
, test_data
[i
].name
);
10101 ok(!dib
.dsBmih
.biSizeImage
, "Got unexpected image size %u for format %s.\n",
10102 dib
.dsBmih
.biSizeImage
, test_data
[i
].name
);
10103 ok(!dib
.dsBmih
.biXPelsPerMeter
, "Got unexpected horizontal resolution %d for format %s.\n",
10104 dib
.dsBmih
.biXPelsPerMeter
, test_data
[i
].name
);
10105 ok(!dib
.dsBmih
.biYPelsPerMeter
, "Got unexpected vertical resolution %d for format %s.\n",
10106 dib
.dsBmih
.biYPelsPerMeter
, test_data
[i
].name
);
10107 ok(!dib
.dsBmih
.biClrUsed
, "Got unexpected used colour count %u for format %s.\n",
10108 dib
.dsBmih
.biClrUsed
, test_data
[i
].name
);
10109 ok(!dib
.dsBmih
.biClrImportant
, "Got unexpected important colour count %u for format %s.\n",
10110 dib
.dsBmih
.biClrImportant
, test_data
[i
].name
);
10112 if (dib
.dsBmih
.biCompression
== BI_BITFIELDS
)
10114 ok((dib
.dsBitfields
[0] == U2(test_data
[i
].format
).dwRBitMask
10115 && dib
.dsBitfields
[1] == U3(test_data
[i
].format
).dwGBitMask
10116 && dib
.dsBitfields
[2] == U4(test_data
[i
].format
).dwBBitMask
)
10117 || broken(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2]),
10118 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
10119 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
10123 ok(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2],
10124 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
10125 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
10127 ok(!dib
.dshSection
, "Got unexpected section %p for format %s.\n", dib
.dshSection
, test_data
[i
].name
);
10128 ok(!dib
.dsOffset
, "Got unexpected offset %u for format %s.\n", dib
.dsOffset
, test_data
[i
].name
);
10130 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10131 ok(hr
== DD_OK
, "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10135 ok(!dc
, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
10138 IDirectDrawSurface_Release(surface
);
10143 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
10144 if (FAILED(hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
10146 skip("Failed to create mip-mapped texture for format %s (hr %#x), skipping tests.\n",
10147 test_data
[i
].name
, hr
);
10151 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
10152 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10153 hr
= IDirectDrawSurface_GetAttachedSurface(tmp
, &caps
, &surface2
);
10154 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10155 IDirectDrawSurface_Release(tmp
);
10157 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10158 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10159 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10160 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10161 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10162 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10163 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10164 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10166 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10167 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10168 dc2
= (void *)0x1234;
10169 hr
= IDirectDrawSurface_GetDC(surface
, &dc2
);
10170 ok(hr
== DDERR_DCALREADYCREATED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10171 ok(dc2
== (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
10172 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10173 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10174 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10175 ok(hr
== DDERR_NODC
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10177 map_desc
.dwSize
= sizeof(map_desc
);
10178 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10179 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10180 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10181 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10182 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10183 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10184 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10185 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10187 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10188 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10189 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10190 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10191 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10192 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10194 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10195 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
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_Unlock(surface
, NULL
);
10201 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10203 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10204 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10205 hr
= IDirectDrawSurface_GetDC(surface2
, &dc2
);
10206 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10207 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc2
);
10208 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10209 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10210 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10212 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10213 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10214 hr
= IDirectDrawSurface_GetDC(surface
, &dc2
);
10215 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10216 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc2
);
10217 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10218 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10219 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10221 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10222 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10223 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10224 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10225 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10226 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10227 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10228 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10230 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10231 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10232 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10233 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10234 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10235 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10236 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10237 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10239 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10240 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10241 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10242 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10243 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10244 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10245 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10246 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10248 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10249 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10250 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10251 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10252 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10253 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10254 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10255 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10257 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10258 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10259 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10260 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10261 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10262 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10263 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10264 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10266 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10267 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10268 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10269 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10270 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10271 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10272 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10273 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10274 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10275 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10277 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10278 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10279 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10280 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10281 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10282 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10283 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10284 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10285 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10286 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10288 IDirectDrawSurface_Release(surface2
);
10289 IDirectDrawSurface_Release(surface
);
10292 IDirectDraw2_Release(ddraw
);
10293 DestroyWindow(window
);
10296 static void test_draw_primitive(void)
10298 static WORD indices
[] = {0, 1, 2, 3};
10299 static D3DVERTEX quad
[] =
10301 {{-1.0f
}, {-1.0f
}, {0.0f
}},
10302 {{-1.0f
}, { 1.0f
}, {0.0f
}},
10303 {{ 1.0f
}, {-1.0f
}, {0.0f
}},
10304 {{ 1.0f
}, { 1.0f
}, {0.0f
}},
10306 IDirect3DViewport2
*viewport
;
10307 IDirect3DDevice2
*device
;
10308 IDirectDraw2
*ddraw
;
10314 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10315 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
10316 ddraw
= create_ddraw();
10317 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10318 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10320 skip("Failed to create a 3D device, skipping test.\n");
10321 IDirectDraw2_Release(ddraw
);
10322 DestroyWindow(window
);
10326 viewport
= create_viewport(device
, 0, 0, 640, 480);
10327 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
10328 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10330 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
10331 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
10333 IDirect3D2_Release(d3d
);
10335 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, NULL
, 0, 0);
10336 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10337 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, 0);
10338 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10340 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, indices
, 4, 0);
10341 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10343 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, NULL
, 0, 0);
10344 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10345 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, 0);
10346 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10347 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, indices
, 4, 0);
10348 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10350 destroy_viewport(device
, viewport
);
10351 refcount
= IDirect3DDevice2_Release(device
);
10352 ok(!refcount
, "Device has %u references left.\n", refcount
);
10353 IDirectDraw2_Release(ddraw
);
10354 DestroyWindow(window
);
10357 static void test_edge_antialiasing_blending(void)
10359 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10360 IDirect3DMaterial2
*green_background
;
10361 IDirect3DMaterial2
*red_background
;
10362 IDirectDrawSurface
*offscreen
, *ds
;
10363 D3DDEVICEDESC hal_desc
, hel_desc
;
10364 IDirect3DViewport2
*viewport
;
10365 DDSURFACEDESC surface_desc
;
10366 IDirect3DDevice2
*device
;
10367 IDirectDraw2
*ddraw
;
10373 static D3DMATRIX mat
=
10375 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10376 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10377 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10378 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10380 static D3DLVERTEX green_quad
[] =
10382 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10383 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10384 {{ 1.0f
}, {-1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10385 {{ 1.0f
}, { 1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10387 static D3DLVERTEX red_quad
[] =
10389 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xccff0000}},
10390 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xccff0000}},
10391 {{ 1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xccff0000}},
10392 {{ 1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xccff0000}},
10395 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10396 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
10397 ddraw
= create_ddraw();
10398 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10399 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10401 skip("Failed to create a 3D device.\n");
10402 DestroyWindow(window
);
10406 memset(&hal_desc
, 0, sizeof(hal_desc
));
10407 hal_desc
.dwSize
= sizeof(hal_desc
);
10408 memset(&hel_desc
, 0, sizeof(hel_desc
));
10409 hel_desc
.dwSize
= sizeof(hel_desc
);
10410 hr
= IDirect3DDevice2_GetCaps(device
, &hal_desc
, &hel_desc
);
10411 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
10412 trace("HAL line edge antialiasing support: %#x.\n",
10413 hal_desc
.dpcLineCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10414 trace("HAL triangle edge antialiasing support: %#x.\n",
10415 hal_desc
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10416 trace("HEL line edge antialiasing support: %#x.\n",
10417 hel_desc
.dpcLineCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10418 trace("HEL triangle edge antialiasing support: %#x.\n",
10419 hel_desc
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10421 memset(&surface_desc
, 0, sizeof(surface_desc
));
10422 surface_desc
.dwSize
= sizeof(surface_desc
);
10423 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
10424 surface_desc
.dwWidth
= 640;
10425 surface_desc
.dwHeight
= 480;
10426 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
10427 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
10428 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
10429 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
10430 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10431 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10432 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10433 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
10434 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
10435 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr %#x.\n", hr
);
10437 ds
= get_depth_stencil(device
);
10438 hr
= IDirectDrawSurface_AddAttachedSurface(offscreen
, ds
);
10439 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
10440 IDirectDrawSurface_Release(ds
);
10442 hr
= IDirect3DDevice2_SetRenderTarget(device
, offscreen
, 0);
10443 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
10445 red_background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 0.8f
);
10446 green_background
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.5f
);
10448 viewport
= create_viewport(device
, 0, 0, 640, 480);
10449 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
10450 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10452 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
10453 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
10454 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
10455 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
10456 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
10457 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
10458 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
10459 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
10460 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
10461 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
10462 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10463 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10464 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
10465 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
10466 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
10467 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
10468 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10469 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
10471 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
10472 ok(SUCCEEDED(hr
), "Failed to enable blending, hr %#x.\n", hr
);
10473 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
10474 ok(SUCCEEDED(hr
), "Failed to set src blend, hr %#x.\n", hr
);
10475 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_DESTALPHA
);
10476 ok(SUCCEEDED(hr
), "Failed to set dest blend, hr %#x.\n", hr
);
10478 viewport_set_background(device
, viewport
, red_background
);
10479 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10480 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10481 hr
= IDirect3DDevice2_BeginScene(device
);
10482 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10483 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10484 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10485 hr
= IDirect3DDevice2_EndScene(device
);
10486 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10487 color
= get_surface_color(offscreen
, 320, 240);
10488 ok(compare_color(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
10490 viewport_set_background(device
, viewport
, green_background
);
10491 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10492 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10493 hr
= IDirect3DDevice2_BeginScene(device
);
10494 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10495 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, red_quad
, 4, 0);
10496 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10497 hr
= IDirect3DDevice2_EndScene(device
);
10498 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10499 color
= get_surface_color(offscreen
, 320, 240);
10500 ok(compare_color(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
10502 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
10503 ok(SUCCEEDED(hr
), "Failed to disable blending, hr %#x.\n", hr
);
10505 viewport_set_background(device
, viewport
, red_background
);
10506 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10507 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10508 hr
= IDirect3DDevice2_BeginScene(device
);
10509 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10510 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10511 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10512 hr
= IDirect3DDevice2_EndScene(device
);
10513 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10514 color
= get_surface_color(offscreen
, 320, 240);
10515 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
10517 viewport_set_background(device
, viewport
, green_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
, red_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
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
10529 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_EDGEANTIALIAS
, TRUE
);
10530 ok(SUCCEEDED(hr
), "Failed to enable edge antialiasing, hr %#x.\n", hr
);
10532 viewport_set_background(device
, viewport
, red_background
);
10533 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10534 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10535 hr
= IDirect3DDevice2_BeginScene(device
);
10536 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10537 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10538 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10539 hr
= IDirect3DDevice2_EndScene(device
);
10540 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10541 color
= get_surface_color(offscreen
, 320, 240);
10542 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
10544 viewport_set_background(device
, viewport
, green_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
, red_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
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
10556 IDirectDrawSurface_Release(offscreen
);
10557 destroy_viewport(device
, viewport
);
10558 destroy_material(red_background
);
10559 destroy_material(green_background
);
10560 refcount
= IDirect3DDevice2_Release(device
);
10561 ok(!refcount
, "Device has %u references left.\n", refcount
);
10562 IDirectDraw2_Release(ddraw
);
10563 DestroyWindow(window
);
10566 /* TransformVertices always writes 32 bytes regardless of the input / output stride.
10567 * The stride is honored for navigating to the next vertex. 3 floats input position
10568 * are read, and 16 bytes extra vertex data are copied around. */
10569 struct transform_input
10571 float x
, y
, z
, unused1
; /* Position data, transformed. */
10572 DWORD v1
, v2
, v3
, v4
; /* Extra data, e.g. color and texture coords, copied. */
10576 struct transform_output
10579 DWORD v1
, v2
, v3
, v4
;
10580 DWORD unused3
, unused4
;
10583 static void test_transform_vertices(void)
10585 IDirect3DDevice2
*device
;
10586 IDirectDrawSurface
*rt
;
10587 IDirectDraw2
*ddraw
;
10592 IDirect3DViewport2
*viewport
;
10593 IDirect3DMaterial2
*background
;
10595 static struct transform_input position_tests
[] =
10597 { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
10598 { 1.0f
, 1.0f
, 1.0f
, 8.0f
, 6, 7, 8, 9, 10},
10599 {-1.0f
, -1.0f
, -1.0f
, 4.0f
, 11, 12, 13, 14, 15},
10600 { 0.5f
, 0.5f
, 0.5f
, 2.0f
, 16, 17, 18, 19, 20},
10601 {-0.5f
, -0.5f
, -0.5f
, 1.0f
, ~1U, ~2U, ~3U, ~4U, ~5U},
10602 {-0.5f
, -0.5f
, 0.0f
, 0.0f
, ~6U, ~7U, ~8U, ~9U, ~0U},
10604 static struct transform_input cliptest
[] =
10606 { 25.59f
, 25.59f
, 1.0f
, 0.0f
, 1, 2, 3, 4, 5},
10607 { 25.61f
, 25.61f
, 1.01f
, 0.0f
, 1, 2, 3, 4, 5},
10608 {-25.59f
, -25.59f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
10609 {-25.61f
, -25.61f
, -0.01f
, 0.0f
, 1, 2, 3, 4, 5},
10611 static struct transform_input offscreentest
[] =
10613 {128.1f
, 0.0f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
10615 struct transform_output out
[ARRAY_SIZE(position_tests
)];
10616 D3DHVERTEX out_h
[ARRAY_SIZE(position_tests
)];
10617 D3DTRANSFORMDATA transformdata
;
10618 static const D3DVIEWPORT vp_template
=
10620 sizeof(vp_template
), 0, 0, 256, 256, 5.0f
, 5.0f
, 256.0f
, 256.0f
, -25.0f
, 60.0f
10622 D3DVIEWPORT vp_data
=
10624 sizeof(vp_data
), 0, 0, 256, 256, 1.0f
, 1.0f
, 256.0f
, 256.0f
, 0.0f
, 1.0f
10626 D3DVIEWPORT2 vp2_data
;
10629 static D3DMATRIX mat_scale
=
10631 2.0f
, 0.0f
, 0.0f
, 0.0f
,
10632 0.0f
, 2.0f
, 0.0f
, 0.0f
,
10633 0.0f
, 0.0f
, 2.0f
, 0.0f
,
10634 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10638 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10639 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10640 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10641 1.0f
, 0.0f
, 0.0f
, 1.0f
,
10645 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10646 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10647 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10648 0.0f
, 1.0f
, 0.0f
, 1.0f
,
10652 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10653 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10654 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10655 0.0f
, 19.2f
, 0.0f
, 2.0f
,
10659 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10660 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10661 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10662 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10664 static D3DLVERTEX quad
[] =
10666 {{-0.75f
},{-0.5f
}, {0.0f
}, 0, {0xffff0000}},
10667 {{-0.75f
},{ 0.25f
}, {0.0f
}, 0, {0xffff0000}},
10668 {{ 0.5f
}, {-0.5f
}, {0.0f
}, 0, {0xffff0000}},
10669 {{ 0.5f
}, { 0.25f
}, {0.0f
}, 0, {0xffff0000}},
10671 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10674 for (i
= 0; i
< ARRAY_SIZE(out
); ++i
)
10676 out
[i
].unused3
= 0xdeadbeef;
10677 out
[i
].unused4
= 0xcafecafe;
10680 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10681 0, 0, 640, 480, 0, 0, 0, 0);
10682 ddraw
= create_ddraw();
10683 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10684 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10686 skip("Failed to create a 3D device, skipping test.\n");
10687 IDirectDraw2_Release(ddraw
);
10688 DestroyWindow(window
);
10691 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
10692 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10694 viewport
= create_viewport(device
, 0, 0, 256, 256);
10695 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10696 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10698 memset(&transformdata
, 0, sizeof(transformdata
));
10699 transformdata
.dwSize
= sizeof(transformdata
);
10700 transformdata
.lpIn
= position_tests
;
10701 transformdata
.dwInSize
= sizeof(position_tests
[0]);
10702 transformdata
.lpOut
= out
;
10703 transformdata
.dwOutSize
= sizeof(out
[0]);
10704 transformdata
.lpHOut
= NULL
;
10706 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10707 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10708 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10709 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10711 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10713 static const struct vec4 cmp
[] =
10715 {128.0f
, 128.0f
, 0.0f
, 1.0f
}, {129.0f
, 127.0f
, 1.0f
, 1.0f
}, {127.0f
, 129.0f
, -1.0f
, 1.0f
},
10716 {128.5f
, 127.5f
, 0.5f
, 1.0f
}, {127.5f
, 128.5f
, -0.5f
, 1.0f
}, {127.5f
, 128.5f
, 0.0f
, 1.0f
}
10719 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10720 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10721 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10722 ok(out
[i
].v1
== position_tests
[i
].v1
&& out
[i
].v2
== position_tests
[i
].v2
10723 && out
[i
].v3
== position_tests
[i
].v3
&& out
[i
].v4
== position_tests
[i
].v4
,
10724 "Vertex %u payload is %u %u %u %u.\n", i
, out
[i
].v1
, out
[i
].v2
, out
[i
].v3
, out
[i
].v4
);
10725 ok(out
[i
].unused3
== 0xdeadbeef && out
[i
].unused4
== 0xcafecafe,
10726 "Vertex %u unused data is %#x, %#x.\n", i
, out
[i
].unused3
, out
[i
].unused4
);
10729 vp_data
= vp_template
;
10730 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10731 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10732 offscreen
= 0xdeadbeef;
10733 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10734 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10735 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10736 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10738 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10740 static const struct vec4 cmp
[] =
10742 {128.0f
, 128.0f
, 0.0f
, 1.0f
}, {133.0f
, 123.0f
, 1.0f
, 1.0f
}, {123.0f
, 133.0f
, -1.0f
, 1.0f
},
10743 {130.5f
, 125.5f
, 0.5f
, 1.0f
}, {125.5f
, 130.5f
, -0.5f
, 1.0f
}, {125.5f
, 130.5f
, 0.0f
, 1.0f
}
10745 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10746 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10747 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10752 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10753 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10754 offscreen
= 0xdeadbeef;
10755 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10756 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10757 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10758 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10759 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10761 static const struct vec4 cmp
[] =
10763 {138.0f
, 148.0f
, 0.0f
, 1.0f
}, {143.0f
, 143.0f
, 1.0f
, 1.0f
}, {133.0f
, 153.0f
, -1.0f
, 1.0f
},
10764 {140.5f
, 145.5f
, 0.5f
, 1.0f
}, {135.5f
, 150.5f
, -0.5f
, 1.0f
}, {135.5f
, 150.5f
, 0.0f
, 1.0f
}
10766 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10767 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10768 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10771 transformdata
.lpHOut
= out_h
;
10772 offscreen
= 0xdeadbeef;
10773 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10774 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10775 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10776 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10777 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10779 static const D3DHVERTEX cmp_h
[] =
10781 {0, { 0.0f
}, { 0.0f
}, { 0.0f
}}, {0, { 1.0f
}, { 1.0f
}, {1.0f
}},
10782 {D3DCLIP_FRONT
, {-1.0f
}, {-1.0f
}, {-1.0f
}}, {0, { 0.5f
}, { 0.5f
}, {0.5f
}},
10783 {D3DCLIP_FRONT
, {-0.5f
}, {-0.5f
}, {-0.5f
}}, {0, {-0.5f
}, {-0.5f
}, {0.0f
}}
10785 ok(compare_float(U1(cmp_h
[i
]).hx
, U1(out_h
[i
]).hx
, 4096)
10786 && compare_float(U2(cmp_h
[i
]).hy
, U2(out_h
[i
]).hy
, 4096)
10787 && compare_float(U3(cmp_h
[i
]).hz
, U3(out_h
[i
]).hz
, 4096)
10788 && cmp_h
[i
].dwFlags
== out_h
[i
].dwFlags
,
10789 "HVertex %u differs. Got %#x %f %f %f.\n", i
,
10790 out_h
[i
].dwFlags
, U1(out_h
[i
]).hx
, U2(out_h
[i
]).hy
, U3(out_h
[i
]).hz
);
10792 /* No scheme has been found behind those return values. It seems to be
10793 * whatever data windows has when throwing the vertex away. Modify the
10794 * input test vertices to test this more. Depending on the input data
10795 * it can happen that the z coord gets written into y, or similar things. */
10798 static const struct vec4 cmp
[] =
10800 {138.0f
, 148.0f
, 0.0f
, 1.0f
}, {143.0f
, 143.0f
, 1.0f
, 1.0f
}, { -1.0f
, -1.0f
, 0.5f
, 1.0f
},
10801 {140.5f
, 145.5f
, 0.5f
, 1.0f
}, { -0.5f
, -0.5f
, -0.5f
, 1.0f
}, {135.5f
, 150.5f
, 0.0f
, 1.0f
}
10803 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10804 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10805 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10809 transformdata
.lpIn
= cliptest
;
10810 transformdata
.dwInSize
= sizeof(cliptest
[0]);
10811 offscreen
= 0xdeadbeef;
10812 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
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(cliptest
); ++i
)
10818 static const DWORD flags
[] =
10821 D3DCLIP_RIGHT
| D3DCLIP_BACK
| D3DCLIP_TOP
,
10823 D3DCLIP_LEFT
| D3DCLIP_BOTTOM
| D3DCLIP_FRONT
,
10825 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
10828 vp_data
= vp_template
;
10829 vp_data
.dwWidth
= 10;
10830 vp_data
.dwHeight
= 480;
10831 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10832 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10833 offscreen
= 0xdeadbeef;
10834 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
10835 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10836 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10837 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10838 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
10840 static const DWORD flags
[] =
10843 D3DCLIP_RIGHT
| D3DCLIP_BACK
,
10845 D3DCLIP_LEFT
| D3DCLIP_FRONT
,
10847 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
10850 vp_data
= vp_template
;
10851 vp_data
.dwWidth
= 256;
10852 vp_data
.dwHeight
= 256;
10853 vp_data
.dvScaleX
= 1;
10854 vp_data
.dvScaleY
= 1;
10855 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10856 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10857 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
10858 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10859 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10860 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10861 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
10863 static const DWORD flags
[] =
10870 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
10873 /* Finally try to figure out how the DWORD dwOffscreen works.
10874 * It is a logical AND of the vertices' dwFlags members. */
10875 vp_data
= vp_template
;
10876 vp_data
.dwWidth
= 5;
10877 vp_data
.dwHeight
= 5;
10878 vp_data
.dvScaleX
= 10000.0f
;
10879 vp_data
.dvScaleY
= 10000.0f
;
10880 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10881 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10882 transformdata
.lpIn
= cliptest
;
10883 offscreen
= 0xdeadbeef;
10884 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10885 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10886 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10887 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10889 offscreen
= 0xdeadbeef;
10890 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10891 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10892 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10893 ok(offscreen
== (D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
10894 offscreen
= 0xdeadbeef;
10895 hr
= IDirect3DViewport2_TransformVertices(viewport
, 2,
10896 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10897 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10898 ok(offscreen
== (D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
10899 hr
= IDirect3DViewport2_TransformVertices(viewport
, 3,
10900 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10901 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10902 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10904 transformdata
.lpIn
= cliptest
+ 1;
10905 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10906 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10907 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10908 ok(offscreen
== (D3DCLIP_BACK
| D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
10910 transformdata
.lpIn
= cliptest
+ 2;
10911 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10912 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10913 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10914 ok(offscreen
== (D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
10915 offscreen
= 0xdeadbeef;
10916 hr
= IDirect3DViewport2_TransformVertices(viewport
, 2,
10917 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10918 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10919 ok(offscreen
== (D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
10921 transformdata
.lpIn
= cliptest
+ 3;
10922 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10923 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10924 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10925 ok(offscreen
== (D3DCLIP_FRONT
| D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
10927 transformdata
.lpIn
= offscreentest
;
10928 transformdata
.dwInSize
= sizeof(offscreentest
[0]);
10929 vp_data
= vp_template
;
10930 vp_data
.dwWidth
= 257;
10931 vp_data
.dwHeight
= 257;
10932 vp_data
.dvScaleX
= 1.0f
;
10933 vp_data
.dvScaleY
= 1.0f
;
10934 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10935 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10936 offscreen
= 0xdeadbeef;
10937 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10938 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10939 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10940 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10942 vp_data
.dwWidth
= 256;
10943 vp_data
.dwHeight
= 256;
10944 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10945 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10946 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
10947 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10948 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10949 ok(offscreen
== D3DCLIP_RIGHT
, "Offscreen is %x.\n", offscreen
);
10951 /* Test the effect of Matrices.
10953 * Basically the x coordinate ends up as ((x + 1) * 2 + 0) * 5 and
10954 * y as ((y + 0) * 2 + 1) * 5. The 5 comes from dvScaleX/Y, 2 from
10955 * the view matrix and the +1's from the world and projection matrix. */
10958 vp_data
.dwWidth
= 256;
10959 vp_data
.dwHeight
= 256;
10960 vp_data
.dvScaleX
= 5.0f
;
10961 vp_data
.dvScaleY
= 5.0f
;
10962 vp_data
.dvMinZ
= 0.0f
;
10963 vp_data
.dvMaxZ
= 1.0f
;
10964 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10965 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10967 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat_translate1
);
10968 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
10969 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat_scale
);
10970 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
10971 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat_translate2
);
10972 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
10974 transformdata
.lpIn
= position_tests
;
10975 transformdata
.dwInSize
= sizeof(position_tests
[0]);
10976 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10977 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10978 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10980 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10982 static const struct vec4 cmp
[] =
10984 {138.0f
, 123.0f
, 0.0f
, 1.0f
}, {148.0f
, 113.0f
, 2.0f
, 1.0f
}, {128.0f
, 133.0f
, -2.0f
, 1.0f
},
10985 {143.0f
, 118.0f
, 1.0f
, 1.0f
}, {133.0f
, 128.0f
, -1.0f
, 1.0f
}, {133.0f
, 128.0f
, 0.0f
, 1.0f
}
10988 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10989 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10990 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10993 /* Invalid flags. */
10994 offscreen
= 0xdeadbeef;
10995 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10996 &transformdata
, 0, &offscreen
);
10997 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
10998 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11000 /* NULL transform data. */
11001 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11002 NULL
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11003 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11004 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11005 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11006 NULL
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11007 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11008 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11010 /* NULL transform data and NULL dwOffscreen.
11012 * Valid transform data + NULL dwOffscreen -> crash. */
11013 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11014 NULL
, D3DTRANSFORM_UNCLIPPED
, NULL
);
11015 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11018 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11019 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11020 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11021 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
11022 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11023 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11024 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11025 ok(offscreen
== ~0U, "Offscreen is %x.\n", offscreen
);
11027 /* Invalid sizes. */
11028 offscreen
= 0xdeadbeef;
11029 transformdata
.dwSize
= sizeof(transformdata
) - 1;
11030 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11031 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11032 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11033 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11034 transformdata
.dwSize
= sizeof(transformdata
) + 1;
11035 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11036 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11037 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11038 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11040 /* NULL lpIn or lpOut -> crash, except when transforming 0 vertices. */
11041 transformdata
.dwSize
= sizeof(transformdata
);
11042 transformdata
.lpIn
= NULL
;
11043 transformdata
.lpOut
= NULL
;
11044 offscreen
= 0xdeadbeef;
11045 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11046 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11047 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11048 ok(offscreen
== ~0U, "Offscreen is %x.\n", offscreen
);
11050 /* Test how vertices are transformed during draws. */
11053 vp_data
.dwWidth
= 200;
11054 vp_data
.dwHeight
= 400;
11055 vp_data
.dvScaleX
= 20.0f
;
11056 vp_data
.dvScaleY
= 50.0f
;
11057 vp_data
.dvMinZ
= 0.0f
;
11058 vp_data
.dvMaxZ
= 1.0f
;
11059 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
11060 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
11061 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
11062 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
11064 ok(SUCCEEDED(hr
), "Failed to clear the render target, hr %#x.\n", hr
);
11065 background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 0.0f
);
11066 viewport_set_background(device
, viewport
, background
);
11067 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
11068 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
11070 hr
= IDirect3DDevice2_BeginScene(device
);
11071 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11072 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
11073 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11074 hr
= IDirect3DDevice2_EndScene(device
);
11075 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11077 color
= get_surface_color(rt
, 128, 143);
11078 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11079 color
= get_surface_color(rt
, 132, 143);
11080 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11081 color
= get_surface_color(rt
, 128, 147);
11082 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11083 color
= get_surface_color(rt
, 132, 147);
11084 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11086 color
= get_surface_color(rt
, 177, 217);
11087 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11088 color
= get_surface_color(rt
, 181, 217);
11089 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11090 color
= get_surface_color(rt
, 177, 221);
11091 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11092 color
= get_surface_color(rt
, 181, 221);
11093 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11095 /* Test D3DVIEWPORT2 behavior. */
11096 vp2_data
.dwSize
= sizeof(vp2_data
);
11099 vp2_data
.dwWidth
= 200;
11100 vp2_data
.dwHeight
= 400;
11101 vp2_data
.dvClipX
= -0.5f
;
11102 vp2_data
.dvClipY
= 4.0f
;
11103 vp2_data
.dvClipWidth
= 5.0f
;
11104 vp2_data
.dvClipHeight
= 10.0f
;
11105 vp2_data
.dvMinZ
= 0.0f
;
11106 vp2_data
.dvMaxZ
= 2.0f
;
11107 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp2_data
);
11108 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
11109 transformdata
.lpIn
= position_tests
;
11110 transformdata
.lpOut
= out
;
11111 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
11112 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11113 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11114 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
11116 static const struct vec4 cmp
[] =
11118 {120.0f
, 140.0f
, 0.0f
, 1.0f
}, {200.0f
, 60.0f
, 1.0f
, 1.0f
}, {40.0f
, 220.0f
, -1.0f
, 1.0f
},
11119 {160.0f
, 100.0f
, 0.5f
, 1.0f
}, { 80.0f
, 180.0f
, -0.5f
, 1.0f
}, {80.0f
, 180.0f
, 0.0f
, 1.0f
}
11122 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
11123 "Vertex %u differs. Got %f %f %f %f.\n", i
,
11124 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
11127 memset(&mat
, 0, sizeof(mat
));
11128 mat
.dwSize
= sizeof(mat
);
11129 U1(U(mat
).diffuse
).r
= 0.0f
;
11130 U2(U(mat
).diffuse
).g
= 1.0f
;
11131 U3(U(mat
).diffuse
).b
= 0.0f
;
11132 U4(U(mat
).diffuse
).a
= 0.0f
;
11133 hr
= IDirect3DMaterial2_SetMaterial(background
, &mat
);
11134 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
11135 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
11136 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
11138 hr
= IDirect3DDevice2_BeginScene(device
);
11139 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11140 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
11141 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11142 hr
= IDirect3DDevice2_EndScene(device
);
11143 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11145 color
= get_surface_color(rt
, 58, 118);
11146 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11147 color
= get_surface_color(rt
, 62, 118);
11148 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11149 color
= get_surface_color(rt
, 58, 122);
11150 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11151 color
= get_surface_color(rt
, 62, 122);
11152 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11154 color
= get_surface_color(rt
, 157, 177);
11155 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11156 color
= get_surface_color(rt
, 161, 177);
11157 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11158 color
= get_surface_color(rt
, 157, 181);
11159 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11160 color
= get_surface_color(rt
, 161, 181);
11161 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11163 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat_identity
);
11164 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11165 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat_identity
);
11166 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11167 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat_transform3
);
11168 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11170 vp2_data
.dwX
= 0.0;
11171 vp2_data
.dwY
= 0.0;
11172 vp2_data
.dwWidth
= 1;
11173 vp2_data
.dwHeight
= 1;
11174 vp2_data
.dvClipX
= -12.8f
;
11175 vp2_data
.dvClipY
= 12.8f
+ mat_transform3
._42
/ mat_transform3
._44
;
11176 vp2_data
.dvClipWidth
= 25.6f
;
11177 vp2_data
.dvClipHeight
= 25.6f
;
11178 vp2_data
.dvMinZ
= 0.0f
;
11179 vp2_data
.dvMaxZ
= 0.5f
;
11180 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp2_data
);
11181 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
11182 transformdata
.lpIn
= cliptest
;
11183 transformdata
.dwInSize
= sizeof(cliptest
[0]);
11184 offscreen
= 0xdeadbeef;
11185 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
11186 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11187 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11188 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
11189 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
11191 static const D3DHVERTEX cmp_h
[] =
11193 {0, { 25.59f
}, { 44.79f
}, { 1.0f
}},
11194 {D3DCLIP_RIGHT
| D3DCLIP_TOP
| D3DCLIP_BACK
, { 25.61f
}, { 44.81f
}, { 1.01f
}},
11195 {0, {-25.59f
}, {-6.39f
}, { 0.0f
}},
11196 {D3DCLIP_LEFT
| D3DCLIP_BOTTOM
| D3DCLIP_FRONT
,{-25.61f
}, {-6.41f
}, {-0.01f
}},
11198 ok(compare_float(U1(cmp_h
[i
]).hx
, U1(out_h
[i
]).hx
, 4096)
11199 && compare_float(U2(cmp_h
[i
]).hy
, U2(out_h
[i
]).hy
, 4096)
11200 && compare_float(U3(cmp_h
[i
]).hz
, U3(out_h
[i
]).hz
, 4096)
11201 && cmp_h
[i
].dwFlags
== out_h
[i
].dwFlags
,
11202 "HVertex %u differs. Got %#x %f %f %f.\n", i
,
11203 out_h
[i
].dwFlags
, U1(out_h
[i
]).hx
, U2(out_h
[i
]).hy
, U3(out_h
[i
]).hz
);
11206 IDirectDrawSurface_Release(rt
);
11207 destroy_viewport(device
, viewport
);
11208 IDirect3DMaterial2_Release(background
);
11209 refcount
= IDirect3DDevice_Release(device
);
11210 ok(!refcount
, "Device has %u references left.\n", refcount
);
11211 IDirectDraw2_Release(ddraw
);
11212 DestroyWindow(window
);
11215 static void test_display_mode_surface_pixel_format(void)
11217 unsigned int width
, height
, bpp
;
11218 IDirectDrawSurface
*surface
;
11219 DDSURFACEDESC surface_desc
;
11220 IDirectDraw2
*ddraw
;
11225 if (!(ddraw
= create_ddraw()))
11227 skip("Failed to create ddraw.\n");
11231 surface_desc
.dwSize
= sizeof(surface_desc
);
11232 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
11233 ok(SUCCEEDED(hr
), "Failed to get display mode, hr %#x.\n", hr
);
11234 width
= surface_desc
.dwWidth
;
11235 height
= surface_desc
.dwHeight
;
11237 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11238 0, 0, width
, height
, NULL
, NULL
, NULL
, NULL
);
11239 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
11240 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11243 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 16, 0, 0)))
11245 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0)))
11247 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
11249 ok(bpp
, "Set display mode failed.\n");
11251 surface_desc
.dwSize
= sizeof(surface_desc
);
11252 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
11253 ok(SUCCEEDED(hr
), "Failed to get display mode, hr %#x.\n", hr
);
11254 ok(surface_desc
.dwWidth
== width
, "Got width %u, expected %u.\n", surface_desc
.dwWidth
, width
);
11255 ok(surface_desc
.dwHeight
== height
, "Got height %u, expected %u.\n", surface_desc
.dwHeight
, height
);
11256 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== bpp
, "Got bpp %u, expected %u.\n",
11257 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, bpp
);
11259 memset(&surface_desc
, 0, sizeof(surface_desc
));
11260 surface_desc
.dwSize
= sizeof(surface_desc
);
11261 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
11262 surface_desc
.dwBackBufferCount
= 1;
11263 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
;
11264 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
11265 ok(hr
== D3D_OK
, "Failed to create surface, hr %#x.\n", hr
);
11266 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
11267 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
11268 ok(surface_desc
.dwWidth
== width
, "Got width %u, expected %u.\n", surface_desc
.dwWidth
, width
);
11269 ok(surface_desc
.dwHeight
== height
, "Got height %u, expected %u.\n", surface_desc
.dwHeight
, height
);
11270 ok(surface_desc
.ddpfPixelFormat
.dwFlags
== DDPF_RGB
, "Got unexpected pixel format flags %#x.\n",
11271 surface_desc
.ddpfPixelFormat
.dwFlags
);
11272 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== bpp
, "Got bpp %u, expected %u.\n",
11273 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, bpp
);
11274 IDirectDrawSurface_Release(surface
);
11276 memset(&surface_desc
, 0, sizeof(surface_desc
));
11277 surface_desc
.dwSize
= sizeof(surface_desc
);
11278 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
11279 surface_desc
.dwWidth
= width
;
11280 surface_desc
.dwHeight
= height
;
11281 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11282 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
11283 ok(hr
== D3D_OK
, "Failed to create surface, hr %#x.\n", hr
);
11284 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
11285 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
11286 ok(surface_desc
.ddpfPixelFormat
.dwFlags
== DDPF_RGB
, "Got unexpected pixel format flags %#x.\n",
11287 surface_desc
.ddpfPixelFormat
.dwFlags
);
11288 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== bpp
, "Got bpp %u, expected %u.\n",
11289 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, bpp
);
11290 IDirectDrawSurface_Release(surface
);
11292 refcount
= IDirectDraw2_Release(ddraw
);
11293 ok(!refcount
, "DirectDraw has %u references left.\n", refcount
);
11294 DestroyWindow(window
);
11297 static void test_surface_desc_size(void)
11302 DDSURFACEDESC desc1
;
11303 DDSURFACEDESC2 desc2
;
11306 IDirectDrawSurface7
*surface7
;
11307 IDirectDrawSurface2
*surface2
;
11308 IDirectDrawSurface
*surface
;
11309 DDSURFACEDESC surface_desc
;
11310 HRESULT expected_hr
, hr
;
11311 IDirectDraw2
*ddraw
;
11315 static const struct
11322 {DDSCAPS_OFFSCREENPLAIN
, "offscreenplain"},
11323 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, "systemmemory texture"},
11324 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, "videomemory texture"},
11326 static const unsigned int desc_sizes
[] =
11328 sizeof(DDSURFACEDESC
),
11329 sizeof(DDSURFACEDESC2
),
11330 sizeof(DDSURFACEDESC
) + 1,
11331 sizeof(DDSURFACEDESC2
) + 1,
11332 2 * sizeof(DDSURFACEDESC
),
11333 2 * sizeof(DDSURFACEDESC2
),
11334 sizeof(DDSURFACEDESC
) - 1,
11335 sizeof(DDSURFACEDESC2
) - 1,
11336 sizeof(DDSURFACEDESC
) / 2,
11337 sizeof(DDSURFACEDESC2
) / 2,
11342 sizeof(desc
) - 100,
11345 if (!(ddraw
= create_ddraw()))
11347 skip("Failed to create ddraw.\n");
11350 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
11351 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11353 for (i
= 0; i
< sizeof(surface_caps
) / sizeof(*surface_caps
); ++i
)
11355 memset(&surface_desc
, 0, sizeof(surface_desc
));
11356 surface_desc
.dwSize
= sizeof(surface_desc
);
11357 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
11358 surface_desc
.ddsCaps
.dwCaps
= surface_caps
[i
].caps
;
11359 surface_desc
.dwHeight
= 128;
11360 surface_desc
.dwWidth
= 128;
11361 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11363 skip("Failed to create surface, type %s.\n", surface_caps
[i
].name
);
11366 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface2
, (void **)&surface2
);
11367 ok(hr
== DD_OK
, "Failed to query IDirectDrawSurface2, hr %#x, type %s.\n", hr
, surface_caps
[i
].name
);
11368 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface7
, (void **)&surface7
);
11369 ok(hr
== DD_OK
, "Failed to query IDirectDrawSurface7, hr %#x, type %s.\n", hr
, surface_caps
[i
].name
);
11371 /* GetSurfaceDesc() */
11372 for (j
= 0; j
< sizeof(desc_sizes
) / sizeof(*desc_sizes
); ++j
)
11374 memset(&desc
, 0, sizeof(desc
));
11375 desc
.dwSize
= desc_sizes
[j
];
11376 expected_hr
= desc
.dwSize
== sizeof(DDSURFACEDESC
) ? DD_OK
: DDERR_INVALIDPARAMS
;
11377 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &desc
.desc1
);
11378 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11379 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11381 memset(&desc
, 0, sizeof(desc
));
11382 desc
.dwSize
= desc_sizes
[j
];
11383 expected_hr
= desc
.dwSize
== sizeof(DDSURFACEDESC
) ? DD_OK
: DDERR_INVALIDPARAMS
;
11384 hr
= IDirectDrawSurface2_GetSurfaceDesc(surface2
, &desc
.desc1
);
11385 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11386 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11388 memset(&desc
, 0, sizeof(desc
));
11389 desc
.dwSize
= desc_sizes
[j
];
11390 expected_hr
= desc
.dwSize
== sizeof(DDSURFACEDESC2
) ? DD_OK
: DDERR_INVALIDPARAMS
;
11391 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
11392 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11393 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11397 for (j
= 0; j
< sizeof(desc_sizes
) / sizeof(*desc_sizes
); ++j
)
11399 const BOOL valid_size
= desc_sizes
[j
] == sizeof(DDSURFACEDESC
)
11400 || desc_sizes
[j
] == sizeof(DDSURFACEDESC2
);
11401 DWORD expected_texture_stage
;
11403 memset(&desc
, 0, sizeof(desc
));
11404 desc
.dwSize
= desc_sizes
[j
];
11405 desc
.desc2
.dwTextureStage
= 0xdeadbeef;
11406 desc
.blob
[sizeof(DDSURFACEDESC2
)] = 0xef;
11407 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &desc
.desc1
, 0, 0);
11408 expected_hr
= valid_size
? DD_OK
: DDERR_INVALIDPARAMS
;
11409 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11410 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11411 ok(desc
.dwSize
== desc_sizes
[j
], "dwSize was changed from %u to %u, type %s.\n",
11412 desc_sizes
[j
], desc
.dwSize
, surface_caps
[i
].name
);
11413 ok(desc
.blob
[sizeof(DDSURFACEDESC2
)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
11414 desc
.blob
[sizeof(DDSURFACEDESC2
)], desc_sizes
[j
], surface_caps
[i
].name
);
11417 ok(desc
.desc1
.dwWidth
== 128, "Got unexpected width %u, dwSize %u, type %s.\n",
11418 desc
.desc1
.dwWidth
, desc_sizes
[j
], surface_caps
[i
].name
);
11419 ok(desc
.desc1
.dwHeight
== 128, "Got unexpected height %u, dwSize %u, type %s.\n",
11420 desc
.desc1
.dwHeight
, desc_sizes
[j
], surface_caps
[i
].name
);
11421 expected_texture_stage
= desc_sizes
[j
] >= sizeof(DDSURFACEDESC2
) ? 0 : 0xdeadbeef;
11422 todo_wine_if(!expected_texture_stage
)
11423 ok(desc
.desc2
.dwTextureStage
== expected_texture_stage
,
11424 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
11425 desc
.desc2
.dwTextureStage
, desc_sizes
[j
], surface_caps
[i
].name
);
11426 IDirectDrawSurface_Unlock(surface
, NULL
);
11429 memset(&desc
, 0, sizeof(desc
));
11430 desc
.dwSize
= desc_sizes
[j
];
11431 desc
.desc2
.dwTextureStage
= 0xdeadbeef;
11432 desc
.blob
[sizeof(DDSURFACEDESC2
)] = 0xef;
11433 hr
= IDirectDrawSurface2_Lock(surface2
, NULL
, &desc
.desc1
, 0, 0);
11434 expected_hr
= valid_size
? DD_OK
: DDERR_INVALIDPARAMS
;
11435 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11436 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11437 ok(desc
.dwSize
== desc_sizes
[j
], "dwSize was changed from %u to %u, type %s.\n",
11438 desc_sizes
[j
], desc
.dwSize
, surface_caps
[i
].name
);
11439 ok(desc
.blob
[sizeof(DDSURFACEDESC2
)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
11440 desc
.blob
[sizeof(DDSURFACEDESC2
)], desc_sizes
[j
], surface_caps
[i
].name
);
11443 ok(desc
.desc2
.dwWidth
== 128, "Got unexpected width %u, dwSize %u, type %s.\n",
11444 desc
.desc2
.dwWidth
, desc_sizes
[j
], surface_caps
[i
].name
);
11445 ok(desc
.desc2
.dwHeight
== 128, "Got unexpected height %u, dwSize %u, type %s.\n",
11446 desc
.desc2
.dwHeight
, desc_sizes
[j
], surface_caps
[i
].name
);
11447 expected_texture_stage
= desc_sizes
[j
] >= sizeof(DDSURFACEDESC2
) ? 0 : 0xdeadbeef;
11448 todo_wine_if(!expected_texture_stage
)
11449 ok(desc
.desc2
.dwTextureStage
== expected_texture_stage
,
11450 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
11451 desc
.desc2
.dwTextureStage
, desc_sizes
[j
], surface_caps
[i
].name
);
11452 IDirectDrawSurface2_Unlock(surface2
, NULL
);
11455 memset(&desc
, 0, sizeof(desc
));
11456 desc
.dwSize
= desc_sizes
[j
];
11457 desc
.desc2
.dwTextureStage
= 0xdeadbeef;
11458 desc
.blob
[sizeof(DDSURFACEDESC2
)] = 0xef;
11459 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
11460 expected_hr
= valid_size
? DD_OK
: DDERR_INVALIDPARAMS
;
11461 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11462 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11463 ok(desc
.dwSize
== desc_sizes
[j
], "dwSize was changed from %u to %u, type %s.\n",
11464 desc_sizes
[j
], desc
.dwSize
, surface_caps
[i
].name
);
11465 ok(desc
.blob
[sizeof(DDSURFACEDESC2
)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
11466 desc
.blob
[sizeof(DDSURFACEDESC2
)], desc_sizes
[j
], surface_caps
[i
].name
);
11469 ok(desc
.desc2
.dwWidth
== 128, "Got unexpected width %u, dwSize %u, type %s.\n",
11470 desc
.desc2
.dwWidth
, desc_sizes
[j
], surface_caps
[i
].name
);
11471 ok(desc
.desc2
.dwHeight
== 128, "Got unexpected height %u, dwSize %u, type %s.\n",
11472 desc
.desc2
.dwHeight
, desc_sizes
[j
], surface_caps
[i
].name
);
11473 expected_texture_stage
= desc_sizes
[j
] >= sizeof(DDSURFACEDESC2
) ? 0 : 0xdeadbeef;
11474 ok(desc
.desc2
.dwTextureStage
== expected_texture_stage
,
11475 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
11476 desc
.desc2
.dwTextureStage
, desc_sizes
[j
], surface_caps
[i
].name
);
11477 IDirectDrawSurface7_Unlock(surface7
, NULL
);
11481 IDirectDrawSurface7_Release(surface7
);
11482 IDirectDrawSurface2_Release(surface2
);
11483 IDirectDrawSurface_Release(surface
);
11486 refcount
= IDirectDraw2_Release(ddraw
);
11487 ok(!refcount
, "DirectDraw has %u references left.\n", refcount
);
11492 IDirectDraw2
*ddraw
;
11493 DEVMODEW current_mode
;
11496 if (!(ddraw
= create_ddraw()))
11498 skip("Failed to create a ddraw object, skipping tests.\n");
11501 IDirectDraw2_Release(ddraw
);
11503 memset(¤t_mode
, 0, sizeof(current_mode
));
11504 current_mode
.dmSize
= sizeof(current_mode
);
11505 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
11506 registry_mode
.dmSize
= sizeof(registry_mode
);
11507 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
11508 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
11509 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
11511 skip("Current mode does not match registry mode, skipping test.\n");
11515 if ((dwmapi
= LoadLibraryA("dwmapi.dll")))
11516 pDwmIsCompositionEnabled
= (void *)GetProcAddress(dwmapi
, "DwmIsCompositionEnabled");
11518 test_coop_level_create_device_window();
11519 test_clipper_blt();
11520 test_coop_level_d3d_state();
11521 test_surface_interface_mismatch();
11522 test_coop_level_threaded();
11524 test_texture_load_ckey();
11533 test_window_style();
11534 test_redundant_mode_set();
11535 test_coop_level_mode_set();
11536 test_coop_level_mode_set_multi();
11538 test_coop_level_surf_create();
11539 test_coop_level_multi_window();
11540 test_clear_rect_count();
11541 test_coop_level_versions();
11542 test_lighting_interface_versions();
11543 test_coop_level_activateapp();
11544 test_unsupported_formats();
11546 test_primary_caps();
11547 test_surface_lock();
11548 test_surface_discard();
11550 test_set_surface_desc();
11551 test_user_memory_getdc();
11552 test_sysmem_overlay();
11553 test_primary_palette();
11554 test_surface_attachment();
11555 test_pixel_format();
11556 test_create_surface_pitch();
11558 test_palette_complex();
11562 test_specular_lighting();
11563 test_palette_gdi();
11564 test_palette_alpha();
11565 test_lost_device();
11566 test_surface_desc_lock();
11567 test_texturemapblend();
11568 test_viewport_clear_rect();
11570 test_colorkey_precision();
11571 test_range_colorkey();
11573 test_lockrect_invalid();
11574 test_yv12_overlay();
11575 test_offscreen_overlay();
11576 test_overlay_rect();
11579 test_draw_primitive();
11580 test_edge_antialiasing_blending();
11581 test_transform_vertices();
11582 test_display_mode_surface_pixel_format();
11583 test_surface_desc_size();