2 * Copyright 2005 Antoine Chavasse (a.chavasse@gmail.com)
3 * Copyright 2008, 2011, 2012-2014 Stefan Dösinger for CodeWeavers
4 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
29 static BOOL is_ddraw64
= sizeof(DWORD
) != sizeof(DWORD
*);
30 static DEVMODEW registry_mode
;
32 static HRESULT (WINAPI
*pDwmIsCompositionEnabled
)(BOOL
*);
35 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
43 struct create_window_thread_param
46 HANDLE window_created
;
47 HANDLE destroy_window
;
51 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
53 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
55 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
57 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
59 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
63 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
73 if (abs(x
- y
) > ulps
)
79 static BOOL
compare_vec4(const struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
81 return compare_float(vec
->x
, x
, ulps
)
82 && compare_float(vec
->y
, y
, ulps
)
83 && compare_float(vec
->z
, z
, ulps
)
84 && compare_float(vec
->w
, w
, ulps
);
87 static BOOL
ddraw_get_identifier(IDirectDraw2
*ddraw
, DDDEVICEIDENTIFIER
*identifier
)
92 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
93 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
94 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, identifier
, 0);
95 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
96 IDirectDraw4_Release(ddraw4
);
101 static BOOL
ddraw_is_warp(IDirectDraw2
*ddraw
)
103 DDDEVICEIDENTIFIER identifier
;
105 return strcmp(winetest_platform
, "wine")
106 && ddraw_get_identifier(ddraw
, &identifier
)
107 && strstr(identifier
.szDriver
, "warp");
110 static BOOL
ddraw_is_vendor(IDirectDraw2
*ddraw
, DWORD vendor
)
112 DDDEVICEIDENTIFIER identifier
;
114 return strcmp(winetest_platform
, "wine")
115 && ddraw_get_identifier(ddraw
, &identifier
)
116 && identifier
.dwVendorId
== vendor
;
119 static BOOL
ddraw_is_intel(IDirectDraw2
*ddraw
)
121 return ddraw_is_vendor(ddraw
, 0x8086);
124 static BOOL
ddraw_is_nvidia(IDirectDraw2
*ddraw
)
126 return ddraw_is_vendor(ddraw
, 0x10de);
129 static BOOL
ddraw_is_vmware(IDirectDraw2
*ddraw
)
131 return ddraw_is_vendor(ddraw
, 0x15ad);
134 static IDirectDrawSurface
*create_overlay(IDirectDraw2
*ddraw
,
135 unsigned int width
, unsigned int height
, DWORD format
)
137 IDirectDrawSurface
*surface
;
140 memset(&desc
, 0, sizeof(desc
));
141 desc
.dwSize
= sizeof(desc
);
142 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
143 desc
.dwWidth
= width
;
144 desc
.dwHeight
= height
;
145 desc
.ddsCaps
.dwCaps
= DDSCAPS_OVERLAY
;
146 desc
.ddpfPixelFormat
.dwSize
= sizeof(desc
.ddpfPixelFormat
);
147 desc
.ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
148 desc
.ddpfPixelFormat
.dwFourCC
= format
;
150 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &desc
, &surface
, NULL
)))
155 static HWND
create_window(void)
157 RECT r
= {0, 0, 640, 480};
159 AdjustWindowRect(&r
, WS_OVERLAPPEDWINDOW
| WS_VISIBLE
, FALSE
);
161 return CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
162 CW_USEDEFAULT
, CW_USEDEFAULT
, r
.right
- r
.left
, r
.bottom
- r
.top
, NULL
, NULL
, NULL
, NULL
);
165 static DWORD WINAPI
create_window_thread_proc(void *param
)
167 struct create_window_thread_param
*p
= param
;
171 p
->window
= create_window();
172 ret
= SetEvent(p
->window_created
);
173 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
179 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
180 DispatchMessageA(&msg
);
181 res
= WaitForSingleObject(p
->destroy_window
, 100);
182 if (res
== WAIT_OBJECT_0
)
184 if (res
!= WAIT_TIMEOUT
)
186 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
191 DestroyWindow(p
->window
);
196 static void create_window_thread(struct create_window_thread_param
*p
)
200 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
201 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
202 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
203 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
204 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
205 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
206 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
207 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
210 static void destroy_window_thread(struct create_window_thread_param
*p
)
212 SetEvent(p
->destroy_window
);
213 WaitForSingleObject(p
->thread
, INFINITE
);
214 CloseHandle(p
->destroy_window
);
215 CloseHandle(p
->window_created
);
216 CloseHandle(p
->thread
);
219 static IDirectDrawSurface
*get_depth_stencil(IDirect3DDevice2
*device
)
221 IDirectDrawSurface
*rt
, *ret
;
222 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
225 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
226 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
227 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ret
);
228 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
229 IDirectDrawSurface_Release(rt
);
233 static HRESULT
set_display_mode(IDirectDraw2
*ddraw
, DWORD width
, DWORD height
)
235 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
237 return IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
240 static D3DCOLOR
get_surface_color(IDirectDrawSurface
*surface
, UINT x
, UINT y
)
242 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
243 DDSURFACEDESC surface_desc
;
247 memset(&surface_desc
, 0, sizeof(surface_desc
));
248 surface_desc
.dwSize
= sizeof(surface_desc
);
250 hr
= IDirectDrawSurface_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
251 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
255 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
257 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
258 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
263 static DWORD
get_device_z_depth(IDirect3DDevice2
*device
)
265 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
266 IDirectDrawSurface
*ds
, *rt
;
270 if (FAILED(IDirect3DDevice2_GetRenderTarget(device
, &rt
)))
273 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ds
);
274 IDirectDrawSurface_Release(rt
);
278 desc
.dwSize
= sizeof(desc
);
279 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
280 IDirectDrawSurface_Release(ds
);
284 return U2(desc
).dwZBufferBitDepth
;
287 static IDirectDraw2
*create_ddraw(void)
289 IDirectDraw2
*ddraw2
;
293 if (FAILED(DirectDrawCreate(NULL
, &ddraw1
, NULL
)))
296 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw2
, (void **)&ddraw2
);
297 IDirectDraw_Release(ddraw1
);
304 static IDirect3DDevice2
*create_device(IDirectDraw2
*ddraw
, HWND window
, DWORD coop_level
)
306 /* Prefer 16 bit depth buffers because Nvidia gives us an unpadded D24 buffer if we ask
307 * for 24 bit and handles such buffers incorrectly in DDBLT_DEPTHFILL. AMD only supports
308 * 16 bit buffers in ddraw1/2. Stencil was added in ddraw4, so we cannot create a D24S8
310 static const DWORD z_depths
[] = {16, 32, 24};
311 IDirectDrawSurface
*surface
, *ds
;
312 IDirect3DDevice2
*device
= NULL
;
313 DDSURFACEDESC surface_desc
;
318 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, coop_level
);
319 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
321 memset(&surface_desc
, 0, sizeof(surface_desc
));
322 surface_desc
.dwSize
= sizeof(surface_desc
);
323 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
324 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
325 surface_desc
.dwWidth
= 640;
326 surface_desc
.dwHeight
= 480;
328 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
329 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
331 if (coop_level
& DDSCL_NORMAL
)
333 IDirectDrawClipper
*clipper
;
335 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
336 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
337 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
338 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
339 hr
= IDirectDrawSurface_SetClipper(surface
, clipper
);
340 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
341 IDirectDrawClipper_Release(clipper
);
344 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
347 IDirectDrawSurface_Release(surface
);
351 /* We used to use EnumDevices() for this, but it seems
352 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
353 * relationship with reality. */
354 for (i
= 0; i
< ARRAY_SIZE(z_depths
); ++i
)
356 memset(&surface_desc
, 0, sizeof(surface_desc
));
357 surface_desc
.dwSize
= sizeof(surface_desc
);
358 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
359 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
360 U2(surface_desc
).dwZBufferBitDepth
= z_depths
[i
];
361 surface_desc
.dwWidth
= 640;
362 surface_desc
.dwHeight
= 480;
363 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
)))
366 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
367 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
368 IDirectDrawSurface_Release(ds
);
372 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
)))
375 IDirectDrawSurface_DeleteAttachedSurface(surface
, 0, ds
);
378 IDirect3D2_Release(d3d
);
379 IDirectDrawSurface_Release(surface
);
383 static IDirect3DViewport2
*create_viewport(IDirect3DDevice2
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
385 IDirect3DViewport2
*viewport
;
390 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
391 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
392 hr
= IDirect3D2_CreateViewport(d3d
, &viewport
, NULL
);
393 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
394 hr
= IDirect3DDevice2_AddViewport(device
, viewport
);
395 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
396 memset(&vp
, 0, sizeof(vp
));
397 vp
.dwSize
= sizeof(vp
);
404 vp
.dvClipWidth
= 2.0f
;
405 vp
.dvClipHeight
= 2.0f
;
408 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp
);
409 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
410 IDirect3D2_Release(d3d
);
415 static void viewport_set_background(IDirect3DDevice2
*device
, IDirect3DViewport2
*viewport
,
416 IDirect3DMaterial2
*material
)
418 D3DMATERIALHANDLE material_handle
;
421 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &material_handle
);
422 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
423 hr
= IDirect3DViewport2_SetBackground(viewport
, material_handle
);
424 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
427 static void destroy_viewport(IDirect3DDevice2
*device
, IDirect3DViewport2
*viewport
)
431 hr
= IDirect3DDevice2_DeleteViewport(device
, viewport
);
432 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
433 IDirect3DViewport2_Release(viewport
);
436 static IDirect3DMaterial2
*create_material(IDirect3DDevice2
*device
, D3DMATERIAL
*mat
)
438 IDirect3DMaterial2
*material
;
442 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
443 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
444 hr
= IDirect3D2_CreateMaterial(d3d
, &material
, NULL
);
445 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
446 hr
= IDirect3DMaterial2_SetMaterial(material
, mat
);
447 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
448 IDirect3D2_Release(d3d
);
453 static IDirect3DMaterial2
*create_diffuse_material(IDirect3DDevice2
*device
, float r
, float g
, float b
, float a
)
457 memset(&mat
, 0, sizeof(mat
));
458 mat
.dwSize
= sizeof(mat
);
459 U1(U(mat
).diffuse
).r
= r
;
460 U2(U(mat
).diffuse
).g
= g
;
461 U3(U(mat
).diffuse
).b
= b
;
462 U4(U(mat
).diffuse
).a
= a
;
464 return create_material(device
, &mat
);
467 static IDirect3DMaterial2
*create_specular_material(IDirect3DDevice2
*device
,
468 float r
, float g
, float b
, float a
, float power
)
472 memset(&mat
, 0, sizeof(mat
));
473 mat
.dwSize
= sizeof(mat
);
474 U1(U2(mat
).specular
).r
= r
;
475 U2(U2(mat
).specular
).g
= g
;
476 U3(U2(mat
).specular
).b
= b
;
477 U4(U2(mat
).specular
).a
= a
;
478 U4(mat
).power
= power
;
480 return create_material(device
, &mat
);
483 static IDirect3DMaterial2
*create_emissive_material(IDirect3DDevice2
*device
, float r
, float g
, float b
, float a
)
487 memset(&mat
, 0, sizeof(mat
));
488 mat
.dwSize
= sizeof(mat
);
489 U1(U3(mat
).emissive
).r
= r
;
490 U2(U3(mat
).emissive
).g
= g
;
491 U3(U3(mat
).emissive
).b
= b
;
492 U4(U3(mat
).emissive
).a
= a
;
494 return create_material(device
, &mat
);
497 static void destroy_material(IDirect3DMaterial2
*material
)
499 IDirect3DMaterial2_Release(material
);
506 WPARAM expect_wparam
;
509 static const struct message
*expect_messages
;
511 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
513 if (expect_messages
&& message
== expect_messages
->message
)
515 if (expect_messages
->check_wparam
)
516 ok (wparam
== expect_messages
->expect_wparam
,
517 "Got unexpected wparam %lx for message %x, expected %lx.\n",
518 wparam
, message
, expect_messages
->expect_wparam
);
523 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
526 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
527 * interface. This prevents subsequent SetCooperativeLevel() calls on a
528 * different window from failing with DDERR_HWNDALREADYSET. */
529 static void fix_wndproc(HWND window
, LONG_PTR proc
)
534 if (!(ddraw
= create_ddraw()))
537 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
538 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
539 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
540 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
541 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
543 IDirectDraw2_Release(ddraw
);
546 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
548 HRESULT hr
= IDirectDrawSurface_Restore(surface
);
549 ok(SUCCEEDED(hr
) || hr
== DDERR_IMPLICITLYCREATED
, "Failed to restore surface, hr %#x.\n", hr
);
550 IDirectDrawSurface_Release(surface
);
555 static HRESULT
restore_surfaces(IDirectDraw2
*ddraw
)
557 return IDirectDraw2_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
558 NULL
, NULL
, restore_callback
);
561 static void test_coop_level_create_device_window(void)
563 HWND focus_window
, device_window
;
567 focus_window
= create_window();
568 ddraw
= create_ddraw();
569 ok(!!ddraw
, "Failed to create a ddraw object.\n");
571 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
572 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
573 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
574 ok(!device_window
, "Unexpected device window found.\n");
575 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
576 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
577 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
578 ok(!device_window
, "Unexpected device window found.\n");
579 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
580 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
581 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
582 ok(!device_window
, "Unexpected device window found.\n");
583 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
584 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
585 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
586 ok(!device_window
, "Unexpected device window found.\n");
587 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
588 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
589 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
590 ok(!device_window
, "Unexpected device window found.\n");
592 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
593 if (broken(hr
== DDERR_INVALIDPARAMS
))
595 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
596 IDirectDraw2_Release(ddraw
);
597 DestroyWindow(focus_window
);
601 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
602 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
603 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
604 ok(!device_window
, "Unexpected device window found.\n");
605 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
606 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
607 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
608 ok(!device_window
, "Unexpected device window found.\n");
610 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
611 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
612 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
613 ok(!device_window
, "Unexpected device window found.\n");
614 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
615 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
616 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
617 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
618 ok(!!device_window
, "Device window not found.\n");
620 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
621 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
622 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
623 ok(!device_window
, "Unexpected device window found.\n");
624 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
625 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
626 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
627 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
628 ok(!!device_window
, "Device window not found.\n");
630 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
631 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
632 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
633 ok(!device_window
, "Unexpected device window found.\n");
634 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
635 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
636 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
637 ok(!device_window
, "Unexpected device window found.\n");
638 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
639 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
640 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
641 ok(!device_window
, "Unexpected device window found.\n");
642 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
643 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
644 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
645 ok(!!device_window
, "Device window not found.\n");
647 IDirectDraw2_Release(ddraw
);
648 DestroyWindow(focus_window
);
651 static void test_clipper_blt(void)
653 IDirectDrawSurface
*src_surface
, *dst_surface
;
654 RECT client_rect
, src_rect
;
655 IDirectDrawClipper
*clipper
;
656 DDSURFACEDESC surface_desc
;
657 unsigned int i
, j
, x
, y
;
669 static const DWORD src_data
[] =
671 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
672 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
673 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
675 static const D3DCOLOR expected1
[] =
677 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
678 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
679 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
680 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
682 /* Nvidia on Windows seems to have an off-by-one error
683 * when processing source rectangles. Our left = 1 and
684 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
685 * read as well, but only for the edge pixels on the
686 * output image. The bug happens on the y axis as well,
687 * but we only read one row there, and all source rows
688 * contain the same data. This bug is not dependent on
689 * the presence of a clipper. */
690 static const D3DCOLOR expected1_broken
[] =
692 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
693 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
694 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
695 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
697 static const D3DCOLOR expected2
[] =
699 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
700 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
701 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
702 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
705 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
706 10, 10, 640, 480, 0, 0, 0, 0);
707 ShowWindow(window
, SW_SHOW
);
708 ddraw
= create_ddraw();
709 ok(!!ddraw
, "Failed to create a ddraw object.\n");
711 ret
= GetClientRect(window
, &client_rect
);
712 ok(ret
, "Failed to get client rect.\n");
713 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
714 ok(ret
, "Failed to map client rect.\n");
716 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
717 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
719 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
720 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
721 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
722 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
723 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
724 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
725 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
726 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
727 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
728 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
729 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
730 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
731 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
732 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
733 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
734 "Got unexpected bounding rect %s, expected %s.\n",
735 wine_dbgstr_rect(&rgn_data
->rdh
.rcBound
), wine_dbgstr_rect(&client_rect
));
736 HeapFree(GetProcessHeap(), 0, rgn_data
);
738 r1
= CreateRectRgn(0, 0, 320, 240);
739 ok(!!r1
, "Failed to create region.\n");
740 r2
= CreateRectRgn(320, 240, 640, 480);
741 ok(!!r2
, "Failed to create region.\n");
742 CombineRgn(r1
, r1
, r2
, RGN_OR
);
743 ret
= GetRegionData(r1
, 0, NULL
);
744 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
745 ret
= GetRegionData(r1
, ret
, rgn_data
);
746 ok(!!ret
, "Failed to get region data.\n");
751 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
752 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
753 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
754 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
755 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
756 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
758 HeapFree(GetProcessHeap(), 0, rgn_data
);
760 memset(&surface_desc
, 0, sizeof(surface_desc
));
761 surface_desc
.dwSize
= sizeof(surface_desc
);
762 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
763 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
764 surface_desc
.dwWidth
= 640;
765 surface_desc
.dwHeight
= 480;
766 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
767 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
768 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
769 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
770 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
771 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
773 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
774 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
775 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
776 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
778 memset(&fx
, 0, sizeof(fx
));
779 fx
.dwSize
= sizeof(fx
);
780 hr
= IDirectDrawSurface_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
781 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
782 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
783 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
785 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
786 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
787 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
788 ptr
= surface_desc
.lpSurface
;
789 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
790 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
791 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
792 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
793 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
795 hr
= IDirectDrawSurface_SetClipper(dst_surface
, clipper
);
796 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
798 SetRect(&src_rect
, 1, 1, 5, 2);
799 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
800 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
801 for (i
= 0; i
< 4; ++i
)
803 for (j
= 0; j
< 4; ++j
)
805 x
= 80 * ((2 * j
) + 1);
806 y
= 60 * ((2 * i
) + 1);
807 color
= get_surface_color(dst_surface
, x
, y
);
808 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
809 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
810 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
814 U5(fx
).dwFillColor
= 0xff0000ff;
815 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
816 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
817 for (i
= 0; i
< 4; ++i
)
819 for (j
= 0; j
< 4; ++j
)
821 x
= 80 * ((2 * j
) + 1);
822 y
= 60 * ((2 * i
) + 1);
823 color
= get_surface_color(dst_surface
, x
, y
);
824 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
825 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
829 hr
= IDirectDrawSurface_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
830 ok(hr
== DDERR_BLTFASTCANTCLIP
|| broken(hr
== E_NOTIMPL
/* NT4 */), "Got unexpected hr %#x.\n", hr
);
832 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
833 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
834 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
835 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
836 DestroyWindow(window
);
837 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
838 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
839 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
840 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
841 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
842 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
843 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
844 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
845 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
846 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
847 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
848 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
850 IDirectDrawSurface_Release(dst_surface
);
851 IDirectDrawSurface_Release(src_surface
);
852 refcount
= IDirectDrawClipper_Release(clipper
);
853 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
854 IDirectDraw2_Release(ddraw
);
857 static void test_coop_level_d3d_state(void)
859 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
860 IDirectDrawSurface
*rt
, *surface
;
861 IDirect3DMaterial2
*background
;
862 IDirect3DViewport2
*viewport
;
863 IDirect3DDevice2
*device
;
864 D3DMATERIAL material
;
871 window
= create_window();
872 ddraw
= create_ddraw();
873 ok(!!ddraw
, "Failed to create a ddraw object.\n");
874 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
876 skip("Failed to create a 3D device, skipping test.\n");
877 IDirectDraw2_Release(ddraw
);
878 DestroyWindow(window
);
882 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
883 viewport
= create_viewport(device
, 0, 0, 640, 480);
884 viewport_set_background(device
, viewport
, background
);
886 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
887 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
888 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
889 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
890 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
891 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
892 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
893 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
894 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
895 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
896 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
897 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
898 color
= get_surface_color(rt
, 320, 240);
899 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
901 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
902 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
903 hr
= IDirectDrawSurface_IsLost(rt
);
904 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
905 hr
= restore_surfaces(ddraw
);
906 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
908 memset(&material
, 0, sizeof(material
));
909 material
.dwSize
= sizeof(material
);
910 U1(U(material
).diffuse
).r
= 0.0f
;
911 U2(U(material
).diffuse
).g
= 1.0f
;
912 U3(U(material
).diffuse
).b
= 0.0f
;
913 U4(U(material
).diffuse
).a
= 1.0f
;
914 hr
= IDirect3DMaterial2_SetMaterial(background
, &material
);
915 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
917 hr
= IDirect3DDevice2_GetRenderTarget(device
, &surface
);
918 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
919 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
920 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
921 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
922 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
923 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
924 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
925 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
926 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
927 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
928 color
= get_surface_color(rt
, 320, 240);
929 ok(compare_color(color
, 0x0000ff00, 1) || broken(compare_color(color
, 0x00000000, 1)),
930 "Got unexpected color 0x%08x.\n", color
);
932 destroy_viewport(device
, viewport
);
933 destroy_material(background
);
934 IDirectDrawSurface_Release(surface
);
935 IDirectDrawSurface_Release(rt
);
936 IDirect3DDevice2_Release(device
);
937 IDirectDraw2_Release(ddraw
);
938 DestroyWindow(window
);
941 static void test_surface_interface_mismatch(void)
943 IDirectDraw2
*ddraw
= NULL
;
944 IDirect3D2
*d3d
= NULL
;
945 IDirectDrawSurface
*surface
= NULL
, *ds
;
946 IDirectDrawSurface3
*surface3
= NULL
;
947 IDirect3DDevice2
*device
= NULL
;
948 IDirect3DViewport2
*viewport
= NULL
;
949 IDirect3DMaterial2
*background
= NULL
;
950 DDSURFACEDESC surface_desc
;
956 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
958 window
= create_window();
959 ddraw
= create_ddraw();
960 ok(!!ddraw
, "Failed to create a ddraw object.\n");
961 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
963 skip("Failed to create a 3D device, skipping test.\n");
964 IDirectDraw2_Release(ddraw
);
965 DestroyWindow(window
);
968 z_depth
= get_device_z_depth(device
);
969 ok(!!z_depth
, "Failed to get device z depth.\n");
970 IDirect3DDevice2_Release(device
);
973 memset(&surface_desc
, 0, sizeof(surface_desc
));
974 surface_desc
.dwSize
= sizeof(surface_desc
);
975 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
976 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
977 surface_desc
.dwWidth
= 640;
978 surface_desc
.dwHeight
= 480;
980 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
981 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
983 hr
= IDirectDrawSurface2_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
986 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
990 if (FAILED(IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
)))
992 skip("D3D interface is not available, skipping test.\n");
996 memset(&surface_desc
, 0, sizeof(surface_desc
));
997 surface_desc
.dwSize
= sizeof(surface_desc
);
998 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
999 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1000 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
1001 surface_desc
.dwWidth
= 640;
1002 surface_desc
.dwHeight
= 480;
1003 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
1004 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
1008 /* Using a different surface interface version still works */
1009 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
1010 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
1011 refcount
= IDirectDrawSurface_Release(ds
);
1012 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1017 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface
*)surface3
, &device
);
1018 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
1022 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1023 viewport
= create_viewport(device
, 0, 0, 640, 480);
1024 viewport_set_background(device
, viewport
, background
);
1026 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1027 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1028 color
= get_surface_color(surface
, 320, 240);
1029 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
1033 destroy_viewport(device
, viewport
);
1035 destroy_material(background
);
1036 if (surface3
) IDirectDrawSurface3_Release(surface3
);
1037 if (surface
) IDirectDrawSurface_Release(surface
);
1038 if (device
) IDirect3DDevice2_Release(device
);
1039 if (d3d
) IDirect3D2_Release(d3d
);
1040 if (ddraw
) IDirectDraw2_Release(ddraw
);
1041 DestroyWindow(window
);
1044 static void test_coop_level_threaded(void)
1046 struct create_window_thread_param p
;
1047 IDirectDraw2
*ddraw
;
1050 ddraw
= create_ddraw();
1051 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1052 create_window_thread(&p
);
1054 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1055 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1057 IDirectDraw2_Release(ddraw
);
1058 destroy_window_thread(&p
);
1061 static void test_depth_blit(void)
1063 static D3DLVERTEX quad1
[] =
1065 {{-1.0}, { 1.0}, {0.50f
}, 0, {0xff00ff00}},
1066 {{ 1.0}, { 1.0}, {0.50f
}, 0, {0xff00ff00}},
1067 {{-1.0}, {-1.0}, {0.50f
}, 0, {0xff00ff00}},
1068 {{ 1.0}, {-1.0}, {0.50f
}, 0, {0xff00ff00}},
1070 static const D3DCOLOR expected_colors
[4][4] =
1072 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1073 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1074 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1075 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1077 DDSURFACEDESC ddsd_new
, ddsd_existing
;
1079 IDirect3DDevice2
*device
;
1080 IDirectDrawSurface
*ds1
, *ds2
, *ds3
, *rt
;
1081 IDirect3DViewport2
*viewport
;
1082 RECT src_rect
, dst_rect
;
1086 IDirectDraw2
*ddraw
;
1090 IDirect3DMaterial2
*background
;
1092 window
= create_window();
1093 ddraw
= create_ddraw();
1094 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1095 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1097 skip("Failed to create a 3D device, skipping test.\n");
1098 IDirectDraw2_Release(ddraw
);
1099 DestroyWindow(window
);
1103 ds1
= get_depth_stencil(device
);
1105 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1106 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1107 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1108 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1109 hr
= IDirectDrawSurface_GetSurfaceDesc(ds1
, &ddsd_existing
);
1110 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
1111 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1112 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1113 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1114 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1115 ddsd_new
.ddpfPixelFormat
= ddsd_existing
.ddpfPixelFormat
;
1116 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1117 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1118 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1119 ok(SUCCEEDED(hr
), "Failed to create a surface, hr %#x.\n", hr
);
1121 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1122 viewport
= create_viewport(device
, 0, 0, ddsd_existing
.dwWidth
, ddsd_existing
.dwHeight
);
1123 viewport_set_background(device
, viewport
, background
);
1124 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1125 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
1127 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1128 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1129 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1130 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1132 U1(d3drect
).x1
= U2(d3drect
).y1
= 0;
1133 U3(d3drect
).x2
= ddsd_existing
.dwWidth
; U4(d3drect
).y2
= ddsd_existing
.dwHeight
;
1134 hr
= IDirect3DViewport2_Clear(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
);
1135 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1138 SetRect(&src_rect
, 0, 0, 320, 240);
1139 SetRect(&dst_rect
, 0, 0, 320, 240);
1140 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1141 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1142 /* Different locations. */
1143 SetRect(&src_rect
, 0, 0, 320, 240);
1144 SetRect(&dst_rect
, 320, 240, 640, 480);
1145 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1146 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1148 SetRect(&src_rect
, 0, 0, 320, 240);
1149 SetRect(&dst_rect
, 0, 0, 640, 480);
1150 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1151 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1153 SetRect(&src_rect
, 0, 480, 640, 0);
1154 SetRect(&dst_rect
, 0, 0, 640, 480);
1155 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1156 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1157 SetRect(&src_rect
, 0, 0, 640, 480);
1158 SetRect(&dst_rect
, 0, 480, 640, 0);
1159 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1160 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1161 /* Full, explicit. */
1162 SetRect(&src_rect
, 0, 0, 640, 480);
1163 SetRect(&dst_rect
, 0, 0, 640, 480);
1164 hr
= IDirectDrawSurface_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1165 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1166 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1168 /* Depth blit inside a BeginScene / EndScene pair */
1169 hr
= IDirect3DDevice2_BeginScene(device
);
1170 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1171 /* From the current depth stencil */
1172 hr
= IDirectDrawSurface_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1173 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1174 /* To the current depth stencil */
1175 hr
= IDirectDrawSurface_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1176 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1177 /* Between unbound surfaces */
1178 hr
= IDirectDrawSurface_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1179 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1180 hr
= IDirect3DDevice2_EndScene(device
);
1181 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1183 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1184 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1185 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1186 * a reliable result(z = 0.0) */
1187 memset(&fx
, 0, sizeof(fx
));
1188 fx
.dwSize
= sizeof(fx
);
1189 U5(fx
).dwFillDepth
= 0;
1190 hr
= IDirectDrawSurface_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1191 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1193 /* This clears the Z buffer with 1.0 */
1194 hr
= IDirect3DViewport2_Clear(viewport
, 1, &d3drect
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
);
1195 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1197 SetRect(&dst_rect
, 0, 0, 320, 240);
1198 hr
= IDirectDrawSurface_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1199 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1200 IDirectDrawSurface_Release(ds3
);
1201 IDirectDrawSurface_Release(ds2
);
1202 IDirectDrawSurface_Release(ds1
);
1204 hr
= IDirect3DDevice2_BeginScene(device
);
1205 ok(SUCCEEDED(hr
), "Failed to start a scene, hr %#x.\n", hr
);
1206 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad1
, 4, 0);
1207 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1208 hr
= IDirect3DDevice2_EndScene(device
);
1209 ok(SUCCEEDED(hr
), "Failed to end a scene, hr %#x.\n", hr
);
1211 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1212 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1213 for (i
= 0; i
< 4; ++i
)
1215 for (j
= 0; j
< 4; ++j
)
1217 unsigned int x
= 80 * ((2 * j
) + 1);
1218 unsigned int y
= 60 * ((2 * i
) + 1);
1219 color
= get_surface_color(rt
, x
, y
);
1220 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1221 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1224 IDirectDrawSurface_Release(rt
);
1226 destroy_viewport(device
, viewport
);
1227 destroy_material(background
);
1228 IDirect3DDevice2_Release(device
);
1229 IDirectDraw2_Release(ddraw
);
1230 DestroyWindow(window
);
1233 static void test_texture_load_ckey(void)
1235 IDirectDraw2
*ddraw
= NULL
;
1236 IDirectDrawSurface
*src
= NULL
;
1237 IDirectDrawSurface
*dst
= NULL
;
1238 IDirect3DTexture
*src_tex
= NULL
;
1239 IDirect3DTexture
*dst_tex
= NULL
;
1244 ddraw
= create_ddraw();
1245 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1246 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
1247 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1249 memset(&ddsd
, 0, sizeof(ddsd
));
1250 ddsd
.dwSize
= sizeof(ddsd
);
1251 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1252 ddsd
.dwHeight
= 128;
1254 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1255 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1256 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1257 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1258 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1259 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1261 hr
= IDirectDrawSurface_QueryInterface(src
, &IID_IDirect3DTexture
, (void **)&src_tex
);
1262 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get Direct3DTexture interface, hr %#x.\n", hr
);
1265 /* 64 bit ddraw does not support d3d */
1266 skip("Could not get Direct3DTexture interface, skipping texture::Load color keying tests.\n");
1269 hr
= IDirectDrawSurface_QueryInterface(dst
, &IID_IDirect3DTexture
, (void **)&dst_tex
);
1270 ok(SUCCEEDED(hr
), "Failed to get Direct3DTexture interface, hr %#x.\n", hr
);
1272 /* No surface has a color key */
1273 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1274 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDCAPS
), "Got unexpected hr %#x.\n", hr
);
1277 /* Testbot Windows NT VMs */
1278 skip("IDirect3DTexture::Load does not work, skipping color keying tests.\n");
1282 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1283 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1284 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1285 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1286 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1288 /* Source surface has a color key */
1289 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1290 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1291 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1292 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1293 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1294 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1295 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1296 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1297 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1299 /* Both surfaces have a color key: Dest ckey is overwritten */
1300 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1301 hr
= IDirectDrawSurface_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1302 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1303 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1304 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1305 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1306 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1307 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1308 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1310 /* Only the destination has a color key: It is not deleted */
1311 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1312 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1313 hr
= IDirectDrawSurface_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1314 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1315 hr
= IDirect3DTexture_Load(dst_tex
, src_tex
);
1316 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1317 hr
= IDirectDrawSurface_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1318 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1319 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1320 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1323 if (dst_tex
) IDirect3DTexture_Release(dst_tex
);
1324 if (src_tex
) IDirect3DTexture_Release(src_tex
);
1325 if (dst
) IDirectDrawSurface_Release(dst
);
1326 if (src
) IDirectDrawSurface_Release(src
);
1327 if (ddraw
) IDirectDraw2_Release(ddraw
);
1330 static ULONG
get_refcount(IUnknown
*test_iface
)
1332 IUnknown_AddRef(test_iface
);
1333 return IUnknown_Release(test_iface
);
1336 static void test_viewport(void)
1338 IDirectDraw2
*ddraw
;
1341 ULONG ref
, old_d3d_ref
;
1342 IDirect3DViewport
*viewport
;
1343 IDirect3DViewport2
*viewport2
, *another_vp
, *test_vp
;
1344 IDirect3DViewport3
*viewport3
;
1345 IDirectDrawGammaControl
*gamma
;
1347 IDirect3DDevice2
*device
;
1350 window
= create_window();
1351 ddraw
= create_ddraw();
1352 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1353 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1355 skip("Failed to create a 3D device, skipping test.\n");
1356 IDirectDraw_Release(ddraw
);
1357 DestroyWindow(window
);
1361 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
1362 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to get d3d interface, hr %#x.\n", hr
);
1365 skip("D3D interface is not available, skipping test.\n");
1366 IDirectDraw2_Release(ddraw
);
1369 old_d3d_ref
= get_refcount((IUnknown
*)d3d
);
1371 hr
= IDirect3D2_CreateViewport(d3d
, &viewport2
, NULL
);
1372 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1373 ref
= get_refcount((IUnknown
*)viewport2
);
1374 ok(ref
== 1, "Initial IDirect3DViewport2 refcount is %u\n", ref
);
1375 ref
= get_refcount((IUnknown
*)d3d
);
1376 ok(ref
== old_d3d_ref
, "IDirect3D2 refcount is %u\n", ref
);
1378 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1379 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1380 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
1381 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1382 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1383 /* NULL iid: Segfaults */
1385 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirect3DViewport
, (void **)&viewport
);
1386 ok(SUCCEEDED(hr
), "Failed to QI IDirect3DViewport, hr %#x.\n", hr
);
1389 ref
= get_refcount((IUnknown
*)viewport
);
1390 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1391 ref
= get_refcount((IUnknown
*)viewport2
);
1392 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1393 IDirect3DViewport_Release(viewport
);
1397 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IDirect3DViewport3
, (void **)&viewport3
);
1398 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
, "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1401 ref
= get_refcount((IUnknown
*)viewport2
);
1402 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1403 ref
= get_refcount((IUnknown
*)viewport3
);
1404 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1405 IDirect3DViewport3_Release(viewport3
);
1408 hr
= IDirect3DViewport2_QueryInterface(viewport2
, &IID_IUnknown
, (void **)&unknown
);
1409 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1412 ref
= get_refcount((IUnknown
*)viewport2
);
1413 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1414 ref
= get_refcount(unknown
);
1415 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1416 IUnknown_Release(unknown
);
1419 /* AddViewport(NULL): Segfault */
1420 hr
= IDirect3DDevice2_DeleteViewport(device
, NULL
);
1421 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1422 hr
= IDirect3DDevice2_GetCurrentViewport(device
, NULL
);
1423 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1425 hr
= IDirect3D2_CreateViewport(d3d
, &another_vp
, NULL
);
1426 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1428 /* Setting a viewport not in the viewport list fails */
1429 hr
= IDirect3DDevice2_SetCurrentViewport(device
, another_vp
);
1430 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1432 hr
= IDirect3DDevice2_AddViewport(device
, viewport2
);
1433 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1434 ref
= get_refcount((IUnknown
*) viewport2
);
1435 ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1436 hr
= IDirect3DDevice2_AddViewport(device
, another_vp
);
1437 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1438 ref
= get_refcount((IUnknown
*) another_vp
);
1439 ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1441 test_vp
= (IDirect3DViewport2
*) 0xbaadc0de;
1442 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1443 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1444 ok(test_vp
== (IDirect3DViewport2
*) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp
);
1446 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
1447 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1448 ref
= get_refcount((IUnknown
*) viewport2
);
1449 ok(ref
== 3, "viewport2 refcount is %d\n", ref
);
1450 ref
= get_refcount((IUnknown
*) device
);
1451 ok(ref
== 1, "device refcount is %d\n", ref
);
1454 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1455 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1456 ok(test_vp
== viewport2
, "Got unexpected viewport %p\n", test_vp
);
1457 ref
= get_refcount((IUnknown
*) viewport2
);
1458 ok(ref
== 4, "viewport2 refcount is %d\n", ref
);
1459 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1461 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1463 /* Cannot set the viewport to NULL */
1464 hr
= IDirect3DDevice2_SetCurrentViewport(device
, NULL
);
1465 ok(hr
== DDERR_INVALIDPARAMS
, "Failed to set viewport to NULL, hr %#x.\n", hr
);
1467 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1468 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1469 ok(test_vp
== viewport2
, "Got unexpected viewport %p\n", test_vp
);
1470 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1472 /* SetCurrentViewport properly releases the old viewport's reference */
1473 hr
= IDirect3DDevice2_SetCurrentViewport(device
, another_vp
);
1474 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1475 ref
= get_refcount((IUnknown
*) viewport2
);
1476 ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1477 ref
= get_refcount((IUnknown
*) another_vp
);
1478 ok(ref
== 3, "another_vp refcount is %d\n", ref
);
1480 /* Deleting the viewport removes the reference added by AddViewport, but not
1481 * the one added by SetCurrentViewport. */
1482 hr
= IDirect3DDevice2_DeleteViewport(device
, another_vp
);
1483 ok(SUCCEEDED(hr
), "Failed to delete viewport from device, hr %#x.\n", hr
);
1484 ref
= get_refcount((IUnknown
*) another_vp
);
1485 todo_wine
ok(ref
== 2, "IDirect3DViewport2 refcount is %d\n", ref
);
1487 /* GetCurrentViewport fails though */
1489 hr
= IDirect3DDevice2_GetCurrentViewport(device
, &test_vp
);
1490 ok(hr
== D3DERR_NOCURRENTVIEWPORT
, "Got unexpected hr %#x.\n", hr
);
1491 ok(test_vp
== NULL
, "Got unexpected viewport %p\n", test_vp
);
1492 if(test_vp
) IDirect3DViewport2_Release(test_vp
);
1494 /* Setting a different viewport does not free the leaked reference. How
1495 * do I get rid of it? Leak the viewport for now. */
1496 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
1497 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1498 ref
= get_refcount((IUnknown
*) viewport2
);
1499 ok(ref
== 3, "viewport2 refcount is %d\n", ref
);
1500 ref
= get_refcount((IUnknown
*) another_vp
);
1501 todo_wine
ok(ref
== 2, "another_vp refcount is %d\n", ref
);
1503 /* Destroying the device removes the viewport, but does not free the reference
1504 * added by SetCurrentViewport. */
1505 IDirect3DDevice2_Release(device
);
1506 ref
= get_refcount((IUnknown
*) viewport2
);
1507 todo_wine
ok(ref
== 2, "viewport2 refcount is %d\n", ref
);
1509 IDirect3DViewport2_Release(another_vp
);
1510 IDirect3DViewport2_Release(viewport2
);
1511 IDirect3D2_Release(d3d
);
1512 DestroyWindow(window
);
1513 IDirectDraw2_Release(ddraw
);
1516 static void test_zenable(void)
1518 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1519 static D3DTLVERTEX tquad
[] =
1521 {{ 0.0f
}, {480.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1522 {{ 0.0f
}, { 0.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1523 {{640.0f
}, {480.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1524 {{640.0f
}, { 0.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1526 IDirect3DMaterial2
*background
;
1527 IDirect3DViewport2
*viewport
;
1528 IDirect3DDevice2
*device
;
1529 IDirectDrawSurface
*rt
;
1530 IDirectDraw2
*ddraw
;
1537 window
= create_window();
1538 ddraw
= create_ddraw();
1539 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1540 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1542 skip("Failed to create a 3D device, skipping test.\n");
1543 IDirectDraw2_Release(ddraw
);
1544 DestroyWindow(window
);
1548 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1549 viewport
= create_viewport(device
, 0, 0, 640, 480);
1550 viewport_set_background(device
, viewport
, background
);
1551 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1552 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1554 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1555 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1557 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1558 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1559 hr
= IDirect3DDevice2_BeginScene(device
);
1560 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1561 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, tquad
, 4, 0);
1562 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1563 hr
= IDirect3DDevice2_EndScene(device
);
1564 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1566 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1567 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1568 for (i
= 0; i
< 4; ++i
)
1570 for (j
= 0; j
< 4; ++j
)
1572 x
= 80 * ((2 * j
) + 1);
1573 y
= 60 * ((2 * i
) + 1);
1574 color
= get_surface_color(rt
, x
, y
);
1575 ok(compare_color(color
, 0x0000ff00, 1),
1576 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1579 IDirectDrawSurface_Release(rt
);
1581 destroy_viewport(device
, viewport
);
1582 destroy_material(background
);
1583 IDirect3DDevice2_Release(device
);
1584 IDirectDraw2_Release(ddraw
);
1585 DestroyWindow(window
);
1588 static void test_ck_rgba(void)
1590 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1591 static D3DTLVERTEX tquad
[] =
1593 {{ 0.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1594 {{ 0.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1595 {{640.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1596 {{640.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1597 {{ 0.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1598 {{ 0.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1599 {{640.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1600 {{640.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1604 D3DCOLOR fill_color
;
1607 D3DCOLOR result1
, result1_broken
;
1608 D3DCOLOR result2
, result2_broken
;
1612 /* r200 on Windows doesn't check the alpha component when applying the color
1613 * key, so the key matches on every texel. */
1614 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1615 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1616 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1617 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1618 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1619 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1620 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1621 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1624 D3DTEXTUREHANDLE texture_handle
;
1625 IDirect3DMaterial2
*background
;
1626 IDirectDrawSurface
*surface
;
1627 IDirect3DViewport2
*viewport
;
1628 IDirect3DTexture2
*texture
;
1629 DDSURFACEDESC surface_desc
;
1630 IDirect3DDevice2
*device
;
1631 IDirectDrawSurface
*rt
;
1632 IDirectDraw2
*ddraw
;
1639 window
= create_window();
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
< ARRAY_SIZE(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
= create_window();
1771 ddraw
= create_ddraw();
1772 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1773 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1775 skip("Failed to create a 3D device, skipping test.\n");
1776 IDirectDraw2_Release(ddraw
);
1777 DestroyWindow(window
);
1781 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
1782 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1784 background
= create_diffuse_material(device
, 0.0, 1.0f
, 0.0f
, 1.0f
);
1785 viewport
= create_viewport(device
, 0, 0, 640, 480);
1786 viewport_set_background(device
, viewport
, background
);
1787 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
1788 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
1790 memset(&surface_desc
, 0, sizeof(surface_desc
));
1791 surface_desc
.dwSize
= sizeof(surface_desc
);
1792 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1793 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1794 surface_desc
.dwWidth
= 256;
1795 surface_desc
.dwHeight
= 256;
1796 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1797 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1798 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1799 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1800 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1801 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1802 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1803 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1804 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1805 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1806 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
1807 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1808 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
1809 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1810 IDirect3DTexture_Release(texture
);
1812 memset(&fx
, 0, sizeof(fx
));
1813 fx
.dwSize
= sizeof(fx
);
1814 U5(fx
).dwFillColor
= 0x000000ff;
1815 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1816 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1818 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1819 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1820 hr
= IDirect3DDevice2_BeginScene(device
);
1821 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1822 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1823 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
1824 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1825 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1826 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1827 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1828 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1829 hr
= IDirect3DDevice2_EndScene(device
);
1830 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1831 color
= get_surface_color(rt
, 320, 240);
1832 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1834 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1835 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1836 hr
= IDirect3DDevice2_BeginScene(device
);
1837 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1838 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1839 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1840 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &tquad
[0], 4, 0);
1841 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1842 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1843 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1844 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1845 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1846 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
1847 hr
= IDirect3DDevice2_EndScene(device
);
1848 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1849 color
= get_surface_color(rt
, 320, 240);
1850 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1852 IDirectDrawSurface_Release(surface
);
1853 destroy_viewport(device
, viewport
);
1854 destroy_material(background
);
1855 IDirectDrawSurface_Release(rt
);
1856 IDirect3DDevice2_Release(device
);
1857 IDirectDraw2_Release(ddraw
);
1858 DestroyWindow(window
);
1861 static void test_ck_complex(void)
1863 IDirectDrawSurface
*surface
, *mipmap
, *tmp
;
1864 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
1865 DDSURFACEDESC surface_desc
;
1866 IDirect3DDevice2
*device
;
1867 DDCOLORKEY color_key
;
1868 IDirectDraw2
*ddraw
;
1874 window
= create_window();
1875 ddraw
= create_ddraw();
1876 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1877 if (!(device
= create_device(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1879 skip("Failed to create a 3D device, skipping test.\n");
1880 DestroyWindow(window
);
1881 IDirectDraw2_Release(ddraw
);
1884 IDirect3DDevice2_Release(device
);
1886 memset(&surface_desc
, 0, sizeof(surface_desc
));
1887 surface_desc
.dwSize
= sizeof(surface_desc
);
1888 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1889 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1890 surface_desc
.dwWidth
= 128;
1891 surface_desc
.dwHeight
= 128;
1892 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1893 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1895 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1896 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1897 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1898 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1899 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1900 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1901 memset(&color_key
, 0, sizeof(color_key
));
1902 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1903 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1904 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1905 color_key
.dwColorSpaceLowValue
);
1906 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1907 color_key
.dwColorSpaceHighValue
);
1910 IDirectDrawSurface_AddRef(mipmap
);
1911 for (i
= 0; i
< 7; ++i
)
1913 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1914 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1916 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1917 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1918 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1919 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1920 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1921 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x, i %u.\n", hr
, i
);
1922 memset(&color_key
, 0, sizeof(color_key
));
1923 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1924 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x, i %u.\n", hr
, i
);
1925 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1926 color_key
.dwColorSpaceLowValue
, i
);
1927 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1928 color_key
.dwColorSpaceHighValue
, i
);
1930 IDirectDrawSurface_Release(mipmap
);
1934 memset(&color_key
, 0, sizeof(color_key
));
1935 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1936 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1937 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1938 color_key
.dwColorSpaceLowValue
);
1939 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1940 color_key
.dwColorSpaceHighValue
);
1942 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1943 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1944 IDirectDrawSurface_Release(mipmap
);
1945 refcount
= IDirectDrawSurface_Release(surface
);
1946 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1948 memset(&surface_desc
, 0, sizeof(surface_desc
));
1949 surface_desc
.dwSize
= sizeof(surface_desc
);
1950 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1951 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1952 surface_desc
.dwBackBufferCount
= 1;
1953 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1954 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1956 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1957 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1958 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1959 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1960 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1961 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1962 memset(&color_key
, 0, sizeof(color_key
));
1963 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1964 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1965 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1966 color_key
.dwColorSpaceLowValue
);
1967 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1968 color_key
.dwColorSpaceHighValue
);
1970 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
1971 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
1973 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1974 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1975 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1976 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1977 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1978 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1979 memset(&color_key
, 0, sizeof(color_key
));
1980 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1981 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1982 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1983 color_key
.dwColorSpaceLowValue
);
1984 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1985 color_key
.dwColorSpaceHighValue
);
1987 IDirectDrawSurface_Release(tmp
);
1989 refcount
= IDirectDrawSurface_Release(surface
);
1990 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1991 refcount
= IDirectDraw2_Release(ddraw
);
1992 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1993 DestroyWindow(window
);
1999 REFIID refcount_iid
;
2003 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
2004 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
2006 ULONG refcount
, expected_refcount
;
2007 IUnknown
*iface1
, *iface2
;
2011 for (i
= 0; i
< entry_count
; ++i
)
2013 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
2014 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
2017 for (j
= 0; j
< entry_count
; ++j
)
2019 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
2020 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
2023 expected_refcount
= 0;
2024 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
2025 ++expected_refcount
;
2026 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
2027 ++expected_refcount
;
2028 refcount
= IUnknown_Release(iface2
);
2029 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2030 refcount
, test_name
, i
, j
, expected_refcount
);
2034 expected_refcount
= 0;
2035 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
2036 ++expected_refcount
;
2037 refcount
= IUnknown_Release(iface1
);
2038 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2039 refcount
, test_name
, i
, expected_refcount
);
2044 static void test_surface_qi(void)
2046 static const struct qi_test tests
[] =
2048 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface
, S_OK
},
2049 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface
, S_OK
},
2050 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
2051 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2052 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
2053 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
2054 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
2055 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
2056 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
2057 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
2058 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
2059 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
2060 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
2061 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
2062 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
2063 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
2064 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
2065 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
2066 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
2067 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
2068 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
2069 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
2070 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
2071 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
2072 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
2073 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
2074 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
2075 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
2076 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
2077 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
2078 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
2079 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
2080 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
2081 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
2082 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
2083 {NULL
, NULL
, E_INVALIDARG
},
2086 IDirectDrawSurface
*surface
;
2087 DDSURFACEDESC surface_desc
;
2088 IDirect3DDevice2
*device
;
2089 IDirectDraw2
*ddraw
;
2093 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2095 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2099 window
= create_window();
2100 ddraw
= create_ddraw();
2101 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2102 /* Try to create a D3D device to see if the ddraw implementation supports
2103 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2104 * doesn't support e.g. the IDirect3DTexture interfaces. */
2105 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
2107 skip("Failed to create a 3D device, skipping test.\n");
2108 IDirectDraw2_Release(ddraw
);
2109 DestroyWindow(window
);
2112 IDirect3DDevice_Release(device
);
2114 memset(&surface_desc
, 0, sizeof(surface_desc
));
2115 surface_desc
.dwSize
= sizeof(surface_desc
);
2116 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2117 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
2118 surface_desc
.dwWidth
= 512;
2119 surface_desc
.dwHeight
= 512;
2120 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, (IDirectDrawSurface
**)0xdeadbeef, NULL
);
2121 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
2122 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
2123 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2125 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface
, tests
, ARRAY_SIZE(tests
));
2127 IDirectDrawSurface_Release(surface
);
2128 IDirectDraw2_Release(ddraw
);
2129 DestroyWindow(window
);
2132 static void test_device_qi(void)
2134 static const struct qi_test tests
[] =
2136 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
2137 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
2138 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
2139 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
2140 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
2141 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
2142 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
2143 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
2144 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
2145 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
2146 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
2147 {&IID_IDirect3DDevice2
, &IID_IDirect3DDevice2
, S_OK
},
2148 {&IID_IDirect3DDevice
, &IID_IDirect3DDevice2
, S_OK
},
2149 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
2150 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
2151 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
2152 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
2153 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
2154 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
2155 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
2156 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
2157 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
2158 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
2159 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
2160 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
2161 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
2162 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
2163 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
2164 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
2165 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
2166 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
2167 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
2168 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
2169 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
2170 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
2171 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
2172 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
2173 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
2174 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
2175 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
2176 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
2177 {&IID_IUnknown
, &IID_IDirect3DDevice2
, S_OK
},
2180 IDirect3DDevice2
*device
;
2181 IDirectDraw2
*ddraw
;
2184 window
= create_window();
2185 ddraw
= create_ddraw();
2186 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2187 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
2189 skip("Failed to create a 3D device, skipping test.\n");
2190 IDirectDraw2_Release(ddraw
);
2191 DestroyWindow(window
);
2195 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice2
, tests
, ARRAY_SIZE(tests
));
2197 IDirect3DDevice2_Release(device
);
2198 IDirectDraw2_Release(ddraw
);
2199 DestroyWindow(window
);
2202 static void test_wndproc(void)
2204 LONG_PTR proc
, ddraw_proc
;
2205 IDirectDraw2
*ddraw
;
2211 static struct message messages
[] =
2213 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2214 {WM_MOVE
, FALSE
, 0},
2215 {WM_SIZE
, FALSE
, 0},
2216 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2217 {WM_ACTIVATE
, FALSE
, 0},
2218 {WM_SETFOCUS
, FALSE
, 0},
2222 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2223 ddraw
= create_ddraw();
2224 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2226 wc
.lpfnWndProc
= test_proc
;
2227 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2228 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2230 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2231 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2233 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2234 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2235 (LONG_PTR
)test_proc
, proc
);
2236 expect_messages
= messages
;
2237 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2238 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2239 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2240 expect_messages
= NULL
;
2241 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2242 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2243 (LONG_PTR
)test_proc
, proc
);
2244 ref
= IDirectDraw2_Release(ddraw
);
2245 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2246 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2247 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2248 (LONG_PTR
)test_proc
, proc
);
2250 /* DDSCL_NORMAL doesn't. */
2251 ddraw
= create_ddraw();
2252 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2253 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2254 (LONG_PTR
)test_proc
, proc
);
2255 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2256 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2257 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2258 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2259 (LONG_PTR
)test_proc
, proc
);
2260 ref
= IDirectDraw2_Release(ddraw
);
2261 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2262 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2263 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2264 (LONG_PTR
)test_proc
, proc
);
2266 /* The original window proc is only restored by ddraw if the current
2267 * window proc matches the one ddraw set. This also affects switching
2268 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2269 ddraw
= create_ddraw();
2270 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2271 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2272 (LONG_PTR
)test_proc
, proc
);
2273 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2274 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2275 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2276 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2277 (LONG_PTR
)test_proc
, proc
);
2279 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2280 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2281 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2282 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2283 (LONG_PTR
)test_proc
, proc
);
2284 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2285 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2286 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2287 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2288 (LONG_PTR
)test_proc
, proc
);
2289 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2290 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2291 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2292 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2293 (LONG_PTR
)DefWindowProcA
, proc
);
2294 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2295 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2296 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2297 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2298 (LONG_PTR
)DefWindowProcA
, proc
);
2299 ref
= IDirectDraw2_Release(ddraw
);
2300 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2301 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2302 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2303 (LONG_PTR
)test_proc
, proc
);
2305 ddraw
= create_ddraw();
2306 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2307 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2308 (LONG_PTR
)test_proc
, proc
);
2309 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2310 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2311 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2312 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2313 (LONG_PTR
)test_proc
, proc
);
2314 ref
= IDirectDraw2_Release(ddraw
);
2315 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2316 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2317 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2318 (LONG_PTR
)DefWindowProcA
, proc
);
2320 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2321 expect_messages
= NULL
;
2322 DestroyWindow(window
);
2323 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2326 static void test_window_style(void)
2328 LONG style
, exstyle
, tmp
, expected_style
;
2329 RECT fullscreen_rect
, r
;
2330 IDirectDraw2
*ddraw
;
2336 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2337 0, 0, 100, 100, 0, 0, 0, 0);
2338 ddraw
= create_ddraw();
2339 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2341 style
= GetWindowLongA(window
, GWL_STYLE
);
2342 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2343 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2345 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2346 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2348 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2349 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2350 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2351 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2353 GetWindowRect(window
, &r
);
2354 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
2355 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
2356 GetClientRect(window
, &r
);
2357 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2359 ret
= SetForegroundWindow(GetDesktopWindow());
2360 ok(ret
, "Failed to set foreground window.\n");
2362 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2363 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2364 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2365 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2367 ret
= SetForegroundWindow(window
);
2368 ok(ret
, "Failed to set foreground window.\n");
2369 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2370 * the next tests expect this. */
2371 ShowWindow(window
, SW_HIDE
);
2373 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2374 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2376 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2377 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2378 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2379 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2381 ShowWindow(window
, SW_SHOW
);
2382 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2383 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2385 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2386 expected_style
= style
| WS_VISIBLE
;
2387 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2388 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2389 expected_style
= exstyle
| WS_EX_TOPMOST
;
2390 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2392 ret
= SetForegroundWindow(GetDesktopWindow());
2393 ok(ret
, "Failed to set foreground window.\n");
2394 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2395 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2396 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2397 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2398 expected_style
= exstyle
| WS_EX_TOPMOST
;
2399 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2401 ref
= IDirectDraw2_Release(ddraw
);
2402 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2404 DestroyWindow(window
);
2407 static void test_redundant_mode_set(void)
2409 DDSURFACEDESC surface_desc
= {0};
2410 IDirectDraw2
*ddraw
;
2416 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2417 0, 0, 100, 100, 0, 0, 0, 0);
2418 ddraw
= create_ddraw();
2419 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2421 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2422 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2424 surface_desc
.dwSize
= sizeof(surface_desc
);
2425 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
2426 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
2428 hr
= IDirectDraw2_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2429 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2430 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2432 GetWindowRect(window
, &q
);
2436 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2437 GetWindowRect(window
, &s
);
2438 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2440 hr
= IDirectDraw2_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2441 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2442 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2444 GetWindowRect(window
, &s
);
2445 ok(EqualRect(&r
, &s
) || broken(EqualRect(&q
, &s
) /* Windows 10 */),
2446 "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2448 ref
= IDirectDraw2_Release(ddraw
);
2449 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2451 DestroyWindow(window
);
2454 static SIZE screen_size
, screen_size2
;
2456 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2458 if (message
== WM_SIZE
)
2460 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2461 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2464 return test_proc(hwnd
, message
, wparam
, lparam
);
2467 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2469 if (message
== WM_SIZE
)
2471 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2472 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2475 return test_proc(hwnd
, message
, wparam
, lparam
);
2478 struct test_coop_level_mode_set_enum_param
2480 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2483 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC
*surface_desc
, void *context
)
2485 struct test_coop_level_mode_set_enum_param
*param
= context
;
2487 if (U1(surface_desc
->ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2488 return DDENUMRET_OK
;
2489 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2490 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2491 return DDENUMRET_OK
;
2493 if (!param
->ddraw_width
)
2495 param
->ddraw_width
= surface_desc
->dwWidth
;
2496 param
->ddraw_height
= surface_desc
->dwHeight
;
2497 return DDENUMRET_OK
;
2499 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2500 return DDENUMRET_OK
;
2502 param
->user32_width
= surface_desc
->dwWidth
;
2503 param
->user32_height
= surface_desc
->dwHeight
;
2504 return DDENUMRET_CANCEL
;
2507 static void test_coop_level_mode_set(void)
2509 IDirectDrawSurface
*primary
;
2510 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2511 IDirectDraw2
*ddraw
;
2514 HWND window
, window2
;
2518 struct test_coop_level_mode_set_enum_param param
;
2523 static const struct message exclusive_messages
[] =
2525 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2526 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2527 {WM_SIZE
, FALSE
, 0},
2528 {WM_DISPLAYCHANGE
, FALSE
, 0},
2531 static const struct message exclusive_focus_loss_messages
[] =
2533 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2534 {WM_DISPLAYCHANGE
, FALSE
, 0},
2535 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2536 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2537 * SW_MINIMIZED, causing a recursive window activation that does not
2538 * produce the same result in Wine yet. Ignore the difference for now.
2539 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2540 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2541 {WM_MOVE
, FALSE
, 0},
2542 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2543 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2546 static const struct message exclusive_focus_restore_messages
[] =
2548 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2549 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2550 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2551 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2552 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2553 /* Native redundantly sets the window size here. */
2554 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2555 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2556 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2557 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2560 static const struct message sc_restore_messages
[] =
2562 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2563 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2564 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2565 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2568 static const struct message sc_minimize_messages
[] =
2570 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2571 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2572 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2573 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2576 static const struct message sc_maximize_messages
[] =
2578 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2579 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2580 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2581 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2585 static const struct message normal_messages
[] =
2587 {WM_DISPLAYCHANGE
, FALSE
, 0},
2591 ddraw
= create_ddraw();
2592 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2594 memset(¶m
, 0, sizeof(param
));
2595 hr
= IDirectDraw2_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2596 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2597 ref
= IDirectDraw2_Release(ddraw
);
2598 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2600 if (!param
.user32_height
)
2602 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2606 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2607 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2608 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2610 memset(&devmode
, 0, sizeof(devmode
));
2611 devmode
.dmSize
= sizeof(devmode
);
2612 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2613 devmode
.dmPelsWidth
= param
.user32_width
;
2614 devmode
.dmPelsHeight
= param
.user32_height
;
2615 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2616 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2618 ddraw
= create_ddraw();
2619 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2621 wc
.lpfnWndProc
= mode_set_proc
;
2622 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2623 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2624 wc
.lpfnWndProc
= mode_set_proc2
;
2625 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2626 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2628 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2629 0, 0, 100, 100, 0, 0, 0, 0);
2630 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2631 0, 0, 100, 100, 0, 0, 0, 0);
2633 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2634 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2636 GetWindowRect(window
, &r
);
2637 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2638 wine_dbgstr_rect(&r
));
2640 memset(&ddsd
, 0, sizeof(ddsd
));
2641 ddsd
.dwSize
= sizeof(ddsd
);
2642 ddsd
.dwFlags
= DDSD_CAPS
;
2643 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2645 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2646 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2647 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2648 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2649 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2650 param
.user32_width
, ddsd
.dwWidth
);
2651 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2652 param
.user32_height
, ddsd
.dwHeight
);
2654 GetWindowRect(window
, &r
);
2655 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2656 wine_dbgstr_rect(&r
));
2658 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2659 expect_messages
= exclusive_messages
;
2663 hr
= IDirectDrawSurface_IsLost(primary
);
2664 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2665 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2666 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2667 hr
= IDirectDrawSurface_IsLost(primary
);
2668 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2670 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2671 expect_messages
= NULL
;
2672 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2673 "Expected screen size %ux%u, got %ux%u.\n",
2674 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2676 GetWindowRect(window
, &r
);
2677 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2678 wine_dbgstr_rect(&r
));
2680 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2681 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2682 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2683 param
.user32_width
, ddsd
.dwWidth
);
2684 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2685 param
.user32_height
, ddsd
.dwHeight
);
2686 IDirectDrawSurface_Release(primary
);
2688 memset(&ddsd
, 0, sizeof(ddsd
));
2689 ddsd
.dwSize
= sizeof(ddsd
);
2690 ddsd
.dwFlags
= DDSD_CAPS
;
2691 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2693 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2694 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2695 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2696 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2697 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2698 param
.ddraw_width
, ddsd
.dwWidth
);
2699 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2700 param
.ddraw_height
, ddsd
.dwHeight
);
2702 GetWindowRect(window
, &r
);
2703 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2704 wine_dbgstr_rect(&r
));
2706 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2707 expect_messages
= exclusive_messages
;
2711 hr
= IDirectDrawSurface_IsLost(primary
);
2712 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2713 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2714 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2715 hr
= IDirectDrawSurface_IsLost(primary
);
2716 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2718 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2719 expect_messages
= NULL
;
2720 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2721 "Expected screen size %ux%u, got %ux%u.\n",
2722 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2724 GetWindowRect(window
, &r
);
2725 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2726 wine_dbgstr_rect(&r
));
2728 expect_messages
= exclusive_focus_loss_messages
;
2729 ret
= SetForegroundWindow(GetDesktopWindow());
2730 ok(ret
, "Failed to set foreground window.\n");
2731 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2732 memset(&devmode
, 0, sizeof(devmode
));
2733 devmode
.dmSize
= sizeof(devmode
);
2734 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2735 ok(ret
, "Failed to get display mode.\n");
2736 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2737 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2738 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2740 expect_messages
= exclusive_focus_restore_messages
;
2741 ShowWindow(window
, SW_RESTORE
);
2742 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2744 GetWindowRect(window
, &r
);
2745 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2746 wine_dbgstr_rect(&r
));
2747 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2748 ok(ret
, "Failed to get display mode.\n");
2749 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2750 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2751 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2753 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2754 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2755 /* Normally the primary should be restored here. Unfortunately this causes the
2756 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2757 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2758 * the point of the GetSurfaceDesc call. */
2760 expect_messages
= sc_minimize_messages
;
2761 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2762 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2763 expect_messages
= NULL
;
2765 expect_messages
= sc_restore_messages
;
2766 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2767 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2768 expect_messages
= NULL
;
2770 expect_messages
= sc_maximize_messages
;
2771 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2772 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2773 expect_messages
= NULL
;
2775 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2776 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2778 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2779 expect_messages
= exclusive_messages
;
2783 hr
= IDirectDrawSurface_IsLost(primary
);
2784 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2785 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
2786 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2787 hr
= IDirectDrawSurface_IsLost(primary
);
2788 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2790 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2791 expect_messages
= NULL
;
2792 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2793 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2794 "Expected screen size %ux%u, got %ux%u.\n",
2795 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2797 GetWindowRect(window
, &r
);
2798 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2799 wine_dbgstr_rect(&r
));
2801 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2802 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2803 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2804 param
.ddraw_width
, ddsd
.dwWidth
);
2805 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2806 param
.ddraw_height
, ddsd
.dwHeight
);
2807 IDirectDrawSurface_Release(primary
);
2810 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2811 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2813 memset(&ddsd
, 0, sizeof(ddsd
));
2814 ddsd
.dwSize
= sizeof(ddsd
);
2815 ddsd
.dwFlags
= DDSD_CAPS
;
2816 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2818 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2819 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2820 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2821 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2822 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2823 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2824 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2825 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2827 GetWindowRect(window
, &r
);
2828 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2829 wine_dbgstr_rect(&r
));
2831 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2832 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2834 GetWindowRect(window
, &r
);
2835 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2836 wine_dbgstr_rect(&r
));
2838 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2839 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2840 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2841 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2842 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2843 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2844 IDirectDrawSurface_Release(primary
);
2846 memset(&ddsd
, 0, sizeof(ddsd
));
2847 ddsd
.dwSize
= sizeof(ddsd
);
2848 ddsd
.dwFlags
= DDSD_CAPS
;
2849 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2851 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2852 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2853 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2854 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2855 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2856 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2857 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2858 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2860 GetWindowRect(window
, &r
);
2861 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2862 wine_dbgstr_rect(&r
));
2864 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2865 expect_messages
= normal_messages
;
2869 hr
= IDirectDrawSurface_IsLost(primary
);
2870 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2871 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2872 devmode
.dmPelsWidth
= param
.user32_width
;
2873 devmode
.dmPelsHeight
= param
.user32_height
;
2874 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2875 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2876 hr
= IDirectDrawSurface_IsLost(primary
);
2877 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2879 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2880 expect_messages
= NULL
;
2881 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2883 GetWindowRect(window
, &r
);
2884 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2885 wine_dbgstr_rect(&r
));
2887 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2888 expect_messages
= normal_messages
;
2892 hr
= IDirectDrawSurface_Restore(primary
);
2893 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2894 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2895 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
2897 win_skip("Broken SetDisplayMode(), skipping remaining tests.\n");
2898 IDirectDrawSurface_Release(primary
);
2899 IDirectDraw2_Release(ddraw
);
2902 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2903 hr
= IDirectDrawSurface_Restore(primary
);
2904 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2905 hr
= IDirectDrawSurface_IsLost(primary
);
2906 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2908 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2909 expect_messages
= NULL
;
2910 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2912 GetWindowRect(window
, &r
);
2913 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2914 wine_dbgstr_rect(&r
));
2916 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2917 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2918 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2919 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2920 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2921 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2922 IDirectDrawSurface_Release(primary
);
2924 memset(&ddsd
, 0, sizeof(ddsd
));
2925 ddsd
.dwSize
= sizeof(ddsd
);
2926 ddsd
.dwFlags
= DDSD_CAPS
;
2927 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2929 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2930 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2931 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2932 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2933 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2934 param
.ddraw_width
, ddsd
.dwWidth
);
2935 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2936 param
.ddraw_height
, ddsd
.dwHeight
);
2938 GetWindowRect(window
, &r
);
2939 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2940 wine_dbgstr_rect(&r
));
2942 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2943 expect_messages
= normal_messages
;
2947 hr
= IDirectDrawSurface_IsLost(primary
);
2948 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2949 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2950 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2951 hr
= IDirectDrawSurface_IsLost(primary
);
2952 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2954 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2955 expect_messages
= NULL
;
2956 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2958 GetWindowRect(window
, &r
);
2959 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2960 wine_dbgstr_rect(&r
));
2962 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2963 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2964 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2965 param
.ddraw_width
, ddsd
.dwWidth
);
2966 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2967 param
.ddraw_height
, ddsd
.dwHeight
);
2968 IDirectDrawSurface_Release(primary
);
2970 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2971 ok(ret
, "Failed to get display mode.\n");
2972 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2973 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2974 "Expected resolution %ux%u, got %ux%u.\n",
2975 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2976 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2977 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2978 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2980 memset(&ddsd
, 0, sizeof(ddsd
));
2981 ddsd
.dwSize
= sizeof(ddsd
);
2982 ddsd
.dwFlags
= DDSD_CAPS
;
2983 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2985 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2986 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2987 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2988 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2989 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2990 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2991 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2992 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2994 GetWindowRect(window
, &r
);
2995 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2996 wine_dbgstr_rect(&r
));
2998 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2999 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
3000 * not DDSCL_FULLSCREEN. */
3001 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3002 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3004 GetWindowRect(window
, &r
);
3005 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3006 wine_dbgstr_rect(&r
));
3008 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3009 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3010 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3011 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3012 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3013 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3014 IDirectDrawSurface_Release(primary
);
3016 memset(&ddsd
, 0, sizeof(ddsd
));
3017 ddsd
.dwSize
= sizeof(ddsd
);
3018 ddsd
.dwFlags
= DDSD_CAPS
;
3019 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3021 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3022 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3023 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3024 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3025 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3026 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3027 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3028 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3030 GetWindowRect(window
, &r
);
3031 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3032 wine_dbgstr_rect(&r
));
3034 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3035 expect_messages
= normal_messages
;
3039 hr
= IDirectDrawSurface_IsLost(primary
);
3040 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3041 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
3042 devmode
.dmPelsWidth
= param
.user32_width
;
3043 devmode
.dmPelsHeight
= param
.user32_height
;
3044 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3045 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3046 hr
= IDirectDrawSurface_IsLost(primary
);
3047 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3049 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3050 expect_messages
= NULL
;
3051 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3053 GetWindowRect(window
, &r
);
3054 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3055 wine_dbgstr_rect(&r
));
3057 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3058 expect_messages
= normal_messages
;
3062 hr
= IDirectDrawSurface_Restore(primary
);
3063 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
3064 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3065 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3066 hr
= IDirectDrawSurface_Restore(primary
);
3067 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
3068 hr
= IDirectDrawSurface_IsLost(primary
);
3069 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3071 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3072 expect_messages
= NULL
;
3073 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3075 GetWindowRect(window
, &r
);
3076 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3077 wine_dbgstr_rect(&r
));
3079 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3080 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3081 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3082 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3083 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3084 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3085 IDirectDrawSurface_Release(primary
);
3087 memset(&ddsd
, 0, sizeof(ddsd
));
3088 ddsd
.dwSize
= sizeof(ddsd
);
3089 ddsd
.dwFlags
= DDSD_CAPS
;
3090 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3092 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3093 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3094 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3095 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3096 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3097 param
.ddraw_width
, ddsd
.dwWidth
);
3098 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3099 param
.ddraw_height
, ddsd
.dwHeight
);
3101 GetWindowRect(window
, &r
);
3102 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3103 wine_dbgstr_rect(&r
));
3105 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3106 expect_messages
= normal_messages
;
3110 hr
= IDirectDrawSurface_IsLost(primary
);
3111 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
3112 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3113 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3114 hr
= IDirectDrawSurface_IsLost(primary
);
3115 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
3117 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3118 expect_messages
= NULL
;
3119 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
3121 GetWindowRect(window
, &r
);
3122 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3123 wine_dbgstr_rect(&r
));
3125 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3126 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3127 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3128 param
.ddraw_width
, ddsd
.dwWidth
);
3129 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3130 param
.ddraw_height
, ddsd
.dwHeight
);
3131 IDirectDrawSurface_Release(primary
);
3133 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3134 ok(ret
, "Failed to get display mode.\n");
3135 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3136 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
3137 "Expected resolution %ux%u, got %ux%u.\n",
3138 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3139 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3140 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3141 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3143 memset(&ddsd
, 0, sizeof(ddsd
));
3144 ddsd
.dwSize
= sizeof(ddsd
);
3145 ddsd
.dwFlags
= DDSD_CAPS
;
3146 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3148 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3149 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3150 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3151 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3152 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3153 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3154 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3155 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3156 IDirectDrawSurface_Release(primary
);
3158 GetWindowRect(window
, &r
);
3159 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3160 wine_dbgstr_rect(&r
));
3162 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
3163 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3164 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3165 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3166 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3168 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3169 expect_messages
= exclusive_messages
;
3173 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3174 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3176 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3177 expect_messages
= NULL
;
3178 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
3179 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
3180 "Expected screen size %ux%u, got %ux%u.\n",
3181 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
3182 screen_size
.cx
, screen_size
.cy
);
3184 GetWindowRect(window
, &r
);
3185 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3186 wine_dbgstr_rect(&r
));
3188 memset(&ddsd
, 0, sizeof(ddsd
));
3189 ddsd
.dwSize
= sizeof(ddsd
);
3190 ddsd
.dwFlags
= DDSD_CAPS
;
3191 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3193 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3194 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3195 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3196 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3197 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3198 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3199 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3200 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3201 IDirectDrawSurface_Release(primary
);
3203 /* The screen restore is a property of DDSCL_EXCLUSIVE */
3204 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
3205 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3206 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3207 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3209 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3210 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3212 memset(&ddsd
, 0, sizeof(ddsd
));
3213 ddsd
.dwSize
= sizeof(ddsd
);
3214 ddsd
.dwFlags
= DDSD_CAPS
;
3215 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3217 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3218 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3219 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3220 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3221 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3222 param
.ddraw_width
, ddsd
.dwWidth
);
3223 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3224 param
.ddraw_height
, ddsd
.dwHeight
);
3225 IDirectDrawSurface_Release(primary
);
3227 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3228 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3230 /* If the window is changed at the same time, messages are sent to the new window. */
3231 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3232 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3233 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3234 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3236 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3237 expect_messages
= exclusive_messages
;
3240 screen_size2
.cx
= 0;
3241 screen_size2
.cy
= 0;
3243 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3244 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3246 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3247 expect_messages
= NULL
;
3248 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
3249 screen_size
.cx
, screen_size
.cy
);
3250 ok(screen_size2
.cx
== registry_mode
.dmPelsWidth
&& screen_size2
.cy
== registry_mode
.dmPelsHeight
,
3251 "Expected screen size 2 %ux%u, got %ux%u.\n",
3252 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size2
.cx
, screen_size2
.cy
);
3254 GetWindowRect(window
, &r
);
3255 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
3256 wine_dbgstr_rect(&r
));
3257 GetWindowRect(window2
, &r
);
3258 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
3259 wine_dbgstr_rect(&r
));
3261 memset(&ddsd
, 0, sizeof(ddsd
));
3262 ddsd
.dwSize
= sizeof(ddsd
);
3263 ddsd
.dwFlags
= DDSD_CAPS
;
3264 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3266 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3267 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3268 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
3269 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3270 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3271 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3272 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3273 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3274 IDirectDrawSurface_Release(primary
);
3276 ref
= IDirectDraw2_Release(ddraw
);
3277 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3279 GetWindowRect(window
, &r
);
3280 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
3281 wine_dbgstr_rect(&r
));
3284 expect_messages
= NULL
;
3285 DestroyWindow(window
);
3286 DestroyWindow(window2
);
3287 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3288 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3291 static void test_coop_level_mode_set_multi(void)
3293 IDirectDraw2
*ddraw1
, *ddraw2
;
3299 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3300 0, 0, 100, 100, 0, 0, 0, 0);
3301 ddraw1
= create_ddraw();
3302 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3304 /* With just a single ddraw object, the display mode is restored on
3306 hr
= set_display_mode(ddraw1
, 800, 600);
3307 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
3309 win_skip("Broken SetDisplayMode(), skipping test.\n");
3310 IDirectDraw2_Release(ddraw1
);
3311 DestroyWindow(window
);
3314 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3315 w
= GetSystemMetrics(SM_CXSCREEN
);
3316 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3317 h
= GetSystemMetrics(SM_CYSCREEN
);
3318 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3320 ref
= IDirectDraw2_Release(ddraw1
);
3321 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3322 w
= GetSystemMetrics(SM_CXSCREEN
);
3323 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3324 h
= GetSystemMetrics(SM_CYSCREEN
);
3325 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3327 /* When there are multiple ddraw objects, the display mode is restored to
3328 * the initial mode, before the first SetDisplayMode() call. */
3329 ddraw1
= create_ddraw();
3330 hr
= set_display_mode(ddraw1
, 800, 600);
3331 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3332 w
= GetSystemMetrics(SM_CXSCREEN
);
3333 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3334 h
= GetSystemMetrics(SM_CYSCREEN
);
3335 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3337 ddraw2
= create_ddraw();
3338 hr
= set_display_mode(ddraw2
, 640, 480);
3339 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3340 w
= GetSystemMetrics(SM_CXSCREEN
);
3341 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3342 h
= GetSystemMetrics(SM_CYSCREEN
);
3343 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3345 ref
= IDirectDraw2_Release(ddraw2
);
3346 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3347 w
= GetSystemMetrics(SM_CXSCREEN
);
3348 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3349 h
= GetSystemMetrics(SM_CYSCREEN
);
3350 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3352 ref
= IDirectDraw2_Release(ddraw1
);
3353 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3354 w
= GetSystemMetrics(SM_CXSCREEN
);
3355 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3356 h
= GetSystemMetrics(SM_CYSCREEN
);
3357 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3359 /* Regardless of release ordering. */
3360 ddraw1
= create_ddraw();
3361 hr
= set_display_mode(ddraw1
, 800, 600);
3362 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3363 w
= GetSystemMetrics(SM_CXSCREEN
);
3364 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3365 h
= GetSystemMetrics(SM_CYSCREEN
);
3366 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3368 ddraw2
= create_ddraw();
3369 hr
= set_display_mode(ddraw2
, 640, 480);
3370 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3371 w
= GetSystemMetrics(SM_CXSCREEN
);
3372 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3373 h
= GetSystemMetrics(SM_CYSCREEN
);
3374 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3376 ref
= IDirectDraw2_Release(ddraw1
);
3377 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3378 w
= GetSystemMetrics(SM_CXSCREEN
);
3379 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3380 h
= GetSystemMetrics(SM_CYSCREEN
);
3381 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3383 ref
= IDirectDraw2_Release(ddraw2
);
3384 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3385 w
= GetSystemMetrics(SM_CXSCREEN
);
3386 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3387 h
= GetSystemMetrics(SM_CYSCREEN
);
3388 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3390 /* But only for ddraw objects that called SetDisplayMode(). */
3391 ddraw1
= create_ddraw();
3392 ddraw2
= create_ddraw();
3393 hr
= set_display_mode(ddraw2
, 640, 480);
3394 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3395 w
= GetSystemMetrics(SM_CXSCREEN
);
3396 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3397 h
= GetSystemMetrics(SM_CYSCREEN
);
3398 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3400 ref
= IDirectDraw2_Release(ddraw1
);
3401 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3402 w
= GetSystemMetrics(SM_CXSCREEN
);
3403 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3404 h
= GetSystemMetrics(SM_CYSCREEN
);
3405 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3407 ref
= IDirectDraw2_Release(ddraw2
);
3408 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3409 w
= GetSystemMetrics(SM_CXSCREEN
);
3410 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3411 h
= GetSystemMetrics(SM_CYSCREEN
);
3412 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3414 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3415 * restoring the display mode. */
3416 ddraw1
= create_ddraw();
3417 hr
= set_display_mode(ddraw1
, 800, 600);
3418 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3419 w
= GetSystemMetrics(SM_CXSCREEN
);
3420 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3421 h
= GetSystemMetrics(SM_CYSCREEN
);
3422 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3424 ddraw2
= create_ddraw();
3425 hr
= set_display_mode(ddraw2
, 640, 480);
3426 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3427 w
= GetSystemMetrics(SM_CXSCREEN
);
3428 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3429 h
= GetSystemMetrics(SM_CYSCREEN
);
3430 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3432 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3433 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3435 ref
= IDirectDraw2_Release(ddraw1
);
3436 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3437 w
= GetSystemMetrics(SM_CXSCREEN
);
3438 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3439 h
= GetSystemMetrics(SM_CYSCREEN
);
3440 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3442 ref
= IDirectDraw2_Release(ddraw2
);
3443 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3444 w
= GetSystemMetrics(SM_CXSCREEN
);
3445 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3446 h
= GetSystemMetrics(SM_CYSCREEN
);
3447 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3449 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3450 ddraw1
= create_ddraw();
3451 hr
= set_display_mode(ddraw1
, 800, 600);
3452 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3453 w
= GetSystemMetrics(SM_CXSCREEN
);
3454 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3455 h
= GetSystemMetrics(SM_CYSCREEN
);
3456 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3458 hr
= IDirectDraw2_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3459 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3461 ddraw2
= create_ddraw();
3462 hr
= set_display_mode(ddraw2
, 640, 480);
3463 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3465 ref
= IDirectDraw2_Release(ddraw1
);
3466 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3467 w
= GetSystemMetrics(SM_CXSCREEN
);
3468 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3469 h
= GetSystemMetrics(SM_CYSCREEN
);
3470 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3472 ref
= IDirectDraw2_Release(ddraw2
);
3473 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3474 w
= GetSystemMetrics(SM_CXSCREEN
);
3475 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3476 h
= GetSystemMetrics(SM_CYSCREEN
);
3477 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3479 DestroyWindow(window
);
3482 static void test_initialize(void)
3484 IDirectDraw2
*ddraw
;
3487 ddraw
= create_ddraw();
3488 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3490 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3491 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3492 IDirectDraw2_Release(ddraw
);
3495 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw2
, (void **)&ddraw
);
3496 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw2 instance, hr %#x.\n", hr
);
3497 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3498 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3499 hr
= IDirectDraw2_Initialize(ddraw
, NULL
);
3500 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3501 IDirectDraw2_Release(ddraw
);
3505 static void test_coop_level_surf_create(void)
3507 IDirectDrawSurface
*surface
;
3508 IDirectDraw2
*ddraw
;
3512 ddraw
= create_ddraw();
3513 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3515 memset(&ddsd
, 0, sizeof(ddsd
));
3516 ddsd
.dwSize
= sizeof(ddsd
);
3517 ddsd
.dwFlags
= DDSD_CAPS
;
3518 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3519 surface
= (void *)0xdeadbeef;
3520 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3521 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3522 ok(surface
== (void *)0xdeadbeef, "Got unexpected surface %p.\n", surface
);
3524 IDirectDraw2_Release(ddraw
);
3527 static void test_coop_level_multi_window(void)
3529 HWND window1
, window2
;
3530 IDirectDraw2
*ddraw
;
3533 window1
= create_window();
3534 window2
= create_window();
3535 ddraw
= create_ddraw();
3536 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3538 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3539 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3540 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3541 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3542 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3543 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3545 IDirectDraw2_Release(ddraw
);
3546 DestroyWindow(window2
);
3547 DestroyWindow(window1
);
3550 static void test_clear_rect_count(void)
3552 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3553 IDirect3DMaterial2
*white
, *red
, *green
, *blue
;
3554 IDirect3DViewport2
*viewport
;
3555 IDirect3DDevice2
*device
;
3556 IDirectDrawSurface
*rt
;
3557 IDirectDraw2
*ddraw
;
3562 window
= create_window();
3563 ddraw
= create_ddraw();
3564 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3565 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3567 skip("Failed to create a 3D device, skipping test.\n");
3568 IDirectDraw2_Release(ddraw
);
3569 DestroyWindow(window
);
3573 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
3574 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3576 white
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
3577 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
3578 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
3579 blue
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
3581 viewport
= create_viewport(device
, 0, 0, 640, 480);
3582 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
3583 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3585 viewport_set_background(device
, viewport
, white
);
3586 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3587 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3588 viewport_set_background(device
, viewport
, red
);
3589 hr
= IDirect3DViewport2_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3590 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3591 viewport_set_background(device
, viewport
, green
);
3592 hr
= IDirect3DViewport2_Clear(viewport
, 0, NULL
, D3DCLEAR_TARGET
);
3593 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3594 viewport_set_background(device
, viewport
, blue
);
3595 hr
= IDirect3DViewport2_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3596 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3598 color
= get_surface_color(rt
, 320, 240);
3599 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x000000ff, 1)),
3600 "Got unexpected color 0x%08x.\n", color
);
3602 IDirectDrawSurface_Release(rt
);
3603 destroy_viewport(device
, viewport
);
3604 destroy_material(white
);
3605 destroy_material(red
);
3606 destroy_material(green
);
3607 destroy_material(blue
);
3608 IDirect3DDevice2_Release(device
);
3609 IDirectDraw2_Release(ddraw
);
3610 DestroyWindow(window
);
3613 static BOOL
test_mode_restored(IDirectDraw2
*ddraw
, HWND window
)
3615 DDSURFACEDESC ddsd1
, ddsd2
;
3618 memset(&ddsd1
, 0, sizeof(ddsd1
));
3619 ddsd1
.dwSize
= sizeof(ddsd1
);
3620 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &ddsd1
);
3621 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3623 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3624 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3625 hr
= set_display_mode(ddraw
, 640, 480);
3626 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3627 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3628 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3630 memset(&ddsd2
, 0, sizeof(ddsd2
));
3631 ddsd2
.dwSize
= sizeof(ddsd2
);
3632 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &ddsd2
);
3633 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3634 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
3635 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3637 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
3640 static void test_coop_level_versions(void)
3646 IDirectDrawSurface
*surface
;
3647 IDirectDraw2
*ddraw2
;
3650 window
= create_window();
3651 ddraw2
= create_ddraw();
3652 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3653 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3654 restored
= test_mode_restored(ddraw2
, window
);
3655 ok(restored
, "Display mode not restored in new ddraw object\n");
3657 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3658 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3659 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3661 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3662 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3663 restored
= test_mode_restored(ddraw2
, window
);
3664 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3666 /* A successful one does */
3667 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3668 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3669 restored
= test_mode_restored(ddraw2
, window
);
3670 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3672 IDirectDraw_Release(ddraw
);
3673 IDirectDraw2_Release(ddraw2
);
3675 ddraw2
= create_ddraw();
3676 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3677 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3678 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3680 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
3681 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3682 restored
= test_mode_restored(ddraw2
, window
);
3683 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3685 IDirectDraw_Release(ddraw
);
3686 IDirectDraw2_Release(ddraw2
);
3688 /* A failing call does not restore the ddraw2+ behavior */
3689 ddraw2
= create_ddraw();
3690 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3691 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3692 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3694 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3695 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3696 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3697 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3698 restored
= test_mode_restored(ddraw2
, window
);
3699 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3701 IDirectDraw_Release(ddraw
);
3702 IDirectDraw2_Release(ddraw2
);
3704 /* Neither does a sequence of successful calls with the new interface */
3705 ddraw2
= create_ddraw();
3706 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3707 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3708 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3710 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3711 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3712 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3713 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3714 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_NORMAL
);
3715 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3717 restored
= test_mode_restored(ddraw2
, window
);
3718 ok(!restored
, "Display mode restored after ddraw1-ddraw2 SetCooperativeLevel() call sequence\n");
3719 IDirectDraw_Release(ddraw
);
3720 IDirectDraw2_Release(ddraw2
);
3722 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3723 ddraw2
= create_ddraw();
3724 ok(!!ddraw2
, "Failed to create a ddraw object.\n");
3725 hr
= IDirectDraw2_QueryInterface(ddraw2
, &IID_IDirectDraw
, (void **)&ddraw
);
3726 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3728 hr
= IDirectDraw2_SetCooperativeLevel(ddraw2
, window
, DDSCL_NORMAL
);
3729 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3731 memset(&ddsd
, 0, sizeof(ddsd
));
3732 ddsd
.dwSize
= sizeof(ddsd
);
3733 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
3734 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
3735 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
3736 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3737 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
3738 IDirectDrawSurface_Release(surface
);
3739 restored
= test_mode_restored(ddraw2
, window
);
3740 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
3742 IDirectDraw_Release(ddraw
);
3743 IDirectDraw2_Release(ddraw2
);
3744 DestroyWindow(window
);
3747 static void test_lighting_interface_versions(void)
3749 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3750 IDirect3DMaterial2
*emissive
, *background
;
3751 IDirect3DViewport2
*viewport
;
3752 IDirect3DDevice2
*device
;
3753 IDirectDrawSurface
*rt
;
3754 IDirectDraw2
*ddraw
;
3758 D3DMATERIALHANDLE mat_handle
;
3762 static D3DVERTEX quad
[] =
3764 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3765 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3766 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3767 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3769 static D3DLVERTEX lquad
[] =
3771 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3772 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3773 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3774 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3776 static D3DTLVERTEX tlquad
[] =
3778 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3779 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3780 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3781 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3785 D3DVERTEXTYPE vertextype
;
3787 DWORD d3drs_lighting
, d3drs_specular
;
3793 /* Lighting is enabled when D3DVT_VERTEX is used and D3DDP_DONOTLIGHT is not
3794 * set. D3DVT_VERTEX has diffuse = 0xffffffff and specular = 0x00000000, as
3795 * in later d3d versions */
3796 { D3DVT_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x0000ff00},
3797 { D3DVT_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
3798 { D3DVT_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3799 { D3DVT_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3800 { D3DVT_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x0000ff00},
3801 { D3DVT_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
3802 { D3DVT_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3803 { D3DVT_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3805 { D3DVT_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
3806 { D3DVT_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x00ff0000},
3807 { D3DVT_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3808 { D3DVT_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3809 { D3DVT_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
3810 { D3DVT_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x00ff8080},
3811 { D3DVT_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3812 { D3DVT_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3814 { D3DVT_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
3815 { D3DVT_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
3816 { D3DVT_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3817 { D3DVT_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3818 { D3DVT_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
3819 { D3DVT_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
3820 { D3DVT_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3821 { D3DVT_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3824 window
= create_window();
3825 ddraw
= create_ddraw();
3826 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3827 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3829 skip("Failed to create a 3D device, skipping test.\n");
3830 IDirectDraw2_Release(ddraw
);
3831 DestroyWindow(window
);
3835 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
3836 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3838 viewport
= create_viewport(device
, 0, 0, 640, 480);
3839 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
3840 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
3842 emissive
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
3843 hr
= IDirect3DMaterial2_GetHandle(emissive
, device
, &mat_handle
);
3844 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
3845 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
3846 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
3847 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
3848 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
3850 background
= create_diffuse_material(device
, 0.1f
, 0.1f
, 0.1f
, 0.1f
);
3851 viewport_set_background(device
, viewport
, background
);
3853 hr
= IDirect3DDevice2_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
3854 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
3855 ok(rs
== TRUE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected TRUE.\n", rs
);
3857 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
3859 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3860 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3862 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
3863 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
3864 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
3865 tests
[i
].d3drs_specular
);
3866 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
3868 hr
= IDirect3DDevice2_BeginScene(device
);
3869 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3870 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
3871 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
3872 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3873 hr
= IDirect3DDevice2_EndScene(device
);
3874 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3876 color
= get_surface_color(rt
, 320, 240);
3877 ok(compare_color(color
, tests
[i
].color
, 1),
3878 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3879 color
, tests
[i
].color
, i
);
3882 destroy_material(background
);
3883 destroy_material(emissive
);
3884 IDirectDrawSurface_Release(rt
);
3885 IDirect3DDevice2_Release(device
);
3886 ref
= IDirectDraw2_Release(ddraw
);
3887 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
3888 DestroyWindow(window
);
3894 IDirectDraw2
*ddraw
;
3897 } activateapp_testdata
;
3899 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
3901 if (message
== WM_ACTIVATEAPP
)
3903 if (activateapp_testdata
.ddraw
)
3906 activateapp_testdata
.received
= FALSE
;
3907 hr
= IDirectDraw2_SetCooperativeLevel(activateapp_testdata
.ddraw
,
3908 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
3909 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
3910 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3912 activateapp_testdata
.received
= TRUE
;
3915 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
3918 static void test_coop_level_activateapp(void)
3920 IDirectDraw2
*ddraw
;
3925 IDirectDrawSurface
*surface
;
3927 ddraw
= create_ddraw();
3928 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3930 wc
.lpfnWndProc
= activateapp_test_proc
;
3931 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
3932 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3934 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3935 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3937 /* Exclusive with window already active. */
3938 SetForegroundWindow(window
);
3939 activateapp_testdata
.received
= FALSE
;
3940 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3941 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3942 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
3943 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3944 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3946 /* Exclusive with window not active. */
3947 SetForegroundWindow(GetDesktopWindow());
3948 activateapp_testdata
.received
= FALSE
;
3949 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3950 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3951 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3952 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3953 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3955 /* Normal with window not active, then exclusive with the same window. */
3956 SetForegroundWindow(GetDesktopWindow());
3957 activateapp_testdata
.received
= FALSE
;
3958 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3959 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3960 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3961 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3962 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3963 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3964 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3965 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3967 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3968 SetForegroundWindow(GetDesktopWindow());
3969 activateapp_testdata
.received
= FALSE
;
3970 activateapp_testdata
.ddraw
= ddraw
;
3971 activateapp_testdata
.window
= window
;
3972 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
3973 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3974 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3975 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3976 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3977 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3979 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3980 * succeeding. Another switch to exclusive and back to normal is needed to release the
3981 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3982 * WM_ACTIVATEAPP messages. */
3983 activateapp_testdata
.ddraw
= NULL
;
3984 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3985 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3986 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3987 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3989 /* Setting DDSCL_NORMAL with recursive invocation. */
3990 SetForegroundWindow(GetDesktopWindow());
3991 activateapp_testdata
.received
= FALSE
;
3992 activateapp_testdata
.ddraw
= ddraw
;
3993 activateapp_testdata
.window
= window
;
3994 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
3995 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3996 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3997 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3999 /* DDraw is in exclusive mode now. */
4000 memset(&ddsd
, 0, sizeof(ddsd
));
4001 ddsd
.dwSize
= sizeof(ddsd
);
4002 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4003 ddsd
.dwBackBufferCount
= 1;
4004 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4005 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4006 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4007 IDirectDrawSurface_Release(surface
);
4009 /* Recover again, just to be sure. */
4010 activateapp_testdata
.ddraw
= NULL
;
4011 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4012 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4013 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4014 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4016 DestroyWindow(window
);
4017 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
4018 IDirectDraw2_Release(ddraw
);
4021 struct format_support_check
4023 const DDPIXELFORMAT
*format
;
4027 static HRESULT WINAPI
test_unsupported_formats_cb(DDSURFACEDESC
*desc
, void *ctx
)
4029 struct format_support_check
*format
= ctx
;
4031 if (!memcmp(format
->format
, &desc
->ddpfPixelFormat
, sizeof(*format
->format
)))
4033 format
->supported
= TRUE
;
4034 return DDENUMRET_CANCEL
;
4037 return DDENUMRET_OK
;
4040 static void test_unsupported_formats(void)
4043 BOOL expect_success
;
4045 IDirectDraw2
*ddraw
;
4046 IDirect3DDevice2
*device
;
4047 IDirectDrawSurface
*surface
;
4050 DWORD expected_caps
;
4061 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
4062 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
4068 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4069 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
4073 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
4075 window
= create_window();
4076 ddraw
= create_ddraw();
4077 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4078 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4080 skip("Failed to create a 3D device, skipping test.\n");
4081 IDirectDraw2_Release(ddraw
);
4082 DestroyWindow(window
);
4086 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++)
4088 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
4089 hr
= IDirect3DDevice2_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
4090 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4092 for (j
= 0; j
< ARRAY_SIZE(caps
); j
++)
4094 memset(&ddsd
, 0, sizeof(ddsd
));
4095 ddsd
.dwSize
= sizeof(ddsd
);
4096 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
4097 ddsd
.ddpfPixelFormat
= formats
[i
].fmt
;
4100 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
4102 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
4103 expect_success
= FALSE
;
4105 expect_success
= TRUE
;
4107 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4108 ok(SUCCEEDED(hr
) == expect_success
,
4109 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4110 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
4114 memset(&ddsd
, 0, sizeof(ddsd
));
4115 ddsd
.dwSize
= sizeof(ddsd
);
4116 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &ddsd
);
4117 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4119 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
4120 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4121 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
4122 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4123 else if (check
.supported
)
4124 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4126 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4128 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
4129 "Expected capability %#x, format %s, input cap %#x.\n",
4130 expected_caps
, formats
[i
].name
, caps
[j
]);
4132 IDirectDrawSurface_Release(surface
);
4136 IDirect3DDevice2_Release(device
);
4137 IDirectDraw2_Release(ddraw
);
4138 DestroyWindow(window
);
4141 static void test_rt_caps(void)
4143 PALETTEENTRY palette_entries
[256];
4144 IDirectDrawPalette
*palette
;
4145 IDirect3DDevice2
*device
;
4146 IDirectDraw2
*ddraw
;
4154 static const DDPIXELFORMAT p8_fmt
=
4156 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4157 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4162 const DDPIXELFORMAT
*pf
;
4165 HRESULT create_device_hr
;
4167 HRESULT alternative_set_rt_hr
;
4168 BOOL create_may_fail
;
4174 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4175 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4183 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4184 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4192 DDSCAPS_OFFSCREENPLAIN
,
4193 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4201 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4202 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4203 D3DERR_SURFACENOTINVIDMEM
,
4210 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4211 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4219 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4220 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4229 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4238 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4246 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4247 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4248 D3DERR_SURFACENOTINVIDMEM
,
4255 DDSCAPS_SYSTEMMEMORY
,
4256 DDSCAPS_SYSTEMMEMORY
,
4265 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4273 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4275 DDERR_NOPALETTEATTACHED
,
4282 DDSCAPS_OFFSCREENPLAIN
,
4283 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4291 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4292 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4293 DDERR_NOPALETTEATTACHED
,
4300 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4301 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4309 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
4310 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4312 DDERR_INVALIDPIXELFORMAT
,
4314 TRUE
/* AMD Evergreen */,
4318 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4319 ~0U /* AMD Evergreen */,
4321 DDERR_INVALIDPIXELFORMAT
,
4328 ~0U /* AMD Evergreen */,
4336 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4337 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4339 DDERR_INVALIDPIXELFORMAT
,
4340 DDERR_INVALIDPIXELFORMAT
,
4341 TRUE
/* Nvidia Kepler */,
4345 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4346 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4350 TRUE
/* Nvidia Kepler */,
4354 window
= create_window();
4355 ddraw
= create_ddraw();
4356 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4357 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4359 skip("Failed to create a 3D device, skipping test.\n");
4360 IDirectDraw2_Release(ddraw
);
4361 DestroyWindow(window
);
4364 z_depth
= get_device_z_depth(device
);
4365 ok(!!z_depth
, "Failed to get device z depth.\n");
4366 IDirect3DDevice2_Release(device
);
4368 if (FAILED(IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
)))
4370 skip("D3D interface is not available, skipping test.\n");
4374 memset(palette_entries
, 0, sizeof(palette_entries
));
4375 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
4376 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
4378 for (i
= 0; i
< ARRAY_SIZE(test_data
); ++i
)
4380 IDirectDrawSurface
*surface
, *rt
, *expected_rt
, *tmp
;
4381 DDSURFACEDESC surface_desc
;
4382 IDirect3DDevice2
*device
;
4384 memset(&surface_desc
, 0, sizeof(surface_desc
));
4385 surface_desc
.dwSize
= sizeof(surface_desc
);
4386 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4387 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4388 if (test_data
[i
].pf
)
4390 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4391 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
4393 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
4395 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4396 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
4398 surface_desc
.dwWidth
= 640;
4399 surface_desc
.dwHeight
= 480;
4400 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4401 ok(SUCCEEDED(hr
) || broken(test_data
[i
].create_may_fail
),
4402 "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4403 i
, test_data
[i
].caps_in
, hr
);
4407 memset(&surface_desc
, 0, sizeof(surface_desc
));
4408 surface_desc
.dwSize
= sizeof(surface_desc
);
4409 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4410 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4411 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
4412 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4413 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4415 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4416 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4417 i
, hr
, test_data
[i
].create_device_hr
);
4420 if (hr
== DDERR_NOPALETTEATTACHED
)
4422 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
4423 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
4424 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4425 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
4426 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4428 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4430 IDirectDrawSurface_Release(surface
);
4432 memset(&surface_desc
, 0, sizeof(surface_desc
));
4433 surface_desc
.dwSize
= sizeof(surface_desc
);
4434 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4435 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
4436 surface_desc
.dwWidth
= 640;
4437 surface_desc
.dwHeight
= 480;
4438 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4439 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
4441 hr
= IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
);
4442 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
4445 memset(&surface_desc
, 0, sizeof(surface_desc
));
4446 surface_desc
.dwSize
= sizeof(surface_desc
);
4447 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4448 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4449 if (test_data
[i
].pf
)
4451 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4452 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
4454 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
4456 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4457 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
4459 surface_desc
.dwWidth
= 640;
4460 surface_desc
.dwHeight
= 480;
4461 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
4462 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4463 i
, test_data
[i
].caps_in
, hr
);
4465 hr
= IDirect3DDevice2_SetRenderTarget(device
, rt
, 0);
4466 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
4467 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4468 i
, hr
, test_data
[i
].set_rt_hr
);
4469 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
4472 expected_rt
= surface
;
4474 /* It appears the surface is set as render target in this case, but no
4475 * reference is taken. */
4476 if (hr
== DDERR_INVALIDPIXELFORMAT
)
4478 refcount
= IDirectDrawSurface_AddRef(rt
);
4479 ok(refcount
== 2, "Test %u: Got unexpected refcount %u.\n", i
, refcount
);
4482 hr
= IDirect3DDevice2_GetRenderTarget(device
, &tmp
);
4483 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
4484 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
4486 IDirectDrawSurface_Release(tmp
);
4487 IDirectDrawSurface_Release(rt
);
4488 refcount
= IDirect3DDevice2_Release(device
);
4489 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
4490 refcount
= IDirectDrawSurface_Release(surface
);
4491 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
4494 IDirectDrawPalette_Release(palette
);
4495 IDirect3D2_Release(d3d
);
4498 refcount
= IDirectDraw2_Release(ddraw
);
4499 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4500 DestroyWindow(window
);
4503 static void test_primary_caps(void)
4505 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4506 IDirectDrawSurface
*surface
;
4507 DDSURFACEDESC surface_desc
;
4508 IDirectDraw2
*ddraw
;
4518 DWORD back_buffer_count
;
4526 DDSCAPS_PRIMARYSURFACE
,
4529 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
4533 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
4540 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
4547 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
4554 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
4561 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
4568 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4575 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4582 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4584 DDERR_NOEXCLUSIVEMODE
,
4588 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4589 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4595 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4596 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4599 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
4602 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4603 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
4609 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4610 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
4617 window
= create_window();
4618 ddraw
= create_ddraw();
4619 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4621 for (i
= 0; i
< ARRAY_SIZE(test_data
); ++i
)
4623 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
4624 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4626 memset(&surface_desc
, 0, sizeof(surface_desc
));
4627 surface_desc
.dwSize
= sizeof(surface_desc
);
4628 surface_desc
.dwFlags
= DDSD_CAPS
;
4629 if (test_data
[i
].back_buffer_count
!= ~0u)
4630 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4631 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4632 surface_desc
.dwBackBufferCount
= test_data
[i
].back_buffer_count
;
4633 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4634 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
4638 memset(&surface_desc
, 0, sizeof(surface_desc
));
4639 surface_desc
.dwSize
= sizeof(surface_desc
);
4640 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
4641 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4642 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
4643 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4644 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4646 IDirectDrawSurface_Release(surface
);
4649 refcount
= IDirectDraw2_Release(ddraw
);
4650 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4651 DestroyWindow(window
);
4654 static void test_surface_lock(void)
4656 IDirectDraw2
*ddraw
;
4657 IDirectDrawSurface
*surface
;
4658 IDirect3DDevice2
*device
;
4673 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
4674 "videomemory offscreenplain"
4677 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4678 "systemmemory offscreenplain"
4681 DDSCAPS_PRIMARYSURFACE
,
4685 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
4686 "videomemory texture"
4689 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
4690 "systemmemory texture"
4693 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4702 window
= create_window();
4703 ddraw
= create_ddraw();
4704 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4705 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4707 skip("Failed to create a 3D device, skipping test.\n");
4708 IDirectDraw2_Release(ddraw
);
4709 DestroyWindow(window
);
4712 z_depth
= get_device_z_depth(device
);
4713 ok(!!z_depth
, "Failed to get device z depth.\n");
4714 IDirect3DDevice2_Release(device
);
4716 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
4718 memset(&ddsd
, 0, sizeof(ddsd
));
4719 ddsd
.dwSize
= sizeof(ddsd
);
4720 ddsd
.dwFlags
= DDSD_CAPS
;
4721 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4723 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4727 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
4729 ddsd
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4730 U2(ddsd
).dwZBufferBitDepth
= z_depth
;
4732 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4734 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4735 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4737 memset(&ddsd
, 0, sizeof(ddsd
));
4738 ddsd
.dwSize
= sizeof(ddsd
);
4739 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4740 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4743 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4744 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4747 memset(&ddsd
, 0, sizeof(ddsd
));
4748 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4749 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, tests
[i
].name
);
4751 IDirectDrawSurface_Release(surface
);
4754 refcount
= IDirectDraw2_Release(ddraw
);
4755 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4756 DestroyWindow(window
);
4759 static void test_surface_discard(void)
4761 IDirectDraw2
*ddraw
;
4762 IDirect3DDevice2
*device
;
4766 IDirectDrawSurface
*surface
, *target
;
4775 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4776 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4777 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4778 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4782 window
= create_window();
4783 ddraw
= create_ddraw();
4784 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4785 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4787 skip("Failed to create a 3D device, skipping test.\n");
4788 DestroyWindow(window
);
4789 IDirectDraw2_Release(ddraw
);
4793 hr
= IDirect3DDevice2_GetRenderTarget(device
, &target
);
4794 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4796 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
4800 memset(&ddsd
, 0, sizeof(ddsd
));
4801 ddsd
.dwSize
= sizeof(ddsd
);
4802 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4803 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4806 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4809 skip("Failed to create surface, skipping.\n");
4813 memset(&ddsd
, 0, sizeof(ddsd
));
4814 ddsd
.dwSize
= sizeof(ddsd
);
4815 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4816 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4817 addr
= ddsd
.lpSurface
;
4818 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4819 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4821 memset(&ddsd
, 0, sizeof(ddsd
));
4822 ddsd
.dwSize
= sizeof(ddsd
);
4823 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4824 ok(SUCCEEDED(hr
) , "Failed to lock surface, hr %#x.\n", hr
);
4825 discarded
= ddsd
.lpSurface
!= addr
;
4826 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4827 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4829 hr
= IDirectDrawSurface_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
4830 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
4832 memset(&ddsd
, 0, sizeof(ddsd
));
4833 ddsd
.dwSize
= sizeof(ddsd
);
4834 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4835 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4836 discarded
|= ddsd
.lpSurface
!= addr
;
4837 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4838 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4840 IDirectDrawSurface_Release(surface
);
4842 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4843 * AMD r500, evergreen). Windows XP, at least on AMD r200, never changes the pointer. */
4844 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
4847 IDirectDrawSurface_Release(target
);
4848 IDirect3DDevice2_Release(device
);
4849 IDirectDraw2_Release(ddraw
);
4850 DestroyWindow(window
);
4853 static void fill_surface(IDirectDrawSurface
*surface
, D3DCOLOR color
)
4855 DDSURFACEDESC surface_desc
= {sizeof(surface_desc
)};
4860 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
4861 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4863 for (y
= 0; y
< surface_desc
.dwHeight
; ++y
)
4865 ptr
= (DWORD
*)((BYTE
*)surface_desc
.lpSurface
+ y
* surface_desc
.lPitch
);
4866 for (x
= 0; x
< surface_desc
.dwWidth
; ++x
)
4872 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4873 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4876 static void test_flip(void)
4878 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4879 IDirectDrawSurface
*frontbuffer
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
4880 DDSCAPS caps
= {DDSCAPS_FLIP
};
4881 DDSURFACEDESC surface_desc
;
4882 BOOL sysmem_primary
;
4883 IDirectDraw2
*ddraw
;
4884 DWORD expected_caps
;
4898 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE
},
4899 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN
},
4900 {"TEXTURE", DDSCAPS_TEXTURE
},
4903 window
= create_window();
4904 ddraw
= create_ddraw();
4905 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4907 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4908 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4910 for (i
= 0; i
< ARRAY_SIZE(test_data
); ++i
)
4912 /* Creating a flippable texture induces a BSoD on some versions of the
4913 * Intel graphics driver. At least Intel GMA 950 with driver version
4914 * 6.14.10.4926 on Windows XP SP3 is affected. */
4915 if ((test_data
[i
].caps
& DDSCAPS_TEXTURE
) && ddraw_is_intel(ddraw
))
4917 win_skip("Skipping flippable texture test.\n");
4921 memset(&surface_desc
, 0, sizeof(surface_desc
));
4922 surface_desc
.dwSize
= sizeof(surface_desc
);
4923 surface_desc
.dwFlags
= DDSD_CAPS
;
4924 if (!(test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4925 surface_desc
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4926 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
4927 surface_desc
.dwWidth
= 512;
4928 surface_desc
.dwHeight
= 512;
4929 surface_desc
.dwBackBufferCount
= 3;
4930 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4931 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4933 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_FLIP
;
4934 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4935 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4936 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4938 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_COMPLEX
;
4939 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_FLIP
;
4940 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4941 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4943 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_COMPLEX
;
4944 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4945 todo_wine_if(test_data
[i
].caps
& DDSCAPS_TEXTURE
)
4946 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
4950 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
4951 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
4952 hr
= IDirectDrawSurface_IsLost(frontbuffer
);
4953 ok(hr
== DD_OK
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4954 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4955 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
4956 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4958 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4959 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4960 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
4961 hr
= IDirectDrawSurface_IsLost(frontbuffer
);
4962 todo_wine
ok(hr
== DDERR_SURFACELOST
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4963 hr
= restore_surfaces(ddraw
);
4964 ok(SUCCEEDED(hr
), "%s: Failed to restore surfaces, hr %#x.\n", test_data
[i
].name
, hr
);
4966 memset(&surface_desc
, 0, sizeof(surface_desc
));
4967 surface_desc
.dwSize
= sizeof(surface_desc
);
4968 hr
= IDirectDrawSurface_GetSurfaceDesc(frontbuffer
, &surface_desc
);
4969 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4970 expected_caps
= DDSCAPS_FRONTBUFFER
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
4971 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
4972 expected_caps
|= DDSCAPS_VISIBLE
;
4973 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4974 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4975 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
4977 hr
= IDirectDrawSurface_GetAttachedSurface(frontbuffer
, &caps
, &backbuffer1
);
4978 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4979 memset(&surface_desc
, 0, sizeof(surface_desc
));
4980 surface_desc
.dwSize
= sizeof(surface_desc
);
4981 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer1
, &surface_desc
);
4982 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4983 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4984 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4985 expected_caps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
);
4986 expected_caps
|= DDSCAPS_BACKBUFFER
;
4987 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4988 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4990 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
4991 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4992 memset(&surface_desc
, 0, sizeof(surface_desc
));
4993 surface_desc
.dwSize
= sizeof(surface_desc
);
4994 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer2
, &surface_desc
);
4995 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4996 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4997 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4998 expected_caps
&= ~DDSCAPS_BACKBUFFER
;
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(backbuffer2
, &caps
, &backbuffer3
);
5003 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
5004 memset(&surface_desc
, 0, sizeof(surface_desc
));
5005 surface_desc
.dwSize
= sizeof(surface_desc
);
5006 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer3
, &surface_desc
);
5007 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
5008 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
5009 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
5010 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
5011 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
5013 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
5014 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
5015 ok(surface
== frontbuffer
, "%s: Got unexpected surface %p, expected %p.\n",
5016 test_data
[i
].name
, surface
, frontbuffer
);
5017 IDirectDrawSurface_Release(surface
);
5019 memset(&surface_desc
, 0, sizeof(surface_desc
));
5020 surface_desc
.dwSize
= sizeof(surface_desc
);
5021 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5022 surface_desc
.ddsCaps
.dwCaps
= 0;
5023 surface_desc
.dwWidth
= 640;
5024 surface_desc
.dwHeight
= 480;
5025 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5026 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
5027 hr
= IDirectDrawSurface_Flip(frontbuffer
, surface
, DDFLIP_WAIT
);
5028 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5029 IDirectDrawSurface_Release(surface
);
5031 hr
= IDirectDrawSurface_Flip(frontbuffer
, frontbuffer
, DDFLIP_WAIT
);
5032 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5033 hr
= IDirectDrawSurface_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
5034 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5035 hr
= IDirectDrawSurface_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
5036 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5037 hr
= IDirectDrawSurface_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
5038 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
5040 /* The Nvidia Geforce 7 driver cannot do a color fill on a texture backbuffer after
5041 * the backbuffer has been locked or GetSurfaceDesc has been called. Do it ourselves
5042 * as a workaround. */
5043 fill_surface(backbuffer1
, 0xffff0000);
5044 fill_surface(backbuffer2
, 0xff00ff00);
5045 fill_surface(backbuffer3
, 0xff0000ff);
5047 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
5048 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5049 color
= get_surface_color(backbuffer1
, 320, 240);
5050 /* The testbot seems to just copy the contents of one surface to all the
5051 * others, instead of properly flipping. */
5052 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
5053 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5054 color
= get_surface_color(backbuffer2
, 320, 240);
5055 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5056 fill_surface(backbuffer3
, 0xffff0000);
5058 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
5059 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5060 color
= get_surface_color(backbuffer1
, 320, 240);
5061 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
5062 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5063 color
= get_surface_color(backbuffer2
, 320, 240);
5064 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5065 fill_surface(backbuffer3
, 0xff00ff00);
5067 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
5068 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5069 color
= get_surface_color(backbuffer1
, 320, 240);
5070 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
5071 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5072 color
= get_surface_color(backbuffer2
, 320, 240);
5073 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5074 fill_surface(backbuffer3
, 0xff0000ff);
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 fill_surface(backbuffer1
, 0xffff0000);
5085 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer2
, DDFLIP_WAIT
);
5086 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5087 color
= get_surface_color(backbuffer1
, 320, 240);
5088 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5089 color
= get_surface_color(backbuffer3
, 320, 240);
5090 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
5091 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5092 fill_surface(backbuffer2
, 0xff00ff00);
5094 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer3
, DDFLIP_WAIT
);
5095 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
5096 color
= get_surface_color(backbuffer1
, 320, 240);
5097 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
5098 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5099 color
= get_surface_color(backbuffer2
, 320, 240);
5100 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
5102 IDirectDrawSurface_Release(backbuffer3
);
5103 IDirectDrawSurface_Release(backbuffer2
);
5104 IDirectDrawSurface_Release(backbuffer1
);
5105 IDirectDrawSurface_Release(frontbuffer
);
5108 refcount
= IDirectDraw2_Release(ddraw
);
5109 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5110 DestroyWindow(window
);
5113 static void reset_ddsd(DDSURFACEDESC
*ddsd
)
5115 memset(ddsd
, 0, sizeof(*ddsd
));
5116 ddsd
->dwSize
= sizeof(*ddsd
);
5119 static void test_set_surface_desc(void)
5121 IDirectDraw2
*ddraw
;
5125 IDirectDrawSurface
*surface
;
5126 IDirectDrawSurface3
*surface3
;
5136 invalid_caps_tests
[] =
5138 {DDSCAPS_VIDEOMEMORY
, FALSE
, "videomemory plain"},
5139 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, TRUE
, "systemmemory texture"},
5140 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, FALSE
, "systemmemory primary"},
5143 window
= create_window();
5144 ddraw
= create_ddraw();
5145 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5146 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5147 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5150 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5153 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5154 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5155 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5156 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5157 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5158 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5159 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5161 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5162 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5164 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5165 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5166 IDirectDrawSurface_Release(surface
);
5169 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5170 ddsd
.lpSurface
= data
;
5171 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5172 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5174 /* Redundantly setting the same lpSurface is not an error. */
5175 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5176 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5177 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5178 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5179 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5180 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
5182 hr
= IDirectDrawSurface3_Lock(surface3
, NULL
, &ddsd
, 0, NULL
);
5183 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5184 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5185 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
5186 hr
= IDirectDrawSurface3_Unlock(surface3
, NULL
);
5187 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5190 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5191 ddsd
.lpSurface
= data
;
5192 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 1);
5193 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
5195 ddsd
.lpSurface
= NULL
;
5196 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5197 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
5199 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, NULL
, 0);
5200 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
5202 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5203 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5204 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5205 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5207 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5208 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5209 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
5211 ddsd
.dwFlags
= DDSD_CAPS
;
5212 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5213 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5215 /* dwCaps = 0 is allowed, but ignored. */
5216 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
5217 ddsd
.lpSurface
= data
;
5218 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5219 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5220 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5221 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5222 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5223 ddsd
.ddsCaps
.dwCaps
= 0;
5224 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5225 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5227 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5228 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5229 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5230 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5232 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5234 ddsd
.dwFlags
= DDSD_HEIGHT
;
5236 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5237 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
5239 ddsd
.lpSurface
= data
;
5240 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
5241 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5242 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5245 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5246 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
5249 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5250 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
5251 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5252 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5254 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
5256 ddsd
.dwFlags
= DDSD_PITCH
;
5257 U1(ddsd
).lPitch
= 8 * 4;
5258 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5259 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
5261 ddsd
.dwFlags
= DDSD_WIDTH
;
5263 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5264 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
5266 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
5267 ddsd
.lpSurface
= data
;
5268 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5269 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
5271 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
5272 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5273 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
5275 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5276 U1(ddsd
).lPitch
= 16 * 4;
5278 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5279 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5282 hr
= IDirectDrawSurface3_GetSurfaceDesc(surface3
, &ddsd
);
5283 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5284 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5285 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5286 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
5288 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5290 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5291 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5292 U1(ddsd
).lPitch
= 4 * 4;
5293 ddsd
.lpSurface
= data
;
5294 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5295 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5297 U1(ddsd
).lPitch
= 4;
5298 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5299 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5301 U1(ddsd
).lPitch
= 16 * 4 + 1;
5302 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5303 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5305 U1(ddsd
).lPitch
= 16 * 4 + 3;
5306 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5307 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5309 U1(ddsd
).lPitch
= -4;
5310 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5311 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
5313 U1(ddsd
).lPitch
= 16 * 4;
5314 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5315 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5318 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5319 U1(ddsd
).lPitch
= 0;
5321 ddsd
.lpSurface
= data
;
5322 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5323 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
5325 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5326 U1(ddsd
).lPitch
= 16 * 4;
5328 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5329 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
5331 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5332 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
5333 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5334 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5335 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5336 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5337 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5338 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5339 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5340 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
5342 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
5343 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5344 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5346 /* Can't set color keys. */
5348 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
5349 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
5350 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
5351 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5352 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5354 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
5355 ddsd
.lpSurface
= data
;
5356 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5357 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5359 IDirectDrawSurface3_Release(surface3
);
5361 /* SetSurfaceDesc needs systemmemory surfaces.
5363 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5364 for (i
= 0; i
< ARRAY_SIZE(invalid_caps_tests
); i
++)
5367 ddsd
.dwFlags
= DDSD_CAPS
;
5368 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
5369 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5371 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5374 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5375 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5376 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5377 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5378 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5379 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5382 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5383 ok(SUCCEEDED(hr
) || hr
== DDERR_NODIRECTDRAWHW
, "Failed to create surface, hr %#x.\n", hr
);
5386 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5387 invalid_caps_tests
[i
].name
);
5390 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5391 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5392 IDirectDrawSurface_Release(surface
);
5395 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5396 ddsd
.lpSurface
= data
;
5397 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5398 if (invalid_caps_tests
[i
].supported
)
5400 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5404 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5405 invalid_caps_tests
[i
].name
, hr
);
5407 /* Check priority of error conditions. */
5408 ddsd
.dwFlags
= DDSD_WIDTH
;
5409 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5410 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5411 invalid_caps_tests
[i
].name
, hr
);
5414 IDirectDrawSurface3_Release(surface3
);
5418 ref
= IDirectDraw2_Release(ddraw
);
5419 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5420 DestroyWindow(window
);
5423 static void test_user_memory_getdc(void)
5425 IDirectDraw2
*ddraw
;
5429 IDirectDrawSurface
*surface
;
5430 IDirectDrawSurface3
*surface3
;
5439 window
= create_window();
5440 ddraw
= create_ddraw();
5441 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5443 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5444 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5447 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5450 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5451 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5452 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5453 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5454 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5455 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5456 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5457 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5458 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5460 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
5461 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr
);
5462 IDirectDrawSurface_Release(surface
);
5464 memset(data
, 0xaa, sizeof(data
));
5466 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5467 ddsd
.lpSurface
= data
;
5468 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5469 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5471 hr
= IDirectDrawSurface3_GetDC(surface3
, &dc
);
5472 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5473 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
5474 ok(!!bitmap
, "Failed to get bitmap.\n");
5475 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
5476 ok(size
== sizeof(dib
), "Got unexpected size %d.\n", size
);
5477 ok(dib
.dsBm
.bmBits
== data
, "Got unexpected bits %p, expected %p.\n", dib
.dsBm
.bmBits
, data
);
5478 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
5479 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
5480 hr
= IDirectDrawSurface3_ReleaseDC(surface3
, dc
);
5481 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5483 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
5484 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
5486 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
5487 ddsd
.lpSurface
= data
;
5490 U1(ddsd
).lPitch
= sizeof(*data
);
5491 hr
= IDirectDrawSurface3_SetSurfaceDesc(surface3
, &ddsd
, 0);
5492 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5494 memset(data
, 0xaa, sizeof(data
));
5495 hr
= IDirectDrawSurface3_GetDC(surface3
, &dc
);
5496 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5497 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
5498 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
5499 hr
= IDirectDrawSurface3_ReleaseDC(surface3
, dc
);
5500 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5502 for (y
= 0; y
< 4; y
++)
5504 for (x
= 0; x
< 4; x
++)
5506 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
5507 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5510 ok(data
[y
][x
] == 0x00000000, "Expected color 0xaaaaaaaa on position %ux%u, got %#x.\n",
5514 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5516 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5518 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5520 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5523 IDirectDrawSurface3_Release(surface3
);
5524 ref
= IDirectDraw2_Release(ddraw
);
5525 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5526 DestroyWindow(window
);
5529 static void test_sysmem_overlay(void)
5531 IDirectDraw2
*ddraw
;
5535 IDirectDrawSurface
*surface
;
5538 window
= create_window();
5539 ddraw
= create_ddraw();
5540 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5542 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5543 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5546 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
5549 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
5550 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
5551 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5552 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5553 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5554 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5555 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5556 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5557 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
5559 ref
= IDirectDraw2_Release(ddraw
);
5560 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5561 DestroyWindow(window
);
5564 static void test_primary_palette(void)
5566 DDSCAPS surface_caps
= {DDSCAPS_FLIP
};
5567 IDirectDrawSurface
*primary
, *backbuffer
;
5568 PALETTEENTRY palette_entries
[256];
5569 IDirectDrawPalette
*palette
, *tmp
;
5570 DDSURFACEDESC surface_desc
;
5571 IDirectDraw2
*ddraw
;
5577 window
= create_window();
5578 ddraw
= create_ddraw();
5579 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5580 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
5582 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5583 IDirectDraw2_Release(ddraw
);
5584 DestroyWindow(window
);
5587 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5588 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5590 memset(&surface_desc
, 0, sizeof(surface_desc
));
5591 surface_desc
.dwSize
= sizeof(surface_desc
);
5592 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
5593 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
5594 surface_desc
.dwBackBufferCount
= 1;
5595 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
5596 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5597 hr
= IDirectDrawSurface_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
5598 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5600 memset(palette_entries
, 0, sizeof(palette_entries
));
5601 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
5602 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5603 refcount
= get_refcount((IUnknown
*)palette
);
5604 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5606 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5607 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5608 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5610 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5611 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5613 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
5614 * and is generally somewhat broken with respect to 8 bpp / palette
5616 if (SUCCEEDED(IDirectDrawSurface_GetPalette(backbuffer
, &tmp
)))
5618 win_skip("Broken palette handling detected, skipping tests.\n");
5619 IDirectDrawPalette_Release(tmp
);
5620 IDirectDrawPalette_Release(palette
);
5621 /* The Windows 8 testbot keeps extra references to the primary and
5622 * backbuffer while in 8 bpp mode. */
5623 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
5624 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
5628 refcount
= get_refcount((IUnknown
*)palette
);
5629 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5631 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5632 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5633 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
5634 "Got unexpected palette caps %#x.\n", palette_caps
);
5636 hr
= IDirectDrawSurface_SetPalette(primary
, NULL
);
5637 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5638 refcount
= get_refcount((IUnknown
*)palette
);
5639 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5641 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5642 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5643 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5645 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
5646 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5647 refcount
= get_refcount((IUnknown
*)palette
);
5648 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5650 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
5651 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
5652 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
5653 IDirectDrawPalette_Release(tmp
);
5654 hr
= IDirectDrawSurface_GetPalette(backbuffer
, &tmp
);
5655 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5657 refcount
= IDirectDrawPalette_Release(palette
);
5658 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5659 refcount
= IDirectDrawPalette_Release(palette
);
5660 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5662 /* Note that this only seems to work when the palette is attached to the
5663 * primary surface. When attached to a regular surface, attempting to get
5664 * the palette here will cause an access violation. */
5665 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
5666 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5668 hr
= IDirectDrawSurface_IsLost(primary
);
5669 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
5671 memset(&surface_desc
, 0, sizeof(surface_desc
));
5672 surface_desc
.dwSize
= sizeof(surface_desc
);
5673 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
5674 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5675 ok(surface_desc
.dwWidth
== 640, "Got unexpected surface width %u.\n", surface_desc
.dwWidth
);
5676 ok(surface_desc
.dwHeight
== 480, "Got unexpected surface height %u.\n", surface_desc
.dwHeight
);
5677 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 8, "Got unexpected bit count %u.\n",
5678 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
5680 hr
= set_display_mode(ddraw
, 640, 480);
5681 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
5683 memset(&surface_desc
, 0, sizeof(surface_desc
));
5684 surface_desc
.dwSize
= sizeof(surface_desc
);
5685 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
5686 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5687 ok(surface_desc
.dwWidth
== 640, "Got unexpected surface width %u.\n", surface_desc
.dwWidth
);
5688 ok(surface_desc
.dwHeight
== 480, "Got unexpected surface height %u.\n", surface_desc
.dwHeight
);
5689 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 32
5690 || U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 24,
5691 "Got unexpected bit count %u.\n", U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
5693 hr
= IDirectDrawSurface_IsLost(primary
);
5694 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
5695 hr
= IDirectDrawSurface_Restore(primary
);
5696 ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
5697 hr
= IDirectDrawSurface_IsLost(primary
);
5698 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
5700 memset(&surface_desc
, 0, sizeof(surface_desc
));
5701 surface_desc
.dwSize
= sizeof(surface_desc
);
5702 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &surface_desc
);
5703 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5704 ok(surface_desc
.dwWidth
== 640, "Got unexpected surface width %u.\n", surface_desc
.dwWidth
);
5705 ok(surface_desc
.dwHeight
== 480, "Got unexpected surface height %u.\n", surface_desc
.dwHeight
);
5706 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 32
5707 || U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== 24,
5708 "Got unexpected bit count %u.\n", U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
5711 refcount
= IDirectDrawSurface_Release(backbuffer
);
5712 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5713 refcount
= IDirectDrawSurface_Release(primary
);
5714 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5715 refcount
= IDirectDraw2_Release(ddraw
);
5716 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5717 DestroyWindow(window
);
5720 static HRESULT WINAPI
surface_counter(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
5722 UINT
*surface_count
= context
;
5725 IDirectDrawSurface_Release(surface
);
5727 return DDENUMRET_OK
;
5730 static void test_surface_attachment(void)
5732 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
5733 DDSCAPS caps
= {DDSCAPS_TEXTURE
};
5734 DDSURFACEDESC surface_desc
;
5735 IDirectDraw2
*ddraw
;
5741 window
= create_window();
5742 ddraw
= create_ddraw();
5743 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5744 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5745 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5747 memset(&surface_desc
, 0, sizeof(surface_desc
));
5748 surface_desc
.dwSize
= sizeof(surface_desc
);
5749 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
5750 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
5751 U2(surface_desc
).dwMipMapCount
= 3;
5752 surface_desc
.dwWidth
= 128;
5753 surface_desc
.dwHeight
= 128;
5754 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5755 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5757 hr
= IDirectDrawSurface_GetAttachedSurface(surface1
, &caps
, &surface2
);
5758 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5759 hr
= IDirectDrawSurface_GetAttachedSurface(surface2
, &caps
, &surface3
);
5760 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5761 hr
= IDirectDrawSurface_GetAttachedSurface(surface3
, &caps
, &surface4
);
5762 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5765 IDirectDrawSurface_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
5766 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5768 IDirectDrawSurface_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
5769 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5771 IDirectDrawSurface_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
5772 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
5774 memset(&surface_desc
, 0, sizeof(surface_desc
));
5775 surface_desc
.dwSize
= sizeof(surface_desc
);
5776 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5777 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
5778 surface_desc
.dwWidth
= 16;
5779 surface_desc
.dwHeight
= 16;
5780 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5781 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5783 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
5784 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5785 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5786 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5787 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
5788 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5789 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
5790 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5791 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
5792 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5793 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
5794 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5796 IDirectDrawSurface_Release(surface4
);
5798 memset(&surface_desc
, 0, sizeof(surface_desc
));
5799 surface_desc
.dwSize
= sizeof(surface_desc
);
5800 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5801 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5802 surface_desc
.dwWidth
= 16;
5803 surface_desc
.dwHeight
= 16;
5804 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5805 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5807 if (SUCCEEDED(hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
)))
5809 skip("Running on refrast, skipping some tests.\n");
5810 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface4
);
5811 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5815 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5816 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5817 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5818 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
5819 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5820 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
5821 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5822 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
5823 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5824 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
5825 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5828 IDirectDrawSurface_Release(surface4
);
5829 IDirectDrawSurface_Release(surface3
);
5830 IDirectDrawSurface_Release(surface2
);
5831 IDirectDrawSurface_Release(surface1
);
5833 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5834 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5836 /* Try a single primary and two offscreen plain surfaces. */
5837 memset(&surface_desc
, 0, sizeof(surface_desc
));
5838 surface_desc
.dwSize
= sizeof(surface_desc
);
5839 surface_desc
.dwFlags
= DDSD_CAPS
;
5840 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
5841 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5842 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5844 memset(&surface_desc
, 0, sizeof(surface_desc
));
5845 surface_desc
.dwSize
= sizeof(surface_desc
);
5846 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5847 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5848 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
5849 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
5850 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, 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
, &surface3
, NULL
);
5860 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5862 /* This one has a different size. */
5863 memset(&surface_desc
, 0, sizeof(surface_desc
));
5864 surface_desc
.dwSize
= sizeof(surface_desc
);
5865 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5866 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5867 surface_desc
.dwWidth
= 128;
5868 surface_desc
.dwHeight
= 128;
5869 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5870 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5872 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5873 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5874 /* Try the reverse without detaching first. */
5875 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
5876 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5877 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5878 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5880 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
5881 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5882 /* Try to detach reversed. */
5883 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5884 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5885 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
5886 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5888 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
);
5889 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5890 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
5891 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5893 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
5894 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5895 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
5896 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5898 IDirectDrawSurface_Release(surface4
);
5899 IDirectDrawSurface_Release(surface3
);
5900 IDirectDrawSurface_Release(surface2
);
5901 IDirectDrawSurface_Release(surface1
);
5903 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
5904 memset(&surface_desc
, 0, sizeof(surface_desc
));
5905 surface_desc
.dwSize
= sizeof(surface_desc
);
5906 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5907 surface_desc
.dwWidth
= 64;
5908 surface_desc
.dwHeight
= 64;
5909 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5910 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5911 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
5912 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
5913 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
5914 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
5915 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
5916 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5917 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5918 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5919 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5921 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
5922 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
5923 U1(surface_desc
.ddpfPixelFormat
).dwZBufferBitDepth
= 16;
5924 U3(surface_desc
.ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
5925 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5926 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5928 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5929 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5930 refcount
= get_refcount((IUnknown
*)surface2
);
5931 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5932 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5933 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5935 /* Attaching while already attached to other surface. */
5936 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface2
);
5937 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5938 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface3
, 0, surface2
);
5939 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5940 IDirectDrawSurface_Release(surface3
);
5942 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
5943 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5944 refcount
= get_refcount((IUnknown
*)surface2
);
5945 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5947 /* Automatic detachment on release. */
5948 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
5949 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5950 refcount
= get_refcount((IUnknown
*)surface2
);
5951 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5952 refcount
= IDirectDrawSurface_Release(surface1
);
5953 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5954 refcount
= IDirectDrawSurface_Release(surface2
);
5955 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5956 refcount
= IDirectDraw2_Release(ddraw
);
5957 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5958 DestroyWindow(window
);
5961 static void test_pixel_format(void)
5963 HWND window
, window2
= NULL
;
5964 HDC hdc
, hdc2
= NULL
;
5966 int format
, test_format
;
5967 PIXELFORMATDESCRIPTOR pfd
;
5968 IDirectDraw2
*ddraw
= NULL
;
5969 IDirectDrawClipper
*clipper
= NULL
;
5971 IDirectDrawSurface
*primary
= NULL
;
5975 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
5976 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
5979 skip("Failed to create window\n");
5983 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
5984 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
5986 hdc
= GetDC(window
);
5989 skip("Failed to get DC\n");
5994 hdc2
= GetDC(window2
);
5996 gl
= LoadLibraryA("opengl32.dll");
5997 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
5999 format
= GetPixelFormat(hdc
);
6000 ok(format
== 0, "new window has pixel format %d\n", format
);
6002 ZeroMemory(&pfd
, sizeof(pfd
));
6003 pfd
.nSize
= sizeof(pfd
);
6005 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
6006 pfd
.iPixelType
= PFD_TYPE_RGBA
;
6007 pfd
.iLayerType
= PFD_MAIN_PLANE
;
6008 format
= ChoosePixelFormat(hdc
, &pfd
);
6011 skip("no pixel format available\n");
6015 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
6017 skip("failed to set pixel format\n");
6021 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
6023 skip("failed to set pixel format on second window\n");
6026 ReleaseDC(window2
, hdc2
);
6031 ddraw
= create_ddraw();
6032 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6034 test_format
= GetPixelFormat(hdc
);
6035 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6037 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6040 skip("Failed to set cooperative level, hr %#x.\n", hr
);
6044 test_format
= GetPixelFormat(hdc
);
6045 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6049 hr
= IDirectDraw2_CreateClipper(ddraw
, 0, &clipper
, NULL
);
6050 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
6051 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
6052 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
6054 test_format
= GetPixelFormat(hdc
);
6055 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6057 test_format
= GetPixelFormat(hdc2
);
6058 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6061 memset(&ddsd
, 0, sizeof(ddsd
));
6062 ddsd
.dwSize
= sizeof(ddsd
);
6063 ddsd
.dwFlags
= DDSD_CAPS
;
6064 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6066 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
6067 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
6069 test_format
= GetPixelFormat(hdc
);
6070 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6074 test_format
= GetPixelFormat(hdc2
);
6075 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6080 hr
= IDirectDrawSurface2_SetClipper(primary
, clipper
);
6081 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
6083 test_format
= GetPixelFormat(hdc
);
6084 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6086 test_format
= GetPixelFormat(hdc2
);
6087 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6090 memset(&fx
, 0, sizeof(fx
));
6091 fx
.dwSize
= sizeof(fx
);
6092 hr
= IDirectDrawSurface2_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6093 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
6095 test_format
= GetPixelFormat(hdc
);
6096 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6100 test_format
= GetPixelFormat(hdc2
);
6101 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6105 if (primary
) IDirectDrawSurface2_Release(primary
);
6106 if (clipper
) IDirectDrawClipper_Release(clipper
);
6107 if (ddraw
) IDirectDraw2_Release(ddraw
);
6108 if (gl
) FreeLibrary(gl
);
6109 if (hdc
) ReleaseDC(window
, hdc
);
6110 if (hdc2
) ReleaseDC(window2
, hdc2
);
6111 if (window
) DestroyWindow(window
);
6112 if (window2
) DestroyWindow(window2
);
6115 static void test_create_surface_pitch(void)
6117 IDirectDrawSurface
*surface
;
6118 DDSURFACEDESC surface_desc
;
6119 IDirectDraw2
*ddraw
;
6139 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6141 DDSD_PITCH
, 0x100, 0x100},
6142 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6143 DDSD_PITCH
, 0x104, DD_OK
,
6144 DDSD_PITCH
, 0x100, 0x100},
6145 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6146 DDSD_PITCH
, 0x0f8, DD_OK
,
6147 DDSD_PITCH
, 0x100, 0x100},
6148 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6149 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
6151 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6153 DDSD_PITCH
, 0x100, 0x0fc},
6155 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6156 DDSD_PITCH
, 0x104, DD_OK
,
6157 DDSD_PITCH
, 0x100, 0x0fc},
6158 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6159 DDSD_PITCH
, 0x0f8, DD_OK
,
6160 DDSD_PITCH
, 0x100, 0x0fc},
6161 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6162 DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
6163 DDSD_PITCH
, 0x100, 0x0fc},
6164 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6165 DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
6167 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
6168 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
6171 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
6172 0, 0, DDERR_INVALIDCAPS
,
6174 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6176 DDSD_PITCH
, 0x100, 0 },
6177 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6178 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
6180 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
6181 0, 0, DDERR_INVALIDCAPS
,
6183 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6185 DDSD_PITCH
, 0x100, 0 },
6187 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
6188 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
6191 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
6193 window
= create_window();
6194 ddraw
= create_ddraw();
6195 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6196 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6197 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6199 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
6201 for (i
= 0; i
< ARRAY_SIZE(test_data
); ++i
)
6203 memset(&surface_desc
, 0, sizeof(surface_desc
));
6204 surface_desc
.dwSize
= sizeof(surface_desc
);
6205 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
6206 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
6207 surface_desc
.dwWidth
= 63;
6208 surface_desc
.dwHeight
= 63;
6209 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
6210 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6211 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6212 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6213 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6214 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6215 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6216 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6217 if (test_data
[i
].flags_in
& DDSD_LPSURFACE
)
6219 HRESULT expected_hr
= SUCCEEDED(test_data
[i
].hr
) ? DDERR_INVALIDPARAMS
: test_data
[i
].hr
;
6220 ok(hr
== expected_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, expected_hr
);
6221 surface_desc
.lpSurface
= mem
;
6222 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6224 if ((test_data
[i
].caps
& DDSCAPS_VIDEOMEMORY
) && hr
== DDERR_NODIRECTDRAWHW
)
6226 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
6230 memset(&surface_desc
, 0, sizeof(surface_desc
));
6231 surface_desc
.dwSize
= sizeof(surface_desc
);
6232 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
6233 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
6234 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
6235 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6236 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
6237 /* The pitch for textures seems to be implementation specific. */
6238 if (!(test_data
[i
].caps
& DDSCAPS_TEXTURE
))
6240 if (is_ddraw64
&& test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
6241 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
6242 "Test %u: Got unexpected pitch %u, expected %u.\n",
6243 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
6245 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
6246 "Test %u: Got unexpected pitch %u, expected %u.\n",
6247 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
6249 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
6251 IDirectDrawSurface_Release(surface
);
6254 HeapFree(GetProcessHeap(), 0, mem
);
6255 refcount
= IDirectDraw2_Release(ddraw
);
6256 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6257 DestroyWindow(window
);
6260 static void test_mipmap(void)
6262 IDirectDrawSurface
*surface1
;
6263 IDirectDrawSurface2
*surface
, *surface2
;
6264 DDSURFACEDESC surface_desc
;
6265 IDirectDraw2
*ddraw
;
6270 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
6279 DWORD mipmap_count_in
;
6281 DWORD mipmap_count_out
;
6285 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 3, DD_OK
, 3},
6286 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDPARAMS
, 0},
6287 {0, DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 1},
6288 {0, DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDCAPS
, 0},
6289 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 6},
6290 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 32, 64, 0, DD_OK
, 6},
6293 window
= create_window();
6294 ddraw
= create_ddraw();
6295 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6296 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6297 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6299 memset(&hal_caps
, 0, sizeof(hal_caps
));
6300 hal_caps
.dwSize
= sizeof(hal_caps
);
6301 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
6302 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6303 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6305 skip("Mipmapped textures not supported, skipping tests.\n");
6306 IDirectDraw2_Release(ddraw
);
6307 DestroyWindow(window
);
6311 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
6313 memset(&surface_desc
, 0, sizeof(surface_desc
));
6314 surface_desc
.dwSize
= sizeof(surface_desc
);
6315 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| tests
[i
].flags
;
6316 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
6317 surface_desc
.dwWidth
= tests
[i
].width
;
6318 surface_desc
.dwHeight
= tests
[i
].height
;
6319 if (tests
[i
].flags
& DDSD_MIPMAPCOUNT
)
6320 U2(surface_desc
).dwMipMapCount
= tests
[i
].mipmap_count_in
;
6321 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6322 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
6326 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
6327 ok(SUCCEEDED(hr
), "Test %u: Failed to get IDirectDrawSurface2 interface, hr %#x.\n", i
, hr
);
6328 IDirectDrawSurface_Release(surface1
);
6330 memset(&surface_desc
, 0, sizeof(surface_desc
));
6331 surface_desc
.dwSize
= sizeof(surface_desc
);
6332 hr
= IDirectDrawSurface2_GetSurfaceDesc(surface
, &surface_desc
);
6333 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
6334 ok(surface_desc
.dwFlags
& DDSD_MIPMAPCOUNT
,
6335 "Test %u: Got unexpected flags %#x.\n", i
, surface_desc
.dwFlags
);
6336 ok(U2(surface_desc
).dwMipMapCount
== tests
[i
].mipmap_count_out
,
6337 "Test %u: Got unexpected mipmap count %u.\n", i
, U2(surface_desc
).dwMipMapCount
);
6339 if (U2(surface_desc
).dwMipMapCount
> 1)
6341 hr
= IDirectDrawSurface2_GetAttachedSurface(surface
, &caps
, &surface2
);
6342 ok(SUCCEEDED(hr
), "Test %u: Failed to get attached surface, hr %#x.\n", i
, hr
);
6344 memset(&surface_desc
, 0, sizeof(surface_desc
));
6345 surface_desc
.dwSize
= sizeof(surface_desc
);
6346 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
6347 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
6348 memset(&surface_desc
, 0, sizeof(surface_desc
));
6349 surface_desc
.dwSize
= sizeof(surface_desc
);
6350 hr
= IDirectDrawSurface2_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
6351 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
6352 IDirectDrawSurface2_Unlock(surface2
, NULL
);
6353 IDirectDrawSurface2_Unlock(surface
, NULL
);
6355 IDirectDrawSurface2_Release(surface2
);
6358 IDirectDrawSurface2_Release(surface
);
6361 refcount
= IDirectDraw2_Release(ddraw
);
6362 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6363 DestroyWindow(window
);
6366 static void test_palette_complex(void)
6368 IDirectDrawSurface
*surface1
;
6369 IDirectDrawSurface2
*surface
, *mipmap
, *tmp
;
6370 DDSURFACEDESC surface_desc
;
6371 IDirectDraw2
*ddraw
;
6372 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
6376 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
6378 PALETTEENTRY palette_entries
[256];
6384 window
= create_window();
6385 ddraw
= create_ddraw();
6386 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6387 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6388 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6390 memset(&hal_caps
, 0, sizeof(hal_caps
));
6391 hal_caps
.dwSize
= sizeof(hal_caps
);
6392 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
6393 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6394 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6396 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
6397 IDirectDraw2_Release(ddraw
);
6398 DestroyWindow(window
);
6402 memset(&surface_desc
, 0, sizeof(surface_desc
));
6403 surface_desc
.dwSize
= sizeof(surface_desc
);
6404 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6405 surface_desc
.dwWidth
= 128;
6406 surface_desc
.dwHeight
= 128;
6407 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6408 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6409 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6410 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6411 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6412 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6413 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
6414 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
6415 IDirectDrawSurface_Release(surface1
);
6417 memset(palette_entries
, 0, sizeof(palette_entries
));
6418 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6419 palette_entries
, &palette
, NULL
);
6420 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6422 memset(palette_entries
, 0, sizeof(palette_entries
));
6423 palette_entries
[1].peRed
= 0xff;
6424 palette_entries
[1].peGreen
= 0x80;
6425 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6426 palette_entries
, &palette_mipmap
, NULL
);
6427 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6429 palette2
= (void *)0xdeadbeef;
6430 hr
= IDirectDrawSurface2_GetPalette(surface
, &palette2
);
6431 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6432 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
6433 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
6434 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6435 hr
= IDirectDrawSurface2_GetPalette(surface
, &palette2
);
6436 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6437 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
6438 IDirectDrawPalette_Release(palette2
);
6441 IDirectDrawSurface2_AddRef(mipmap
);
6442 for (i
= 0; i
< 7; ++i
)
6444 hr
= IDirectDrawSurface2_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6445 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
6446 palette2
= (void *)0xdeadbeef;
6447 hr
= IDirectDrawSurface2_GetPalette(tmp
, &palette2
);
6448 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
6449 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
6451 hr
= IDirectDrawSurface2_SetPalette(tmp
, palette_mipmap
);
6452 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
6454 hr
= IDirectDrawSurface2_GetPalette(tmp
, &palette2
);
6455 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
6456 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
6457 IDirectDrawPalette_Release(palette2
);
6459 hr
= IDirectDrawSurface2_GetDC(tmp
, &dc
);
6460 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
6461 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
6462 ok(count
== 1, "Expected count 1, got %u.\n", count
);
6463 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
6464 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
6465 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
6466 hr
= IDirectDrawSurface2_ReleaseDC(tmp
, dc
);
6467 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
6469 IDirectDrawSurface2_Release(mipmap
);
6473 hr
= IDirectDrawSurface2_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6474 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6475 IDirectDrawSurface2_Release(mipmap
);
6476 refcount
= IDirectDrawSurface2_Release(surface
);
6477 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6478 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
6479 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6480 refcount
= IDirectDrawPalette_Release(palette
);
6481 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6483 refcount
= IDirectDraw2_Release(ddraw
);
6484 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6485 DestroyWindow(window
);
6488 static void test_p8_blit(void)
6490 IDirectDrawSurface
*src
, *dst
, *dst_p8
;
6491 DDSURFACEDESC surface_desc
;
6492 IDirectDraw2
*ddraw
;
6493 IDirectDrawPalette
*palette
, *palette2
;
6497 PALETTEENTRY palette_entries
[256];
6501 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
6502 static const BYTE src_data2
[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
6503 static const BYTE expected_p8
[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
6504 static const D3DCOLOR expected
[] =
6506 0x00101010, 0x00010101, 0x00020202, 0x00030303,
6507 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
6511 window
= create_window();
6512 ddraw
= create_ddraw();
6513 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6514 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6515 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6516 is_warp
= ddraw_is_warp(ddraw
);
6518 memset(palette_entries
, 0, sizeof(palette_entries
));
6519 palette_entries
[1].peGreen
= 0xff;
6520 palette_entries
[2].peBlue
= 0xff;
6521 palette_entries
[3].peFlags
= 0xff;
6522 palette_entries
[4].peRed
= 0xff;
6523 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6524 palette_entries
, &palette
, NULL
);
6525 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6526 palette_entries
[1].peBlue
= 0xff;
6527 palette_entries
[2].peGreen
= 0xff;
6528 palette_entries
[3].peRed
= 0xff;
6529 palette_entries
[4].peFlags
= 0x0;
6530 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6531 palette_entries
, &palette2
, NULL
);
6532 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6534 memset(&surface_desc
, 0, sizeof(surface_desc
));
6535 surface_desc
.dwSize
= sizeof(surface_desc
);
6536 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6537 surface_desc
.dwWidth
= 8;
6538 surface_desc
.dwHeight
= 1;
6539 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6540 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6541 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6542 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6543 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
6544 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6545 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst_p8
, NULL
);
6546 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6547 hr
= IDirectDrawSurface_SetPalette(dst_p8
, palette2
);
6548 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6550 memset(&surface_desc
, 0, sizeof(surface_desc
));
6551 surface_desc
.dwSize
= sizeof(surface_desc
);
6552 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6553 surface_desc
.dwWidth
= 8;
6554 surface_desc
.dwHeight
= 1;
6555 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6556 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6557 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6558 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6559 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6560 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6561 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6562 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6563 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
6564 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6566 memset(&surface_desc
, 0, sizeof(surface_desc
));
6567 surface_desc
.dwSize
= sizeof(surface_desc
);
6568 hr
= IDirectDrawSurface_Lock(src
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
6569 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
6570 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
6571 hr
= IDirectDrawSurface_Unlock(src
, NULL
);
6572 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
6574 hr
= IDirectDrawSurface_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
6575 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
6576 memcpy(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
));
6577 hr
= IDirectDrawSurface_Unlock(dst_p8
, NULL
);
6578 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
6580 hr
= IDirectDrawSurface_SetPalette(src
, palette
);
6581 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6582 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
6583 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
6584 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
6585 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
6586 "Failed to blit, hr %#x.\n", hr
);
6590 for (x
= 0; x
< ARRAY_SIZE(expected
); x
++)
6592 color
= get_surface_color(dst
, x
, 0);
6593 todo_wine
ok(compare_color(color
, expected
[x
], 0),
6594 "Pixel %u: Got color %#x, expected %#x.\n",
6595 x
, color
, expected
[x
]);
6599 memset(&fx
, 0, sizeof(fx
));
6600 fx
.dwSize
= sizeof(fx
);
6601 fx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 0x2;
6602 fx
.ddckSrcColorkey
.dwColorSpaceLowValue
= 0x2;
6603 hr
= IDirectDrawSurface7_Blt(dst_p8
, NULL
, src
, NULL
, DDBLT_WAIT
| DDBLT_KEYSRCOVERRIDE
, &fx
);
6604 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
6606 hr
= IDirectDrawSurface_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
6607 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
6608 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
6609 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
6610 * for example) also works as expected.
6612 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
6613 * the display mode set to P8 doesn't help either. */
6614 ok(!memcmp(surface_desc
.lpSurface
, expected_p8
, sizeof(expected_p8
))
6615 || broken(is_warp
&& !memcmp(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
))),
6616 "Got unexpected P8 color key blit result.\n");
6617 hr
= IDirectDrawSurface_Unlock(dst_p8
, NULL
);
6618 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
6620 IDirectDrawSurface_Release(src
);
6621 IDirectDrawSurface_Release(dst
);
6622 IDirectDrawSurface_Release(dst_p8
);
6623 IDirectDrawPalette_Release(palette
);
6624 IDirectDrawPalette_Release(palette2
);
6626 refcount
= IDirectDraw2_Release(ddraw
);
6627 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6628 DestroyWindow(window
);
6631 static void test_material(void)
6633 IDirect3DMaterial2
*background
, *material
;
6634 D3DMATERIALHANDLE mat_handle
, tmp
;
6635 IDirect3DViewport2
*viewport
;
6636 IDirect3DDevice2
*device
;
6637 IDirectDrawSurface
*rt
;
6638 IDirectDraw2
*ddraw
;
6646 static D3DVERTEX quad
[] =
6648 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6649 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6650 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6651 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6656 D3DCOLOR expected_color
;
6661 {FALSE
, 0x00ffffff},
6663 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6665 window
= create_window();
6666 ddraw
= create_ddraw();
6667 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6668 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6670 skip("Failed to create a 3D device, skipping test.\n");
6671 DestroyWindow(window
);
6675 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6676 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6678 background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
6679 viewport
= create_viewport(device
, 0, 0, 640, 480);
6680 viewport_set_background(device
, viewport
, background
);
6681 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6682 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6684 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
6685 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6686 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6688 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6689 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6690 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6691 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6692 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6693 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6694 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6695 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6696 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, 0);
6697 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6698 hr
= IDirect3DDevice2_GetLightState(device
, D3DLIGHTSTATE_MATERIAL
, &tmp
);
6699 ok(SUCCEEDED(hr
), "Failed to get light state, hr %#x.\n", hr
);
6700 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6702 for (i
= 0; i
< ARRAY_SIZE(test_data
); ++i
)
6704 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
6705 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6707 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
6708 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6710 hr
= IDirect3DDevice2_BeginScene(device
);
6711 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6712 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_VERTEX
, quad
, 4, 0);
6713 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6714 hr
= IDirect3DDevice2_EndScene(device
);
6715 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6716 color
= get_surface_color(rt
, 320, 240);
6717 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
6718 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
6721 destroy_material(material
);
6722 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
6723 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6724 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6726 hr
= IDirect3DViewport2_SetBackground(viewport
, mat_handle
);
6727 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
6728 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6729 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6730 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6731 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6732 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6733 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6734 color
= get_surface_color(rt
, 320, 240);
6735 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6737 hr
= IDirect3DViewport2_SetBackground(viewport
, 0);
6738 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6739 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6740 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6741 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
6742 ok(valid
, "Got unexpected valid %#x.\n", valid
);
6743 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6744 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6745 color
= get_surface_color(rt
, 320, 240);
6746 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6748 destroy_viewport(device
, viewport
);
6749 viewport
= create_viewport(device
, 0, 0, 640, 480);
6751 hr
= IDirect3DViewport2_GetBackground(viewport
, &tmp
, &valid
);
6752 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
6753 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
6754 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
6755 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6756 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6757 color
= get_surface_color(rt
, 320, 240);
6758 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
6760 destroy_viewport(device
, viewport
);
6761 destroy_material(background
);
6762 destroy_material(material
);
6763 IDirectDrawSurface_Release(rt
);
6764 refcount
= IDirect3DDevice2_Release(device
);
6765 ok(!refcount
, "Device has %u references left.\n", refcount
);
6766 refcount
= IDirectDraw2_Release(ddraw
);
6767 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
6768 DestroyWindow(window
);
6771 static void test_lighting(void)
6773 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6774 static D3DMATRIX mat
=
6776 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6777 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6778 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6779 0.0f
, 0.0f
, 0.0f
, 1.0f
,
6783 1.0f
, 0.0f
, 1.0f
, 0.0f
,
6784 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6785 1.0f
, 0.0f
, 1.0f
, 0.0f
,
6786 0.0f
, 0.0f
, 0.5f
, 1.0f
,
6790 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6791 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6792 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
6793 10.f
, 10.0f
, 10.0f
, 1.0f
,
6797 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6798 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6799 0.0f
, 0.0f
, 1.0f
, -1.0f
,
6800 10.f
, 10.0f
, 10.0f
, 0.0f
,
6802 static D3DLVERTEX unlitquad
[] =
6804 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6805 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6806 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6807 {{ 0.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
6811 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6812 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6813 {{ 0.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6814 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
6816 static D3DVERTEX unlitnquad
[] =
6818 {{0.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6819 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6820 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6821 {{1.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6825 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6826 {{0.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6827 {{1.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6828 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
6832 {{-1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6833 {{-1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6834 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6835 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6839 {{-10.0f
}, {-11.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6840 {{-10.0f
}, { -9.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6841 {{-10.0f
}, { -9.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6842 {{-10.0f
}, {-11.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
6846 {{-11.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6847 {{-11.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6848 {{ -9.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6849 {{ -9.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
6851 static WORD indices
[] = {0, 1, 2, 2, 3, 0};
6854 D3DMATRIX
*world_matrix
;
6857 const char *message
;
6861 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
6862 {&mat_singular
, nquad
, 0x000000b4, "Lit quad with singular world matrix"},
6863 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
6864 {&mat_nonaffine
, translatedquad
, 0x000000ff, "Lit quad with non-affine matrix"},
6869 IDirect3DDevice2
*device
;
6870 IDirectDraw2
*ddraw
;
6871 IDirectDrawSurface
*rt
;
6872 IDirect3DViewport2
*viewport
;
6873 IDirect3DMaterial2
*material
;
6874 IDirect3DLight
*light
;
6875 D3DMATERIALHANDLE mat_handle
;
6876 D3DLIGHT2 light_desc
;
6882 window
= create_window();
6883 ddraw
= create_ddraw();
6884 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6885 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6887 skip("Failed to create a 3D device, skipping test.\n");
6888 DestroyWindow(window
);
6892 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
6893 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
6895 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
6896 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6898 viewport
= create_viewport(device
, 0, 0, 640, 480);
6899 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
6900 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
6902 material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
6903 viewport_set_background(device
, viewport
, material
);
6905 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6906 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6908 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
6909 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
6910 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
6911 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
6912 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
6913 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
6914 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
6915 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
6916 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
6917 ok(SUCCEEDED(hr
), "Failed to disable zbuffer, hr %#x.\n", hr
);
6918 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
6919 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
6920 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
6921 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
6923 hr
= IDirect3DDevice2_BeginScene(device
);
6924 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6926 /* There is no D3DRENDERSTATE_LIGHTING on ddraw < 7. */
6927 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
6928 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6929 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_LVERTEX
, unlitquad
,
6931 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6933 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
6934 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
6935 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_LVERTEX
, litquad
,
6937 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6939 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
6940 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6941 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, unlitnquad
,
6943 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6945 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
6946 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
6947 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, litnquad
,
6949 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6951 hr
= IDirect3DDevice2_EndScene(device
);
6952 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6954 color
= get_surface_color(rt
, 160, 360);
6955 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color
);
6956 color
= get_surface_color(rt
, 160, 120);
6957 ok(color
== 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color
);
6958 color
= get_surface_color(rt
, 480, 360);
6959 ok(color
== 0x00ffffff, "Unlit quad with normals has color 0x%08x.\n", color
);
6960 color
= get_surface_color(rt
, 480, 120);
6961 ok(color
== 0x00ffffff, "Lit quad with normals has color 0x%08x.\n", color
);
6963 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
6964 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
6965 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
6966 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
6968 hr
= IDirect3D2_CreateLight(d3d
, &light
, NULL
);
6969 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
6970 memset(&light_desc
, 0, sizeof(light_desc
));
6971 light_desc
.dwSize
= sizeof(light_desc
);
6972 light_desc
.dltType
= D3DLIGHT_DIRECTIONAL
;
6973 U1(light_desc
.dcvColor
).r
= 0.0f
;
6974 U2(light_desc
.dcvColor
).g
= 0.0f
;
6975 U3(light_desc
.dcvColor
).b
= 1.0f
;
6976 U4(light_desc
.dcvColor
).a
= 1.0f
;
6977 U3(light_desc
.dvDirection
).z
= 1.0f
;
6978 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
6979 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
6980 hr
= IDirect3DViewport2_AddLight(viewport
, light
);
6981 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
6983 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6984 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
6986 hr
= IDirect3DDevice2_BeginScene(device
);
6987 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6989 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
, nquad
,
6991 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
6993 hr
= IDirect3DDevice2_EndScene(device
);
6994 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6996 color
= get_surface_color(rt
, 320, 240);
6997 ok(color
== 0x00000000, "Lit quad with no light has color 0x%08x.\n", color
);
6999 light_desc
.dwFlags
= D3DLIGHT_ACTIVE
;
7000 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)&light_desc
);
7001 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
7003 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
7005 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, tests
[i
].world_matrix
);
7006 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
7008 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7009 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7011 hr
= IDirect3DDevice2_BeginScene(device
);
7012 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7014 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
,
7015 tests
[i
].quad
, 4, indices
, 6, 0);
7016 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7018 hr
= IDirect3DDevice2_EndScene(device
);
7019 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7021 color
= get_surface_color(rt
, 320, 240);
7022 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
7025 hr
= IDirect3DViewport2_DeleteLight(viewport
, light
);
7026 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
7027 IDirect3DLight_Release(light
);
7028 destroy_material(material
);
7029 destroy_viewport(device
, viewport
);
7030 IDirectDrawSurface2_Release(rt
);
7031 refcount
= IDirect3DDevice2_Release(device
);
7032 ok(!refcount
, "Device has %u references left.\n", refcount
);
7033 IDirect3D2_Release(d3d
);
7034 refcount
= IDirectDraw2_Release(ddraw
);
7035 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
7036 DestroyWindow(window
);
7039 static void test_specular_lighting(void)
7041 static const unsigned int vertices_side
= 5;
7042 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
7043 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7044 static D3DMATRIX mat
=
7046 1.0f
, 0.0f
, 0.0f
, 0.0f
,
7047 0.0f
, 1.0f
, 0.0f
, 0.0f
,
7048 0.0f
, 0.0f
, 1.0f
, 0.0f
,
7049 0.0f
, 0.0f
, 0.0f
, 1.0f
,
7051 static D3DLIGHT2 directional
=
7054 D3DLIGHT_DIRECTIONAL
,
7055 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7056 {{0.0f
}, {0.0f
}, {0.0f
}},
7057 {{0.0f
}, {0.0f
}, {1.0f
}},
7063 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7064 {{0.0f
}, {0.0f
}, {0.0f
}},
7065 {{0.0f
}, {0.0f
}, {0.0f
}},
7074 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7075 {{0.0f
}, {0.0f
}, {0.0f
}},
7076 {{0.0f
}, {0.0f
}, {1.0f
}},
7080 M_PI
/ 12.0f
, M_PI
/ 3.0f
7085 D3DLIGHT_PARALLELPOINT
,
7086 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7087 {{0.5f
}, {0.0f
}, {-1.0f
}},
7088 {{0.0f
}, {0.0f
}, {0.0f
}},
7094 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7095 {{-1.1f
}, {0.0f
}, {1.1f
}},
7096 {{0.0f
}, {0.0f
}, {0.0f
}},
7105 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
7106 {{0.0f
}, {0.0f
}, {0.1f
}},
7107 {{0.0f
}, {0.0f
}, {0.0f
}},
7112 static const struct expected_color
7117 expected_directional_local
[] =
7119 {160, 120, 0x003c3c3c},
7120 {320, 120, 0x00717171},
7121 {480, 120, 0x003c3c3c},
7122 {160, 240, 0x00717171},
7123 {320, 240, 0x00ffffff},
7124 {480, 240, 0x00717171},
7125 {160, 360, 0x003c3c3c},
7126 {320, 360, 0x00717171},
7127 {480, 360, 0x003c3c3c},
7129 expected_point_local
[] =
7131 {160, 120, 0x00000000},
7132 {320, 120, 0x00090909},
7133 {480, 120, 0x00000000},
7134 {160, 240, 0x00090909},
7135 {320, 240, 0x00fafafa},
7136 {480, 240, 0x00090909},
7137 {160, 360, 0x00000000},
7138 {320, 360, 0x00090909},
7139 {480, 360, 0x00000000},
7141 expected_spot_local
[] =
7143 {160, 120, 0x00000000},
7144 {320, 120, 0x00020202},
7145 {480, 120, 0x00000000},
7146 {160, 240, 0x00020202},
7147 {320, 240, 0x00fafafa},
7148 {480, 240, 0x00020202},
7149 {160, 360, 0x00000000},
7150 {320, 360, 0x00020202},
7151 {480, 360, 0x00000000},
7153 expected_parallelpoint
[] =
7155 {160, 120, 0x00050505},
7156 {320, 120, 0x002c2c2c},
7157 {480, 120, 0x006e6e6e},
7158 {160, 240, 0x00090909},
7159 {320, 240, 0x00717171},
7160 {480, 240, 0x00ffffff},
7161 {160, 360, 0x00050505},
7162 {320, 360, 0x002c2c2c},
7163 {480, 360, 0x006e6e6e},
7165 expected_point_side
[] =
7167 {160, 120, 0x00000000},
7168 {320, 120, 0x00000000},
7169 {480, 120, 0x00000000},
7170 {160, 240, 0x00000000},
7171 {320, 240, 0x00000000},
7172 {480, 240, 0x00000000},
7173 {160, 360, 0x00000000},
7174 {320, 360, 0x00000000},
7175 {480, 360, 0x00000000},
7177 expected_point_far
[] =
7179 {160, 120, 0x00000000},
7180 {320, 120, 0x00000000},
7181 {480, 120, 0x00000000},
7182 {160, 240, 0x00000000},
7183 {320, 240, 0x00ffffff},
7184 {480, 240, 0x00000000},
7185 {160, 360, 0x00000000},
7186 {320, 360, 0x00000000},
7187 {480, 360, 0x00000000},
7192 float specular_power
;
7193 const struct expected_color
*expected
;
7194 unsigned int expected_count
;
7198 {&directional
, 30.0f
, expected_directional_local
, ARRAY_SIZE(expected_directional_local
)},
7199 {&point
, 30.0f
, expected_point_local
, ARRAY_SIZE(expected_point_local
)},
7200 {&spot
, 30.0f
, expected_spot_local
, ARRAY_SIZE(expected_spot_local
)},
7201 {¶llelpoint
, 30.0f
, expected_parallelpoint
, ARRAY_SIZE(expected_parallelpoint
)},
7202 {&point_side
, 0.0f
, expected_point_side
, ARRAY_SIZE(expected_point_side
)},
7203 {&point_far
, 1.0f
, expected_point_far
, ARRAY_SIZE(expected_point_far
)},
7206 IDirect3DDevice2
*device
;
7207 IDirectDraw2
*ddraw
;
7208 IDirectDrawSurface
*rt
;
7209 IDirect3DViewport2
*viewport
;
7210 IDirect3DMaterial2
*material
, *background_material
;
7211 IDirect3DLight
*light
;
7212 D3DMATERIALHANDLE mat_handle
;
7217 unsigned int i
, j
, x
, y
;
7221 window
= create_window();
7222 ddraw
= create_ddraw();
7223 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7224 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
7226 skip("Failed to create a 3D device, skipping test.\n");
7227 DestroyWindow(window
);
7231 quad
= HeapAlloc(GetProcessHeap(), 0, vertices_side
* vertices_side
* sizeof(*quad
));
7232 indices
= HeapAlloc(GetProcessHeap(), 0, indices_count
* sizeof(*indices
));
7233 for (i
= 0, y
= 0; y
< vertices_side
; ++y
)
7235 for (x
= 0; x
< vertices_side
; ++x
)
7237 U1(quad
[i
]).x
= x
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
7238 U2(quad
[i
]).y
= y
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
7239 U3(quad
[i
]).z
= 1.0f
;
7240 U4(quad
[i
]).nx
= 0.0f
;
7241 U5(quad
[i
]).ny
= 0.0f
;
7242 U6(quad
[i
]).nz
= -1.0f
;
7243 U7(quad
[i
]).tu
= 0.0f
;
7244 U8(quad
[i
++]).tv
= 0.0f
;
7247 for (i
= 0, y
= 0; y
< (vertices_side
- 1); ++y
)
7249 for (x
= 0; x
< (vertices_side
- 1); ++x
)
7251 indices
[i
++] = y
* vertices_side
+ x
+ 1;
7252 indices
[i
++] = y
* vertices_side
+ x
;
7253 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
7254 indices
[i
++] = y
* vertices_side
+ x
+ 1;
7255 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
7256 indices
[i
++] = (y
+ 1) * vertices_side
+ x
+ 1;
7260 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
7261 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
7263 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
7264 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
7266 viewport
= create_viewport(device
, 0, 0, 640, 480);
7267 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
7268 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
7270 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
7271 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
7272 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
7273 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
7274 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
7275 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
7276 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
7277 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
7278 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
7279 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
7280 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
7281 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
7283 background_material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
7284 viewport_set_background(device
, viewport
, background_material
);
7286 hr
= IDirect3D2_CreateLight(d3d
, &light
, NULL
);
7287 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
7288 hr
= IDirect3DViewport2_AddLight(viewport
, light
);
7289 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
7291 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, TRUE
);
7292 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
7294 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
7296 tests
[i
].light
->dwFlags
= D3DLIGHT_ACTIVE
;
7297 hr
= IDirect3DLight_SetLight(light
, (D3DLIGHT
*)tests
[i
].light
);
7298 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
7300 material
= create_specular_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, tests
[i
].specular_power
);
7301 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &mat_handle
);
7302 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
7303 hr
= IDirect3DDevice2_SetLightState(device
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
7304 ok(SUCCEEDED(hr
), "Failed to set material state, hr %#x.\n", hr
);
7306 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7307 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7309 hr
= IDirect3DDevice2_BeginScene(device
);
7310 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7312 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, D3DVT_VERTEX
,
7313 quad
, vertices_side
* vertices_side
, indices
, indices_count
, 0);
7314 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7316 hr
= IDirect3DDevice2_EndScene(device
);
7317 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7319 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
7321 color
= get_surface_color(rt
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
7322 ok(compare_color(color
, tests
[i
].expected
[j
].color
, 1),
7323 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
7324 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
7325 tests
[i
].expected
[j
].y
, color
, i
);
7328 destroy_material(material
);
7331 hr
= IDirect3DViewport2_DeleteLight(viewport
, light
);
7332 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
7333 IDirect3DLight_Release(light
);
7334 destroy_material(background_material
);
7335 destroy_viewport(device
, viewport
);
7336 IDirectDrawSurface2_Release(rt
);
7337 refcount
= IDirect3DDevice2_Release(device
);
7338 ok(!refcount
, "Device has %u references left.\n", refcount
);
7339 IDirect3D2_Release(d3d
);
7340 refcount
= IDirectDraw2_Release(ddraw
);
7341 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
7342 DestroyWindow(window
);
7343 HeapFree(GetProcessHeap(), 0, indices
);
7344 HeapFree(GetProcessHeap(), 0, quad
);
7347 static void test_palette_gdi(void)
7349 IDirectDrawSurface
*surface
, *primary
;
7350 DDSURFACEDESC surface_desc
;
7351 IDirectDraw2
*ddraw
;
7352 IDirectDrawPalette
*palette
, *palette2
;
7356 PALETTEENTRY palette_entries
[256];
7362 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7363 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7364 * not the point of this test. */
7365 static const RGBQUAD expected1
[] =
7367 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7368 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7370 static const RGBQUAD expected2
[] =
7372 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7373 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7375 static const RGBQUAD expected3
[] =
7377 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7378 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7380 HPALETTE ddraw_palette_handle
;
7381 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7382 RGBQUAD rgbquad
[255];
7383 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
7385 window
= create_window();
7386 ddraw
= create_ddraw();
7387 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7388 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7389 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7391 memset(&surface_desc
, 0, sizeof(surface_desc
));
7392 surface_desc
.dwSize
= sizeof(surface_desc
);
7393 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7394 surface_desc
.dwWidth
= 16;
7395 surface_desc
.dwHeight
= 16;
7396 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7397 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7398 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7399 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
7400 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7401 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7403 /* Avoid colors from the Windows default palette. */
7404 memset(palette_entries
, 0, sizeof(palette_entries
));
7405 palette_entries
[1].peRed
= 0x01;
7406 palette_entries
[2].peGreen
= 0x02;
7407 palette_entries
[3].peBlue
= 0x03;
7408 palette_entries
[4].peRed
= 0x13;
7409 palette_entries
[4].peGreen
= 0x14;
7410 palette_entries
[4].peBlue
= 0x15;
7411 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7412 palette_entries
, &palette
, NULL
);
7413 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7415 /* If there is no palette assigned and the display mode is not 8 bpp, some
7416 * drivers refuse to create a DC while others allow it. If a DC is created,
7417 * the DIB color table is uninitialized and contains random colors. No error
7418 * is generated when trying to read pixels and random garbage is returned.
7420 * The most likely explanation is that if the driver creates a DC, it (or
7421 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7422 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7423 * contains uninitialized garbage. See comments below for the P8 case. */
7425 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
7426 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7427 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7428 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7429 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7430 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7431 "Got unexpected palette %p, expected %p.\n",
7432 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7434 i
= GetDIBColorTable(dc
, 0, ARRAY_SIZE(rgbquad
), rgbquad
);
7435 ok(i
== ARRAY_SIZE(rgbquad
), "Expected count 255, got %u.\n", i
);
7436 for (i
= 0; i
< ARRAY_SIZE(expected1
); i
++)
7438 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
7439 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7440 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7441 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
7443 for (; i
< ARRAY_SIZE(rgbquad
); i
++)
7445 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7446 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7447 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7450 /* Update the palette while the DC is in use. This does not modify the DC. */
7451 palette_entries
[4].peRed
= 0x23;
7452 palette_entries
[4].peGreen
= 0x24;
7453 palette_entries
[4].peBlue
= 0x25;
7454 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
7455 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
7457 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7458 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7459 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7460 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7461 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7462 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7464 /* Neither does re-setting the palette. */
7465 hr
= IDirectDrawSurface_SetPalette(surface
, NULL
);
7466 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7467 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
7468 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7470 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7471 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7472 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7473 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7474 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7475 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7477 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7478 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7480 /* Refresh the DC. This updates the palette. */
7481 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7482 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7483 i
= GetDIBColorTable(dc
, 0, ARRAY_SIZE(rgbquad
), rgbquad
);
7484 ok(i
== ARRAY_SIZE(rgbquad
), "Expected count 255, got %u.\n", i
);
7485 for (i
= 0; i
< ARRAY_SIZE(expected2
); i
++)
7487 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7488 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7489 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7490 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7492 for (; i
< ARRAY_SIZE(rgbquad
); i
++)
7494 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7495 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7496 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7498 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7499 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7501 refcount
= IDirectDrawSurface_Release(surface
);
7502 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7504 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
7505 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7506 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7508 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7509 IDirectDrawPalette_Release(palette
);
7510 IDirectDraw2_Release(ddraw
);
7511 DestroyWindow(window
);
7514 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
7516 memset(&surface_desc
, 0, sizeof(surface_desc
));
7517 surface_desc
.dwSize
= sizeof(surface_desc
);
7518 surface_desc
.dwFlags
= DDSD_CAPS
;
7519 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7520 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
7521 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7523 memset(&fx
, 0, sizeof(fx
));
7524 fx
.dwSize
= sizeof(fx
);
7525 U5(fx
).dwFillColor
= 3;
7526 SetRect(&r
, 0, 0, 319, 479);
7527 hr
= IDirectDrawSurface_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7528 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
7529 SetRect(&r
, 320, 0, 639, 479);
7530 U5(fx
).dwFillColor
= 4;
7531 hr
= IDirectDrawSurface_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7532 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
7534 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
7535 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7536 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
7537 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7539 color
= GetPixel(dc
, 160, 240);
7540 ok(color
== 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color
);
7541 color
= GetPixel(dc
, 480, 240);
7542 ok(color
== 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color
);
7544 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7545 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7546 "Got unexpected palette %p, expected %p.\n",
7547 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7548 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
7550 /* The primary uses the system palette. In exclusive mode, the system palette matches
7551 * the ddraw palette attached to the primary, so the result is what you would expect
7552 * from a regular surface. Tests for the interaction between the ddraw palette and
7553 * the system palette are not included pending an application that depends on this.
7554 * The relation between those causes problems on Windows Vista and newer for games
7555 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
7556 i
= GetDIBColorTable(dc
, 0, ARRAY_SIZE(rgbquad
), rgbquad
);
7557 ok(i
== ARRAY_SIZE(rgbquad
), "Expected count 255, got %u.\n", i
);
7558 for (i
= 0; i
< ARRAY_SIZE(expected2
); i
++)
7560 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7561 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7562 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7563 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7565 for (; i
< ARRAY_SIZE(rgbquad
); i
++)
7567 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7568 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7569 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7571 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
7572 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7574 memset(&surface_desc
, 0, sizeof(surface_desc
));
7575 surface_desc
.dwSize
= sizeof(surface_desc
);
7576 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7577 surface_desc
.dwWidth
= 16;
7578 surface_desc
.dwHeight
= 16;
7579 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7580 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7581 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7583 /* Here the offscreen surface appears to use the primary's palette,
7584 * but in all likelihood it is actually the system palette. */
7585 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7586 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7587 i
= GetDIBColorTable(dc
, 0, ARRAY_SIZE(rgbquad
), rgbquad
);
7588 ok(i
== ARRAY_SIZE(rgbquad
), "Expected count 255, got %u.\n", i
);
7589 for (i
= 0; i
< ARRAY_SIZE(expected2
); i
++)
7591 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7592 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7593 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7594 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7596 for (; i
< ARRAY_SIZE(rgbquad
); i
++)
7598 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7599 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7600 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7602 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7603 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7605 /* On real hardware a change to the primary surface's palette applies immediately,
7606 * even on device contexts from offscreen surfaces that do not have their own
7607 * palette. On the testbot VMs this is not the case. Don't test this until we
7608 * know of an application that depends on this. */
7610 memset(palette_entries
, 0, sizeof(palette_entries
));
7611 palette_entries
[1].peBlue
= 0x40;
7612 palette_entries
[2].peRed
= 0x40;
7613 palette_entries
[3].peGreen
= 0x40;
7614 palette_entries
[4].peRed
= 0x12;
7615 palette_entries
[4].peGreen
= 0x34;
7616 palette_entries
[4].peBlue
= 0x56;
7617 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7618 palette_entries
, &palette2
, NULL
);
7619 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7620 hr
= IDirectDrawSurface_SetPalette(surface
, palette2
);
7621 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7623 /* A palette assigned to the offscreen surface overrides the primary / system
7625 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
7626 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7627 i
= GetDIBColorTable(dc
, 0, ARRAY_SIZE(rgbquad
), rgbquad
);
7628 ok(i
== ARRAY_SIZE(rgbquad
), "Expected count 255, got %u.\n", i
);
7629 for (i
= 0; i
< ARRAY_SIZE(expected3
); i
++)
7631 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
7632 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7633 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7634 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
7636 for (; i
< ARRAY_SIZE(rgbquad
); i
++)
7638 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7639 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7640 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7642 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
7643 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7645 refcount
= IDirectDrawSurface_Release(surface
);
7646 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7648 /* The Windows 8 testbot keeps extra references to the primary and
7649 * backbuffer while in 8 bpp mode. */
7650 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
7651 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7653 refcount
= IDirectDrawSurface_Release(primary
);
7654 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7655 refcount
= IDirectDrawPalette_Release(palette2
);
7656 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7657 refcount
= IDirectDrawPalette_Release(palette
);
7658 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7659 refcount
= IDirectDraw2_Release(ddraw
);
7660 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7661 DestroyWindow(window
);
7664 static void test_palette_alpha(void)
7666 IDirectDrawSurface
*surface1
;
7667 IDirectDrawSurface2
*surface
;
7668 DDSURFACEDESC surface_desc
;
7669 IDirectDraw2
*ddraw
;
7670 IDirectDrawPalette
*palette
;
7674 PALETTEENTRY palette_entries
[256];
7679 BOOL attach_allowed
;
7684 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
7685 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
7686 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
7689 window
= create_window();
7690 ddraw
= create_ddraw();
7691 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7692 if (FAILED(IDirectDraw2_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7694 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7695 IDirectDraw2_Release(ddraw
);
7696 DestroyWindow(window
);
7699 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7700 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7702 memset(palette_entries
, 0, sizeof(palette_entries
));
7703 palette_entries
[1].peFlags
= 0x42;
7704 palette_entries
[2].peFlags
= 0xff;
7705 palette_entries
[3].peFlags
= 0x80;
7706 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
7707 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7709 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7710 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7711 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7712 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7713 palette_entries
[0].peFlags
);
7714 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7715 palette_entries
[1].peFlags
);
7716 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7717 palette_entries
[2].peFlags
);
7718 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7719 palette_entries
[3].peFlags
);
7721 IDirectDrawPalette_Release(palette
);
7723 memset(palette_entries
, 0, sizeof(palette_entries
));
7724 palette_entries
[1].peFlags
= 0x42;
7725 palette_entries
[1].peRed
= 0xff;
7726 palette_entries
[2].peFlags
= 0xff;
7727 palette_entries
[3].peFlags
= 0x80;
7728 hr
= IDirectDraw2_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
7729 palette_entries
, &palette
, NULL
);
7730 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7732 memset(palette_entries
, 0x66, sizeof(palette_entries
));
7733 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
7734 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
7735 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7736 palette_entries
[0].peFlags
);
7737 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7738 palette_entries
[1].peFlags
);
7739 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7740 palette_entries
[2].peFlags
);
7741 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7742 palette_entries
[3].peFlags
);
7744 for (i
= 0; i
< ARRAY_SIZE(test_data
); i
++)
7746 memset(&surface_desc
, 0, sizeof(surface_desc
));
7747 surface_desc
.dwSize
= sizeof(surface_desc
);
7748 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
7749 surface_desc
.dwWidth
= 128;
7750 surface_desc
.dwHeight
= 128;
7751 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
7752 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7753 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7754 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
7755 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
7756 IDirectDrawSurface_Release(surface1
);
7758 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
7759 if (test_data
[i
].attach_allowed
)
7760 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
7762 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7770 hr
= IDirectDrawSurface2_GetDC(surface
, &dc
);
7771 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_CANTCREATEDC
) /* Win2k testbot */,
7772 "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
7775 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
7776 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
7777 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
7778 rgbquad
.rgbRed
, test_data
[i
].name
);
7779 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
7780 rgbquad
.rgbGreen
, test_data
[i
].name
);
7781 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
7782 rgbquad
.rgbBlue
, test_data
[i
].name
);
7783 ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
7784 rgbquad
.rgbReserved
, test_data
[i
].name
);
7785 hr
= IDirectDrawSurface2_ReleaseDC(surface
, dc
);
7786 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7789 IDirectDrawSurface2_Release(surface
);
7792 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
7793 memset(&surface_desc
, 0, sizeof(surface_desc
));
7794 surface_desc
.dwSize
= sizeof(surface_desc
);
7795 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7796 surface_desc
.dwWidth
= 128;
7797 surface_desc
.dwHeight
= 128;
7798 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7799 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7800 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7801 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7802 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7803 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7804 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7805 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
7806 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7807 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
7808 ok(SUCCEEDED(hr
), "Failed to get IDirectDrawSurface2 interface, hr %#x.\n", hr
);
7809 IDirectDrawSurface_Release(surface1
);
7811 hr
= IDirectDrawSurface2_SetPalette(surface
, palette
);
7812 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
7813 IDirectDrawSurface2_Release(surface
);
7815 /* The Windows 8 testbot keeps extra references to the primary
7816 * while in 8 bpp mode. */
7817 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
7818 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7820 refcount
= IDirectDrawPalette_Release(palette
);
7821 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7822 refcount
= IDirectDraw2_Release(ddraw
);
7823 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7824 DestroyWindow(window
);
7827 static void test_lost_device(void)
7829 IDirectDrawSurface
*surface
;
7830 DDSURFACEDESC surface_desc
;
7831 HWND window1
, window2
;
7832 IDirectDraw2
*ddraw
;
7837 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7838 0, 0, 640, 480, 0, 0, 0, 0);
7839 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7840 0, 0, 640, 480, 0, 0, 0, 0);
7841 ddraw
= create_ddraw();
7842 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7843 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7844 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7846 memset(&surface_desc
, 0, sizeof(surface_desc
));
7847 surface_desc
.dwSize
= sizeof(surface_desc
);
7848 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
7849 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
7850 surface_desc
.dwBackBufferCount
= 1;
7851 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7852 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7854 hr
= IDirectDrawSurface_IsLost(surface
);
7855 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7856 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7857 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7859 ret
= SetForegroundWindow(GetDesktopWindow());
7860 ok(ret
, "Failed to set foreground window.\n");
7861 hr
= IDirectDrawSurface_IsLost(surface
);
7862 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7863 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7864 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7866 ret
= SetForegroundWindow(window1
);
7867 ok(ret
, "Failed to set foreground window.\n");
7868 hr
= IDirectDrawSurface_IsLost(surface
);
7869 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7870 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7871 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7873 hr
= restore_surfaces(ddraw
);
7874 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7875 hr
= IDirectDrawSurface_IsLost(surface
);
7876 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7877 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7878 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7880 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
7881 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7882 hr
= IDirectDrawSurface_IsLost(surface
);
7883 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7884 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7885 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7887 /* Trying to restore the primary will crash, probably because flippable
7888 * surfaces can't exist in DDSCL_NORMAL. */
7889 IDirectDrawSurface_Release(surface
);
7890 memset(&surface_desc
, 0, sizeof(surface_desc
));
7891 surface_desc
.dwSize
= sizeof(surface_desc
);
7892 surface_desc
.dwFlags
= DDSD_CAPS
;
7893 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7894 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7895 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7897 hr
= IDirectDrawSurface_IsLost(surface
);
7898 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7900 ret
= SetForegroundWindow(GetDesktopWindow());
7901 ok(ret
, "Failed to set foreground window.\n");
7902 hr
= IDirectDrawSurface_IsLost(surface
);
7903 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7905 ret
= SetForegroundWindow(window1
);
7906 ok(ret
, "Failed to set foreground window.\n");
7907 hr
= IDirectDrawSurface_IsLost(surface
);
7908 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7910 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7911 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7912 hr
= IDirectDrawSurface_IsLost(surface
);
7913 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7915 hr
= restore_surfaces(ddraw
);
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
);
7920 IDirectDrawSurface_Release(surface
);
7921 memset(&surface_desc
, 0, sizeof(surface_desc
));
7922 surface_desc
.dwSize
= sizeof(surface_desc
);
7923 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
7924 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
7925 surface_desc
.dwBackBufferCount
= 1;
7926 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7927 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7929 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| 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
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7936 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
7937 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7938 hr
= IDirectDrawSurface_IsLost(surface
);
7939 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7940 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7941 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7943 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
7944 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7945 hr
= IDirectDrawSurface_IsLost(surface
);
7946 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7947 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7948 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7950 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
7951 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7952 hr
= IDirectDrawSurface_IsLost(surface
);
7953 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7954 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7955 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7957 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
7958 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7959 hr
= IDirectDrawSurface_IsLost(surface
);
7960 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7961 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7962 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
7964 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
7965 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
7966 hr
= IDirectDrawSurface_IsLost(surface
);
7967 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7968 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
7969 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
7971 IDirectDrawSurface_Release(surface
);
7972 refcount
= IDirectDraw2_Release(ddraw
);
7973 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7974 DestroyWindow(window2
);
7975 DestroyWindow(window1
);
7978 static void test_surface_desc_lock(void)
7980 IDirectDrawSurface
*surface
;
7981 DDSURFACEDESC surface_desc
;
7982 IDirectDraw2
*ddraw
;
7987 window
= create_window();
7988 ddraw
= create_ddraw();
7989 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7990 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7991 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7993 memset(&surface_desc
, 0, sizeof(surface_desc
));
7994 surface_desc
.dwSize
= sizeof(surface_desc
);
7995 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7996 surface_desc
.dwWidth
= 16;
7997 surface_desc
.dwHeight
= 16;
7998 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7999 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8000 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8002 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8003 surface_desc
.dwSize
= sizeof(surface_desc
);
8004 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
8005 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8006 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8008 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8009 surface_desc
.dwSize
= sizeof(surface_desc
);
8010 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
8011 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8012 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8013 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8014 surface_desc
.dwSize
= sizeof(surface_desc
);
8015 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
8016 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8017 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8018 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8019 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8021 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8022 surface_desc
.dwSize
= sizeof(surface_desc
);
8023 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
8024 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8025 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8027 IDirectDrawSurface_Release(surface
);
8028 refcount
= IDirectDraw2_Release(ddraw
);
8029 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8030 DestroyWindow(window
);
8033 static void test_texturemapblend(void)
8038 static RECT rect
= {0, 0, 64, 128};
8039 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8041 IDirectDrawSurface
*surface
, *rt
;
8042 IDirect3DTexture2
*texture
;
8043 D3DTEXTUREHANDLE texture_handle
;
8045 IDirectDraw2
*ddraw
;
8046 IDirect3DDevice2
*device
;
8047 IDirect3DMaterial2
*material
;
8048 IDirect3DViewport2
*viewport
;
8052 static D3DTLVERTEX test1_quads
[] =
8054 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {0.0f
}},
8055 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {1.0f
}},
8056 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {0.0f
}},
8057 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {1.0f
}},
8058 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {0.0f
}},
8059 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {1.0f
}},
8060 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {0.0f
}},
8061 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {1.0f
}},
8065 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {0.0f
}},
8066 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {1.0f
}},
8067 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {0.0f
}},
8068 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {1.0f
}},
8069 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {0.0f
}},
8070 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {1.0f
}},
8071 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {0.0f
}},
8072 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {1.0f
}},
8075 window
= create_window();
8076 ddraw
= create_ddraw();
8077 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8078 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8080 skip("Failed to create a 3D device, skipping test.\n");
8081 DestroyWindow(window
);
8082 IDirectDraw2_Release(ddraw
);
8086 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8087 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8089 material
= create_diffuse_material(device
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
8090 viewport
= create_viewport(device
, 0, 0, 640, 480);
8091 viewport_set_background(device
, viewport
, material
);
8092 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
8093 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
8095 /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel.
8097 * The vertex alpha is completely ignored in this case, so case 1 and 2 combined are not
8098 * a D3DTOP_MODULATE with texture alpha = 0xff in case 2 (no alpha in texture). */
8099 memset(&ddsd
, 0, sizeof(ddsd
));
8100 ddsd
.dwSize
= sizeof(ddsd
);
8101 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8102 ddsd
.dwHeight
= 128;
8104 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8105 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8106 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
8107 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8108 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8109 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8110 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8111 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
8112 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8113 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8115 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8116 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8117 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8118 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8119 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8120 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8122 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8123 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8125 memset(&fx
, 0, sizeof(fx
));
8126 fx
.dwSize
= sizeof(fx
);
8127 U5(fx
).dwFillColor
= 0xff0000ff;
8128 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8129 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8130 U5(fx
).dwFillColor
= 0x800000ff;
8131 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8132 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8134 /* Note that the ddraw1 version of this test runs tests 1-3 with D3DRENDERSTATE_COLORKEYENABLE
8135 * enabled, whereas this version only runs test 4 with color keying on. Because no color key
8136 * is set on the texture this should not result in different behavior. */
8137 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
8138 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8139 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8140 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8141 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
8142 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8143 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
8144 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8145 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
8146 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8147 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
);
8148 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8150 hr
= IDirect3DDevice2_BeginScene(device
);
8151 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8152 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8153 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8154 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8155 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8156 hr
= IDirect3DDevice2_EndScene(device
);
8157 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8159 color
= get_surface_color(rt
, 5, 5);
8160 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8161 color
= get_surface_color(rt
, 400, 5);
8162 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8163 color
= get_surface_color(rt
, 5, 245);
8164 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8165 color
= get_surface_color(rt
, 400, 245);
8166 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8168 IDirect3DTexture2_Release(texture
);
8169 ref
= IDirectDrawSurface_Release(surface
);
8170 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8172 /* Test alpha with texture that has no alpha channel - alpha should be taken from diffuse vertex color. */
8173 memset(&ddsd
, 0, sizeof(ddsd
));
8174 ddsd
.dwSize
= sizeof(ddsd
);
8175 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8176 ddsd
.dwHeight
= 128;
8178 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8179 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8180 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8181 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8182 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8183 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8184 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8186 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8187 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8189 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8190 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8191 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8192 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8193 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8194 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8196 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8197 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8199 U5(fx
).dwFillColor
= 0xff0000ff;
8200 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8201 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8202 U5(fx
).dwFillColor
= 0x800000ff;
8203 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8204 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8206 hr
= IDirect3DDevice2_BeginScene(device
);
8207 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8208 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8209 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8210 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8211 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8212 hr
= IDirect3DDevice2_EndScene(device
);
8213 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8215 color
= get_surface_color(rt
, 5, 5);
8216 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8217 color
= get_surface_color(rt
, 400, 5);
8218 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8219 color
= get_surface_color(rt
, 5, 245);
8220 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8221 color
= get_surface_color(rt
, 400, 245);
8222 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
8224 IDirect3DTexture2_Release(texture
);
8225 ref
= IDirectDrawSurface_Release(surface
);
8226 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8228 /* Test RGB - should multiply color components from diffuse vertex color and texture. */
8229 memset(&ddsd
, 0, sizeof(ddsd
));
8230 ddsd
.dwSize
= sizeof(ddsd
);
8231 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8232 ddsd
.dwHeight
= 128;
8234 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8235 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8236 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
8237 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8238 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8239 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8240 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8241 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
8242 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8243 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8245 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8246 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8247 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8248 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8249 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8250 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8252 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8253 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8255 U5(fx
).dwFillColor
= 0x00ffffff;
8256 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8257 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8258 U5(fx
).dwFillColor
= 0x00ffff80;
8259 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8260 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8262 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
8263 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8265 hr
= IDirect3DDevice2_BeginScene(device
);
8266 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8267 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test2_quads
[0], 4, 0);
8268 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8269 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test2_quads
[4], 4, 0);
8270 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8271 hr
= IDirect3DDevice2_EndScene(device
);
8272 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8274 color
= get_surface_color(rt
, 5, 5);
8275 ok(compare_color(color
, 0x00ff0040, 2), "Got unexpected color 0x%08x.\n", color
);
8276 color
= get_surface_color(rt
, 400, 5);
8277 ok(compare_color(color
, 0x00ff0080, 2), "Got unexpected color 0x%08x.\n", color
);
8278 color
= get_surface_color(rt
, 5, 245);
8279 ok(compare_color(color
, 0x00800080, 2), "Got unexpected color 0x%08x.\n", color
);
8280 color
= get_surface_color(rt
, 400, 245);
8281 ok(compare_color(color
, 0x008000ff, 2), "Got unexpected color 0x%08x.\n", color
);
8283 IDirect3DTexture2_Release(texture
);
8284 ref
= IDirectDrawSurface_Release(surface
);
8285 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8287 /* Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere). */
8288 memset(&ddsd
, 0, sizeof(ddsd
));
8289 ddsd
.dwSize
= sizeof(ddsd
);
8290 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8291 ddsd
.dwHeight
= 128;
8293 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8294 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
8295 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8296 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 16;
8297 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
8298 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
8299 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
8301 hr
= IDirectDraw2_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
8302 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8304 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture2
, (void **)&texture
);
8305 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
8306 hr
= IDirect3DTexture2_GetHandle(texture
, device
, &texture_handle
);
8307 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
8308 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
8309 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8311 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8312 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
8314 U5(fx
).dwFillColor
= 0xf800;
8315 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8316 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8317 U5(fx
).dwFillColor
= 0x001f;
8318 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8319 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
8321 ckey
.dwColorSpaceLowValue
= 0x001f;
8322 ckey
.dwColorSpaceHighValue
= 0x001f;
8323 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8324 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8326 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
8327 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8328 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
8329 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8331 hr
= IDirect3DDevice2_BeginScene(device
);
8332 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8333 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[0], 4, 0);
8334 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8335 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_TLVERTEX
, &test1_quads
[4], 4, 0);
8336 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8337 hr
= IDirect3DDevice2_EndScene(device
);
8338 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8340 color
= get_surface_color(rt
, 5, 5);
8341 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
8342 color
= get_surface_color(rt
, 400, 5);
8343 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
8344 color
= get_surface_color(rt
, 5, 245);
8345 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
8346 color
= get_surface_color(rt
, 400, 245);
8347 ok(compare_color(color
, 0x00800000, 2), "Got unexpected color 0x%08x.\n", color
);
8349 IDirect3DTexture2_Release(texture
);
8350 ref
= IDirectDrawSurface_Release(surface
);
8351 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
8353 destroy_viewport(device
, viewport
);
8354 ref
= IDirect3DMaterial2_Release(material
);
8355 ok(ref
== 0, "Material not properly released, refcount %u.\n", ref
);
8356 IDirectDrawSurface_Release(rt
);
8357 IDirect3DDevice2_Release(device
);
8358 ref
= IDirectDraw2_Release(ddraw
);
8359 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
8360 DestroyWindow(window
);
8363 static void test_viewport_clear_rect(void)
8366 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8367 static D3DRECT clear_rect2
= {{90}, {90}, {110}, {110}};
8368 IDirectDrawSurface
*rt
;
8370 IDirectDraw2
*ddraw
;
8371 IDirect3DDevice2
*device
;
8372 IDirect3DMaterial2
*red
, *green
;
8373 IDirect3DViewport2
*viewport
, *viewport2
;
8377 window
= create_window();
8378 ddraw
= create_ddraw();
8379 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8380 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8382 skip("Failed to create a 3D device, skipping test.\n");
8383 DestroyWindow(window
);
8384 IDirectDraw2_Release(ddraw
);
8388 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
8389 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8391 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
8392 viewport
= create_viewport(device
, 0, 0, 640, 480);
8393 viewport_set_background(device
, viewport
, red
);
8394 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8395 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8397 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
8398 viewport2
= create_viewport(device
, 100, 100, 20, 20);
8399 viewport_set_background(device
, viewport2
, green
);
8400 hr
= IDirect3DViewport2_Clear(viewport2
, 1, &clear_rect2
, D3DCLEAR_TARGET
);
8401 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8403 color
= get_surface_color(rt
, 85, 85); /* Outside both. */
8404 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8405 color
= get_surface_color(rt
, 95, 95); /* Outside vp, inside rect. */
8406 /* AMD GPUs ignore the viewport dimensions and only care about the rectangle. */
8407 ok(compare_color(color
, 0x00ff0000, 1) || broken(compare_color(color
, 0x0000ff00, 1)),
8408 "Got unexpected color 0x%08x.\n", color
);
8409 color
= get_surface_color(rt
, 105, 105); /* Inside both. */
8410 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
8411 color
= get_surface_color(rt
, 115, 115); /* Inside vp, outside rect. */
8412 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8413 color
= get_surface_color(rt
, 125, 125); /* Outside both. */
8414 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
8416 destroy_viewport(device
, viewport2
);
8417 destroy_material(green
);
8418 destroy_viewport(device
, viewport
);
8419 destroy_material(red
);
8420 IDirectDrawSurface_Release(rt
);
8421 IDirect3DDevice2_Release(device
);
8422 ref
= IDirectDraw2_Release(ddraw
);
8423 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
8424 DestroyWindow(window
);
8427 static void test_color_fill(void)
8430 IDirect3DDevice2
*device
;
8431 IDirectDraw2
*ddraw
;
8432 IDirectDrawSurface
*surface
, *surface2
;
8433 DDSURFACEDESC surface_desc
;
8439 RECT rect
= {5, 5, 7, 7};
8441 DWORD num_fourcc_codes
, *fourcc_codes
;
8443 BOOL support_uyvy
= FALSE
, support_yuy2
= FALSE
;
8447 HRESULT colorfill_hr
, depthfill_hr
;
8452 DDPIXELFORMAT format
;
8457 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8458 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8460 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8461 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8465 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
8466 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
8468 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8469 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8473 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
8474 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
8476 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8477 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8481 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
8482 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
8484 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
8485 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8489 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
,
8490 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0xdeadbeef, TRUE
,
8491 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
8494 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
8495 * different afterwards. DX9+ GPUs set one of the two luminance values
8496 * in each block, but AMD and Nvidia GPUs disagree on which luminance
8497 * value they set. r200 (dx8) just sets the entire block to the clear
8499 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8500 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
8502 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8503 {0}, {0}, {0}, {0}, {0}
8507 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8508 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
8510 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8511 {0}, {0}, {0}, {0}, {0}
8515 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
8516 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
8518 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
8519 {0}, {0}, {0}, {0}, {0}
8523 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
8524 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
8526 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8527 {0}, {0}, {0}, {0}, {0}
8531 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
8532 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
8534 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8535 {0}, {0}, {0}, {0}, {0}
8539 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
8540 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
8542 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
8543 {0}, {0}, {0}, {0}, {0}
8547 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
8548 * surface works, presumably because it is handled by the runtime instead of
8550 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
8551 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
8553 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
8554 {8}, {0}, {0}, {0}, {0}
8558 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
8559 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
8561 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
8562 {8}, {0}, {0}, {0}, {0}
8574 {SRCCOPY
, "SRCCOPY", DD_OK
},
8575 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
8576 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
8577 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
8578 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
8579 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
8580 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
8581 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
8582 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
8583 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
8584 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
8585 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
8586 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
8587 {BLACKNESS
, "BLACKNESS", DD_OK
},
8588 {WHITENESS
, "WHITENESS", DD_OK
},
8589 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
8592 window
= create_window();
8593 ddraw
= create_ddraw();
8594 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8595 is_warp
= ddraw_is_warp(ddraw
);
8596 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8598 skip("Failed to create a 3D device, skipping test.\n");
8599 DestroyWindow(window
);
8600 IDirectDraw2_Release(ddraw
);
8604 hr
= IDirectDraw2_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
8605 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
8606 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
8607 num_fourcc_codes
* sizeof(*fourcc_codes
));
8610 hr
= IDirectDraw2_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
8611 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
8612 for (i
= 0; i
< num_fourcc_codes
; i
++)
8614 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
8615 support_yuy2
= TRUE
;
8616 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
8617 support_uyvy
= TRUE
;
8619 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
8621 memset(&hal_caps
, 0, sizeof(hal_caps
));
8622 hal_caps
.dwSize
= sizeof(hal_caps
);
8623 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
8624 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
8626 if ((!support_yuy2
&& !support_uyvy
) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
8627 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
8629 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
8631 DWORD expected_broken
= tests
[i
].result
;
8632 DWORD mask
= 0xffffffffu
;
8634 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
8635 memset(&fx
, 0, sizeof(fx
));
8636 fx
.dwSize
= sizeof(fx
);
8637 U5(fx
).dwFillColor
= 0xdeadbeef;
8639 memset(&surface_desc
, 0, sizeof(surface_desc
));
8640 surface_desc
.dwSize
= sizeof(surface_desc
);
8641 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8642 surface_desc
.dwWidth
= 64;
8643 surface_desc
.dwHeight
= 64;
8644 surface_desc
.ddpfPixelFormat
= tests
[i
].format
;
8645 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
8647 if (tests
[i
].caps
& DDSCAPS_TEXTURE
)
8649 struct format_support_check check
= {&tests
[i
].format
, FALSE
};
8650 hr
= IDirect3DDevice2_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
8651 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
8652 if (!check
.supported
)
8656 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !support_yuy2
)
8658 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !support_uyvy
)
8660 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
8663 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
8665 surface_desc
.dwFlags
&= ~DDSD_PIXELFORMAT
;
8666 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
8667 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
8668 mask
>>= (32 - U2(surface_desc
).dwZBufferBitDepth
);
8669 /* Some drivers seem to convert depth values incorrectly or not at
8670 * all. Affects at least AMD PALM, 8.17.10.1247. */
8671 if (tests
[i
].caps
& DDSCAPS_VIDEOMEMORY
)
8676 expected
= tests
[i
].result
& mask
;
8677 f
= ceilf(log2f(expected
+ 1.0f
));
8678 g
= (f
+ 1.0f
) / 2.0f
;
8680 expected_broken
= (expected
/ exp2f(f
) - g
) * 256;
8681 expected_broken
*= 0x01010101;
8685 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8686 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8688 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8689 todo_wine_if (tests
[i
].format
.dwFourCC
)
8690 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8691 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8693 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8694 todo_wine_if (tests
[i
].format
.dwFourCC
)
8695 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8696 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
8698 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8700 memset(&surface_desc
, 0, sizeof(surface_desc
));
8701 surface_desc
.dwSize
= sizeof(surface_desc
);
8702 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8703 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8704 color
= surface_desc
.lpSurface
;
8705 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
8706 *color
, tests
[i
].result
, tests
[i
].name
);
8707 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8708 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8711 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8712 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8713 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
8714 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8715 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
8716 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
8718 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8720 memset(&surface_desc
, 0, sizeof(surface_desc
));
8721 surface_desc
.dwSize
= sizeof(surface_desc
);
8722 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8723 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8724 color
= surface_desc
.lpSurface
;
8725 todo_wine_if(tests
[i
].caps
& DDSCAPS_VIDEOMEMORY
&& U2(surface_desc
).dwZBufferBitDepth
!= 16)
8726 ok((*color
& mask
) == (tests
[i
].result
& mask
) || broken((*color
& mask
) == (expected_broken
& mask
))
8727 || broken(is_warp
&& (*color
& mask
) == (~0u & mask
)) /* Windows 8+ testbot. */,
8728 "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
8729 *color
& mask
, tests
[i
].result
& mask
, tests
[i
].name
);
8730 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8731 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8734 U5(fx
).dwFillColor
= 0xdeadbeef;
8735 fx
.dwROP
= BLACKNESS
;
8736 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8737 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
8738 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
8739 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8740 U5(fx
).dwFillColor
, tests
[i
].name
);
8742 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8744 memset(&surface_desc
, 0, sizeof(surface_desc
));
8745 surface_desc
.dwSize
= sizeof(surface_desc
);
8746 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8747 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8748 color
= surface_desc
.lpSurface
;
8749 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
8750 *color
, tests
[i
].name
);
8751 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8752 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8755 fx
.dwROP
= WHITENESS
;
8756 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8757 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
8758 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
8759 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8760 U5(fx
).dwFillColor
, tests
[i
].name
);
8762 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
8764 memset(&surface_desc
, 0, sizeof(surface_desc
));
8765 surface_desc
.dwSize
= sizeof(surface_desc
);
8766 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
8767 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8768 color
= surface_desc
.lpSurface
;
8769 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
8770 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
8771 *color
, tests
[i
].name
);
8772 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8773 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
8776 IDirectDrawSurface_Release(surface
);
8779 memset(&fx
, 0, sizeof(fx
));
8780 fx
.dwSize
= sizeof(fx
);
8781 U5(fx
).dwFillColor
= 0xdeadbeef;
8782 fx
.dwROP
= WHITENESS
;
8784 memset(&surface_desc
, 0, sizeof(surface_desc
));
8785 surface_desc
.dwSize
= sizeof(surface_desc
);
8786 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8787 surface_desc
.dwWidth
= 64;
8788 surface_desc
.dwHeight
= 64;
8789 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
8790 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8791 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8792 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8793 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8794 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8795 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
8796 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8797 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8798 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
8799 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8802 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
8803 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8804 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
8805 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8807 /* Unused source rectangle. */
8808 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8809 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8810 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8811 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8813 /* Unused source surface. */
8814 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8815 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8816 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8817 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8818 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8819 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8820 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8821 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8823 /* Inverted destination or source rectangle. */
8824 SetRect(&rect
, 5, 7, 7, 5);
8825 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8826 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8827 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8828 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8829 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8830 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8831 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8832 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8833 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8834 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8836 /* Negative rectangle. */
8837 SetRect(&rect
, -1, -1, 5, 5);
8838 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8839 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8840 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8841 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8842 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8843 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8844 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8845 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8846 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8847 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8849 /* Out of bounds rectangle. */
8850 SetRect(&rect
, 0, 0, 65, 65);
8851 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
8852 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8853 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8854 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8856 /* Combine multiple flags. */
8857 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8858 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8859 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8860 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8861 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8862 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8864 for (i
= 0; i
< ARRAY_SIZE(rops
); i
++)
8866 fx
.dwROP
= rops
[i
].rop
;
8867 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
8868 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
8871 IDirectDrawSurface_Release(surface2
);
8872 IDirectDrawSurface_Release(surface
);
8874 memset(&surface_desc
, 0, sizeof(surface_desc
));
8875 surface_desc
.dwSize
= sizeof(surface_desc
);
8876 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_ZBUFFERBITDEPTH
;
8877 surface_desc
.dwWidth
= 64;
8878 surface_desc
.dwHeight
= 64;
8879 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
8880 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
8881 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8882 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8883 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
8884 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8887 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
8888 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8890 /* Unused source rectangle. */
8891 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8892 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8894 /* Unused source surface. */
8895 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8896 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8897 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8898 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8900 /* Inverted destination or source rectangle. */
8901 SetRect(&rect
, 5, 7, 7, 5);
8902 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8903 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8904 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8905 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8906 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8907 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8908 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8909 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8911 /* Negative rectangle. */
8912 SetRect(&rect
, -1, -1, 5, 5);
8913 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8914 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8915 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8916 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
8917 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8918 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8919 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8920 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8922 /* Out of bounds rectangle. */
8923 SetRect(&rect
, 0, 0, 65, 65);
8924 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8925 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
8927 /* Combine multiple flags. */
8928 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
8929 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8931 IDirectDrawSurface_Release(surface2
);
8932 IDirectDrawSurface_Release(surface
);
8935 IDirect3DDevice2_Release(device
);
8936 refcount
= IDirectDraw2_Release(ddraw
);
8937 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
8938 DestroyWindow(window
);
8941 static void test_colorkey_precision(void)
8943 static D3DLVERTEX quad
[] =
8945 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {0.0f
}, {0.0f
}},
8946 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {0.0f
}, {1.0f
}},
8947 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {1.0f
}, {0.0f
}},
8948 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff000000}, {0}, {1.0f
}, {1.0f
}},
8950 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8951 IDirect3DDevice2
*device
;
8952 IDirectDraw2
*ddraw
;
8953 IDirectDrawSurface
*rt
;
8954 IDirect3DViewport2
*viewport
;
8957 IDirectDrawSurface
*src
, *dst
, *texture
;
8958 D3DTEXTUREHANDLE handle
;
8959 IDirect3DTexture2
*d3d_texture
;
8960 IDirect3DMaterial2
*green
;
8961 DDSURFACEDESC surface_desc
, lock_desc
;
8967 DWORD data
[4] = {0}, color_mask
;
8968 BOOL is_nvidia
, is_warp
;
8971 unsigned int max
, shift
, bpp
, clear
;
8979 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE
,
8981 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8982 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
8987 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE
,
8989 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8990 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
8995 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE
,
8997 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
8998 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9003 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE
,
9005 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9006 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
9011 window
= create_window();
9012 ddraw
= create_ddraw();
9013 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9014 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9016 skip("Failed to create a 3D device, skipping test.\n");
9017 DestroyWindow(window
);
9018 IDirectDraw2_Release(ddraw
);
9021 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9022 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9024 is_nvidia
= ddraw_is_nvidia(ddraw
);
9025 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
9026 * (color key doesn't match although the values are equal), and a false
9027 * positive when the color key is 0 and the texture contains the value 1.
9028 * I don't want to mark this broken unconditionally since this would
9029 * essentially disable the test on Windows. Also on random occasions
9030 * 254 == 255 and 255 != 255.*/
9031 is_warp
= ddraw_is_warp(ddraw
);
9033 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
9034 viewport
= create_viewport(device
, 0, 0, 640, 480);
9035 viewport_set_background(device
, viewport
, green
);
9036 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
9037 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
9039 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9040 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9041 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
9042 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
9043 /* There's no way to ignore the texture color in d3d2, so multiply the texture color
9044 * with a black vertex color. */
9045 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATEALPHA
);
9046 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9048 memset(&fx
, 0, sizeof(fx
));
9049 fx
.dwSize
= sizeof(fx
);
9050 memset(&lock_desc
, 0, sizeof(lock_desc
));
9051 lock_desc
.dwSize
= sizeof(lock_desc
);
9053 for (t
= 0; t
< ARRAY_SIZE(tests
); ++t
)
9055 if (is_nvidia
&& tests
[t
].skip_nv
)
9057 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests
[t
].name
);
9061 memset(&surface_desc
, 0, sizeof(surface_desc
));
9062 surface_desc
.dwSize
= sizeof(surface_desc
);
9063 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9064 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9065 surface_desc
.dwWidth
= 4;
9066 surface_desc
.dwHeight
= 1;
9067 surface_desc
.ddpfPixelFormat
= tests
[t
].fmt
;
9068 /* Windows XP (at least with the r200 driver, other drivers untested) produces
9069 * garbage when doing color keyed texture->texture blits. */
9070 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
9071 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9072 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
9073 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9075 U5(fx
).dwFillColor
= tests
[t
].clear
;
9076 /* On the w8 testbot (WARP driver) the blit result has different values in the
9078 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
9079 | U3(tests
[t
].fmt
).dwGBitMask
9080 | U4(tests
[t
].fmt
).dwBBitMask
;
9082 for (c
= 0; c
<= tests
[t
].max
; ++c
)
9084 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
9085 * texture after it has been set once... */
9086 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
9087 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9088 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9089 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9090 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
9091 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9093 hr
= IDirectDrawSurface4_QueryInterface(texture
, &IID_IDirect3DTexture2
, (void **)&d3d_texture
);
9094 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
9095 hr
= IDirect3DTexture2_GetHandle(d3d_texture
, device
, &handle
);
9096 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
9097 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, handle
);
9098 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
9099 IDirect3DTexture2_Release(d3d_texture
);
9101 hr
= IDirectDrawSurface_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9102 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
9104 hr
= IDirectDrawSurface_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9105 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9106 switch (tests
[t
].bpp
)
9109 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9110 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9111 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9112 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
9116 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
9117 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
9118 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
9119 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
9122 hr
= IDirectDrawSurface_Unlock(src
, 0);
9123 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9124 hr
= IDirectDrawSurface_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
9125 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9127 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
9128 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
9129 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
9130 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9132 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
9133 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9135 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
9136 hr
= IDirectDrawSurface_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
9137 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9138 switch (tests
[t
].bpp
)
9141 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9142 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9143 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9144 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
9148 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
9149 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
9150 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
9151 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
9154 hr
= IDirectDrawSurface_Unlock(dst
, 0);
9155 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9159 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9160 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
9162 if (data
[3] == tests
[t
].clear
)
9164 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
9165 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
9166 * even when a different surface is used. The blit itself doesn't draw anything,
9167 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
9168 * never be masked out by the key.
9170 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
9171 * test is disabled entirely.
9173 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
9174 * terrible on WARP. */
9175 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
9176 IDirectDrawSurface_Release(texture
);
9177 IDirectDrawSurface_Release(src
);
9178 IDirectDrawSurface_Release(dst
);
9183 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9184 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
9186 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9187 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
9189 if (c
== tests
[t
].max
)
9190 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9191 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
9193 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
9194 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
9196 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
9197 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9199 hr
= IDirect3DDevice2_BeginScene(device
);
9200 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9201 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
9202 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9203 hr
= IDirect3DDevice2_EndScene(device
);
9204 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9206 color
= get_surface_color(rt
, 80, 240);
9208 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9209 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9210 color
, tests
[t
].name
, c
);
9212 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
9213 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9214 color
, tests
[t
].name
, c
);
9216 color
= get_surface_color(rt
, 240, 240);
9217 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9218 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9219 color
, tests
[t
].name
, c
);
9221 color
= get_surface_color(rt
, 400, 240);
9222 if (c
== tests
[t
].max
)
9223 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
9224 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9225 color
, tests
[t
].name
, c
);
9227 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
9228 "Got unexpected color 0x%08x, format %s, c=%u.\n",
9229 color
, tests
[t
].name
, c
);
9231 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
9232 ok(SUCCEEDED(hr
), "Failed to set texture handle, hr %#x.\n", hr
);
9233 IDirectDrawSurface_Release(texture
);
9235 IDirectDrawSurface_Release(src
);
9236 IDirectDrawSurface_Release(dst
);
9240 destroy_viewport(device
, viewport
);
9241 destroy_material(green
);
9242 IDirectDrawSurface_Release(rt
);
9243 IDirect3DDevice2_Release(device
);
9244 refcount
= IDirectDraw2_Release(ddraw
);
9245 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
9246 DestroyWindow(window
);
9249 static void test_range_colorkey(void)
9251 IDirectDraw2
*ddraw
;
9254 IDirectDrawSurface
*surface
;
9255 DDSURFACEDESC surface_desc
;
9259 window
= create_window();
9260 ddraw
= create_ddraw();
9261 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9262 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9263 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9265 memset(&surface_desc
, 0, sizeof(surface_desc
));
9266 surface_desc
.dwSize
= sizeof(surface_desc
);
9267 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
9268 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9269 surface_desc
.dwWidth
= 1;
9270 surface_desc
.dwHeight
= 1;
9271 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9272 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
9273 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9274 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9275 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9276 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
9278 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
9279 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9280 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
9281 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9282 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9284 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
9285 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9286 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9287 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9289 /* Same for DDSCAPS_OFFSCREENPLAIN. */
9290 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9291 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9292 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
9293 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9294 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9296 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
9297 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9298 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9299 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9301 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
9302 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
9303 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9304 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9306 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
9307 ckey
.dwColorSpaceLowValue
= 0x00000000;
9308 ckey
.dwColorSpaceHighValue
= 0x00000001;
9309 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9310 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9312 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9313 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9314 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9315 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9317 ckey
.dwColorSpaceLowValue
= 0x00000001;
9318 ckey
.dwColorSpaceHighValue
= 0x00000000;
9319 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9320 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9322 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9323 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9324 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9325 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9327 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
9328 ckey
.dwColorSpaceLowValue
= 0x00000000;
9329 ckey
.dwColorSpaceHighValue
= 0x00000000;
9330 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9331 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
9333 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
9334 ckey
.dwColorSpaceLowValue
= 0x00000001;
9335 ckey
.dwColorSpaceHighValue
= 0x00000000;
9336 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9337 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9338 ckey
.dwColorSpaceLowValue
= 0x00000000;
9339 ckey
.dwColorSpaceHighValue
= 0x00000001;
9340 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9341 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9342 /* Range destination keys don't work either. */
9343 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
9344 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9346 /* Just to show it's not because of A, R, and G having equal values. */
9347 ckey
.dwColorSpaceLowValue
= 0x00000000;
9348 ckey
.dwColorSpaceHighValue
= 0x01010101;
9349 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
9350 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
9352 /* None of these operations modified the key. */
9353 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
9354 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
9355 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
9356 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
9358 IDirectDrawSurface_Release(surface
),
9359 refcount
= IDirectDraw2_Release(ddraw
);
9360 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
9361 DestroyWindow(window
);
9364 static void test_shademode(void)
9366 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
9367 IDirect3DMaterial2
*background
;
9368 IDirect3DViewport2
*viewport
;
9369 IDirect3DDevice2
*device
;
9370 IDirectDrawSurface
*rt
;
9371 DWORD color0
, color1
;
9372 IDirectDraw2
*ddraw
;
9378 static D3DLVERTEX quad_strip
[] =
9380 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
9381 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9382 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9383 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
9387 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
9388 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9389 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9391 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
9392 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
9393 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
9399 DWORD color0
, color1
;
9403 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
9404 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
9405 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
9406 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
9407 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
9408 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
9411 window
= create_window();
9412 ddraw
= create_ddraw();
9413 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9414 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9416 skip("Failed to create a 3D device, skipping test.\n");
9417 IDirectDraw2_Release(ddraw
);
9418 DestroyWindow(window
);
9422 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9423 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9425 background
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
9426 viewport
= create_viewport(device
, 0, 0, 640, 480);
9427 viewport_set_background(device
, viewport
, background
);
9428 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
9429 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
9431 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
9432 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
9434 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
9435 * the color fixups we have to do for FLAT shading will be dependent on that. */
9437 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
9439 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
9440 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
9442 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
9443 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
9445 hr
= IDirect3DDevice2_BeginScene(device
);
9446 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9447 quad
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? quad_strip
: quad_list
;
9448 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
9449 hr
= IDirect3DDevice2_DrawPrimitive(device
, tests
[i
].primtype
, D3DVT_LVERTEX
, quad
, count
, 0);
9450 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9451 hr
= IDirect3DDevice2_EndScene(device
);
9452 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9454 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
9455 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
9457 /* For D3DSHADE_FLAT it should take the color of the first vertex of
9458 * each triangle. This requires EXT_provoking_vertex or similar
9459 * functionality being available. */
9460 /* PHONG should be the same as GOURAUD, since no hardware implements
9462 ok(compare_color(color0
, tests
[i
].color0
, 1), "Test %u shading has color0 %08x, expected %08x.\n",
9463 i
, color0
, tests
[i
].color0
);
9464 ok(compare_color(color1
, tests
[i
].color1
, 1), "Test %u shading has color1 %08x, expected %08x.\n",
9465 i
, color1
, tests
[i
].color1
);
9468 destroy_viewport(device
, viewport
);
9469 destroy_material(background
);
9470 IDirectDrawSurface_Release(rt
);
9471 refcount
= IDirect3DDevice2_Release(device
);
9472 ok(!refcount
, "Device has %u references left.\n", refcount
);
9473 IDirectDraw_Release(ddraw
);
9474 DestroyWindow(window
);
9477 static void test_lockrect_invalid(void)
9480 IDirectDraw2
*ddraw
;
9481 IDirectDrawSurface
*surface1
;
9482 IDirectDrawSurface2
*surface
;
9485 DDSURFACEDESC surface_desc
;
9487 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
9488 static RECT valid
[] =
9496 static RECT invalid
[] =
9498 {68, 60, 60, 68}, /* left > right */
9499 {60, 68, 68, 60}, /* top > bottom */
9500 {-8, 60, 0, 68}, /* left < surface */
9501 {60, -8, 68, 0}, /* top < surface */
9502 {-16, 60, -8, 68}, /* right < surface */
9503 {60, -16, 68, -8}, /* bottom < surface */
9504 {60, 60, 136, 68}, /* right > surface */
9505 {60, 60, 68, 136}, /* bottom > surface */
9506 {136, 60, 144, 68}, /* left > surface */
9507 {60, 136, 68, 144}, /* top > surface */
9517 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, "sysmem offscreenplain", DDERR_INVALIDPARAMS
},
9518 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, "vidmem offscreenplain", DDERR_INVALIDPARAMS
},
9519 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, "sysmem texture", DDERR_INVALIDPARAMS
},
9520 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, "vidmem texture", DDERR_INVALIDPARAMS
},
9523 window
= create_window();
9524 ddraw
= create_ddraw();
9525 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9526 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9527 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9529 memset(&hal_caps
, 0, sizeof(hal_caps
));
9530 hal_caps
.dwSize
= sizeof(hal_caps
);
9531 hr
= IDirectDraw2_GetCaps(ddraw
, &hal_caps
, NULL
);
9532 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9533 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
9535 skip("Required surface types not supported, skipping test.\n");
9539 for (r
= 0; r
< ARRAY_SIZE(resources
); ++r
)
9541 memset(&surface_desc
, 0, sizeof(surface_desc
));
9542 surface_desc
.dwSize
= sizeof(surface_desc
);
9543 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9544 surface_desc
.ddsCaps
.dwCaps
= resources
[r
].caps
;
9545 surface_desc
.dwWidth
= 128;
9546 surface_desc
.dwHeight
= 128;
9547 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
9548 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9549 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
9550 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xff0000;
9551 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x00ff00;
9552 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x0000ff;
9554 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
9555 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9556 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&surface
);
9557 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface2 interface, hr %#x.\n", hr
);
9558 IDirectDrawSurface_Release(surface1
);
9560 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, NULL
, DDLOCK_WAIT
, NULL
);
9561 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
9563 for (i
= 0; i
< ARRAY_SIZE(valid
); ++i
)
9565 RECT
*rect
= &valid
[i
];
9567 memset(&surface_desc
, 0, sizeof(surface_desc
));
9568 surface_desc
.dwSize
= sizeof(surface_desc
);
9570 hr
= IDirectDrawSurface2_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9571 ok(SUCCEEDED(hr
), "Lock failed (%#x) for rect %s, type %s.\n",
9572 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
9574 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9575 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9578 for (i
= 0; i
< ARRAY_SIZE(invalid
); ++i
)
9580 RECT
*rect
= &invalid
[i
];
9582 memset(&surface_desc
, 1, sizeof(surface_desc
));
9583 surface_desc
.dwSize
= sizeof(surface_desc
);
9585 hr
= IDirectDrawSurface2_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9586 ok(hr
== resources
[r
].hr
, "Lock returned %#x for rect %s, type %s.\n",
9587 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
9590 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9591 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9594 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
9597 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9598 ok(SUCCEEDED(hr
), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
9599 hr
, resources
[r
].name
);
9600 hr
= IDirectDrawSurface2_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
9601 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned %#x, type %s.\n",
9602 hr
, resources
[r
].name
);
9603 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9604 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9606 hr
= IDirectDrawSurface2_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
9607 ok(SUCCEEDED(hr
), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid
[0]), hr
);
9608 hr
= IDirectDrawSurface2_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
9609 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = %s) failed (%#x).\n",
9610 wine_dbgstr_rect(&valid
[0]), hr
);
9612 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
9613 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
9615 hr
= IDirectDrawSurface2_Unlock(surface
, NULL
);
9616 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
9618 IDirectDrawSurface2_Release(surface
);
9622 IDirectDraw2_Release(ddraw
);
9623 DestroyWindow(window
);
9626 static void test_yv12_overlay(void)
9628 IDirectDrawSurface
*src_surface
, *dst_surface
;
9629 RECT rect
= {13, 17, 14, 18};
9630 unsigned int offset
, y
;
9631 unsigned char *base
;
9632 IDirectDraw2
*ddraw
;
9637 window
= create_window();
9638 ddraw
= create_ddraw();
9639 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9640 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9641 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9643 if (!(src_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
9645 skip("Failed to create a YV12 overlay, skipping test.\n");
9649 memset(&desc
, 0, sizeof(desc
));
9650 desc
.dwSize
= sizeof(desc
);
9651 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
9652 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9654 ok(desc
.dwFlags
== (DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_PITCH
),
9655 "Got unexpected flags %#x.\n", desc
.dwFlags
);
9656 ok(desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_HWCODEC
)
9657 || desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
9658 "Got unexpected caps %#x.\n", desc
.ddsCaps
.dwCaps
);
9659 ok(desc
.dwWidth
== 256, "Got unexpected width %u.\n", desc
.dwWidth
);
9660 ok(desc
.dwHeight
== 256, "Got unexpected height %u.\n", desc
.dwHeight
);
9661 /* The overlay pitch seems to have 256 byte alignment. */
9662 ok(!(U1(desc
).lPitch
& 0xff), "Got unexpected pitch %u.\n", U1(desc
).lPitch
);
9664 /* Fill the surface with some data for the blit test. */
9665 base
= desc
.lpSurface
;
9667 for (y
= 0; y
< desc
.dwHeight
; ++y
)
9669 memset(base
+ U1(desc
).lPitch
* y
, 0x10, desc
.dwWidth
);
9672 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 4; ++y
)
9674 memset(base
+ U1(desc
).lPitch
* y
, 0x20, desc
.dwWidth
);
9677 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 2; ++y
)
9679 memset(base
+ U1(desc
).lPitch
* y
, 0x30, desc
.dwWidth
);
9682 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
9683 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9685 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
9686 * other block-based formats like DXT the entire Y channel is stored in
9687 * one big chunk of memory, followed by the chroma channels. So partial
9688 * locks do not really make sense. Show that they are allowed nevertheless
9689 * and the offset points into the luminance data. */
9690 hr
= IDirectDrawSurface_Lock(src_surface
, &rect
, &desc
, DDLOCK_WAIT
, NULL
);
9691 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9692 offset
= ((const unsigned char *)desc
.lpSurface
- base
);
9693 ok(offset
== rect
.top
* U1(desc
).lPitch
+ rect
.left
, "Got unexpected offset %u, expected %u.\n",
9694 offset
, rect
.top
* U1(desc
).lPitch
+ rect
.left
);
9695 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
9696 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9698 if (!(dst_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
9700 /* Windows XP with a Radeon X1600 GPU refuses to create a second
9701 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
9702 skip("Failed to create a second YV12 surface, skipping blit test.\n");
9703 IDirectDrawSurface_Release(src_surface
);
9707 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, NULL
, DDBLT_WAIT
, NULL
);
9708 /* VMware rejects YV12 blits. This behavior has not been seen on real
9709 * hardware yet, so mark it broken. */
9710 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
), "Failed to blit, hr %#x.\n", hr
);
9714 memset(&desc
, 0, sizeof(desc
));
9715 desc
.dwSize
= sizeof(desc
);
9716 hr
= IDirectDrawSurface_Lock(dst_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
9717 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9719 base
= desc
.lpSurface
;
9720 ok(base
[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base
[0]);
9721 base
+= desc
.dwHeight
* U1(desc
).lPitch
;
9722 todo_wine
ok(base
[0] == 0x20, "Got unexpected V data 0x%02x.\n", base
[0]);
9723 base
+= desc
.dwHeight
/ 4 * U1(desc
).lPitch
;
9724 todo_wine
ok(base
[0] == 0x30, "Got unexpected U data 0x%02x.\n", base
[0]);
9726 hr
= IDirectDrawSurface_Unlock(dst_surface
, NULL
);
9727 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9730 IDirectDrawSurface_Release(dst_surface
);
9731 IDirectDrawSurface_Release(src_surface
);
9733 IDirectDraw2_Release(ddraw
);
9734 DestroyWindow(window
);
9737 static BOOL
dwm_enabled(void)
9741 if (!strcmp(winetest_platform
, "wine"))
9743 if (!pDwmIsCompositionEnabled
)
9745 if (FAILED(pDwmIsCompositionEnabled(&ret
)))
9750 static void test_offscreen_overlay(void)
9752 IDirectDrawSurface
*overlay
, *offscreen
, *primary
;
9753 DDSURFACEDESC surface_desc
;
9754 IDirectDraw2
*ddraw
;
9759 window
= create_window();
9760 ddraw
= create_ddraw();
9761 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9762 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9763 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9765 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
9767 skip("Failed to create a UYVY overlay, skipping test.\n");
9771 memset(&surface_desc
, 0, sizeof(surface_desc
));
9772 surface_desc
.dwSize
= sizeof(surface_desc
);
9773 surface_desc
.dwFlags
= DDSD_CAPS
;
9774 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
9775 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
9776 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9778 /* On Windows 7, and probably Vista, UpdateOverlay() will return
9779 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
9780 * surface prevents this by disabling the dwm. */
9781 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
9782 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
9783 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
9784 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
9786 /* Try to overlay a NULL surface. */
9787 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_SHOW
, NULL
);
9788 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9789 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_HIDE
, NULL
);
9790 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9792 /* Try to overlay an offscreen surface. */
9793 memset(&surface_desc
, 0, sizeof(surface_desc
));
9794 surface_desc
.dwSize
= sizeof(surface_desc
);
9795 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
9796 surface_desc
.dwWidth
= 64;
9797 surface_desc
.dwHeight
= 64;
9798 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9799 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
9800 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9801 surface_desc
.ddpfPixelFormat
.dwFourCC
= 0;
9802 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
9803 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
9804 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
9805 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
9806 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
9807 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9809 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, offscreen
, NULL
, DDOVER_SHOW
, NULL
);
9810 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_OUTOFCAPS
&& dwm_enabled())
9811 || broken(hr
== E_NOTIMPL
&& ddraw_is_vmware(ddraw
)),
9812 "Failed to update overlay, hr %#x.\n", hr
);
9814 /* Try to overlay the primary with a non-overlay surface. */
9815 hr
= IDirectDrawSurface_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
9816 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
9817 hr
= IDirectDrawSurface_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
9818 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
9820 IDirectDrawSurface_Release(offscreen
);
9821 IDirectDrawSurface_Release(primary
);
9822 IDirectDrawSurface_Release(overlay
);
9824 IDirectDraw2_Release(ddraw
);
9825 DestroyWindow(window
);
9828 static void test_overlay_rect(void)
9830 IDirectDrawSurface
*overlay
, *primary
= NULL
;
9831 DDSURFACEDESC surface_desc
;
9832 RECT rect
= {0, 0, 64, 64};
9833 IDirectDraw2
*ddraw
;
9839 window
= create_window();
9840 ddraw
= create_ddraw();
9841 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9842 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
9843 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
9845 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
9847 skip("Failed to create a UYVY overlay, skipping test.\n");
9851 memset(&surface_desc
, 0, sizeof(surface_desc
));
9852 surface_desc
.dwSize
= sizeof(surface_desc
);
9853 surface_desc
.dwFlags
= DDSD_CAPS
;
9854 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
9855 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
9856 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
9858 /* On Windows 7, and probably Vista, UpdateOverlay() will return
9859 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
9860 * surface prevents this by disabling the dwm. */
9861 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
9862 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
9863 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
9864 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
9866 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
9869 win_skip("Cannot disable DWM, skipping overlay test.\n");
9873 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
9874 * used. This is not true in Windows Vista and earlier, but changed in
9876 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
9877 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9878 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
9879 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9880 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
9881 ok(hr
== DD_OK
|| hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9883 /* Show that the overlay position is the (top, left) coordinate of the
9884 * destination rectangle. */
9885 OffsetRect(&rect
, 32, 16);
9886 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
9887 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9888 pos_x
= -1; pos_y
= -1;
9889 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9890 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
9891 ok(pos_x
== rect
.left
, "Got unexpected pos_x %d, expected %d.\n", pos_x
, rect
.left
);
9892 ok(pos_y
== rect
.top
, "Got unexpected pos_y %d, expected %d.\n", pos_y
, rect
.top
);
9894 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
9895 * seen that the overlay overlays the whole primary(==screen). */
9896 hr2
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, 0, NULL
);
9897 ok(hr2
== DD_OK
|| hr2
== DDERR_INVALIDPARAMS
|| hr2
== DDERR_OUTOFCAPS
, "Got unexpected hr %#x.\n", hr2
);
9898 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9899 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
9902 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
9903 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
9907 ok(pos_x
== 32, "Got unexpected pos_x %d.\n", pos_x
);
9908 ok(pos_y
== 16, "Got unexpected pos_y %d.\n", pos_y
);
9911 /* The position cannot be retrieved when the overlay is not shown. */
9912 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_HIDE
, NULL
);
9913 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
9914 pos_x
= -1; pos_y
= -1;
9915 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
9916 ok(hr
== DDERR_OVERLAYNOTVISIBLE
, "Got unexpected hr %#x.\n", hr
);
9917 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
9918 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
9920 IDirectDrawSurface_Release(overlay
);
9923 IDirectDrawSurface_Release(primary
);
9924 IDirectDraw2_Release(ddraw
);
9925 DestroyWindow(window
);
9928 static void test_blt(void)
9930 IDirectDrawSurface
*surface
, *rt
;
9931 DDSURFACEDESC surface_desc
;
9932 IDirect3DDevice2
*device
;
9933 IDirectDraw2
*ddraw
;
9947 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit. */
9948 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, flipped source. */
9949 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, mirrored source. */
9950 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched x. */
9951 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched y. */
9952 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK
}, /* Full surface blit. */
9953 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT
}, /* Full surface, flipped destination. */
9954 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored destination. */
9955 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, flipped source. */
9956 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored source. */
9959 window
= create_window();
9960 ddraw
= create_ddraw();
9961 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9962 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9964 skip("Failed to create a 3D device, skipping test.\n");
9965 IDirectDraw2_Release(ddraw
);
9966 DestroyWindow(window
);
9970 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
9971 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9973 memset(&surface_desc
, 0, sizeof(surface_desc
));
9974 surface_desc
.dwSize
= sizeof(surface_desc
);
9975 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
9976 surface_desc
.dwWidth
= 640;
9977 surface_desc
.dwHeight
= 480;
9978 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
9979 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9980 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9982 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface
, NULL
, 0, NULL
);
9983 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9985 hr
= IDirectDrawSurface_Blt(surface
, NULL
, rt
, NULL
, 0, NULL
);
9986 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
9988 for (i
= 0; i
< ARRAY_SIZE(test_data
); ++i
)
9990 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
9991 surface
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
9992 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
9994 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
9995 rt
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
9996 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
9998 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
9999 NULL
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
10000 ok(hr
== DDERR_INVALIDPARAMS
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
10002 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
, NULL
, NULL
, DDBLT_WAIT
, NULL
);
10003 ok(hr
== DDERR_INVALIDPARAMS
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
10006 IDirectDrawSurface_Release(surface
);
10007 IDirectDrawSurface_Release(rt
);
10008 refcount
= IDirect3DDevice2_Release(device
);
10009 ok(!refcount
, "Device has %u references left.\n", refcount
);
10010 IDirectDraw2_Release(ddraw
);
10011 DestroyWindow(window
);
10014 static void test_blt_z_alpha(void)
10016 DWORD blt_flags
[] =
10020 DDBLT_ALPHADESTCONSTOVERRIDE
,
10021 DDBLT_ALPHADESTNEG
,
10022 DDBLT_ALPHADESTSURFACEOVERRIDE
,
10023 DDBLT_ALPHAEDGEBLEND
,
10026 DDBLT_ALPHASRCCONSTOVERRIDE
,
10028 DDBLT_ALPHASRCSURFACEOVERRIDE
,
10031 DDBLT_ZBUFFERDESTCONSTOVERRIDE
,
10032 DDBLT_ZBUFFERDESTOVERRIDE
,
10033 DDBLT_ZBUFFERSRCCONSTOVERRIDE
,
10034 DDBLT_ZBUFFERSRCOVERRIDE
,
10036 IDirectDrawSurface
*src_surface
, *dst_surface
;
10037 DDSURFACEDESC surface_desc
;
10038 IDirectDraw2
*ddraw
;
10047 window
= create_window();
10048 ddraw
= create_ddraw();
10049 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10050 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10051 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10053 memset(&pf
, 0, sizeof(pf
));
10054 pf
.dwSize
= sizeof(pf
);
10055 pf
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
10056 U1(pf
).dwRGBBitCount
= 32;
10057 U2(pf
).dwRBitMask
= 0x00ff0000;
10058 U3(pf
).dwGBitMask
= 0x0000ff00;
10059 U4(pf
).dwBBitMask
= 0x000000ff;
10060 U5(pf
).dwRGBAlphaBitMask
= 0xff000000;
10062 memset(&surface_desc
, 0, sizeof(surface_desc
));
10063 surface_desc
.dwSize
= sizeof(surface_desc
);
10064 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
10065 surface_desc
.dwWidth
= 64;
10066 surface_desc
.dwHeight
= 64;
10067 surface_desc
.ddpfPixelFormat
= pf
;
10068 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10070 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
10071 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
10072 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
10073 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
10075 memset(&fx
, 0, sizeof(fx
));
10076 fx
.dwSize
= sizeof(fx
);
10077 fx
.dwZBufferOpCode
= D3DCMP_NEVER
;
10078 fx
.dwZDestConstBitDepth
= 32;
10079 U1(fx
).dwZDestConst
= 0x11111111;
10080 fx
.dwZSrcConstBitDepth
= 32;
10081 U2(fx
).dwZSrcConst
= 0xeeeeeeee;
10082 fx
.dwAlphaEdgeBlendBitDepth
= 8;
10083 fx
.dwAlphaEdgeBlend
= 0x7f;
10084 fx
.dwAlphaDestConstBitDepth
= 8;
10085 U3(fx
).dwAlphaDestConst
= 0xdd;
10086 fx
.dwAlphaSrcConstBitDepth
= 8;
10087 U4(fx
).dwAlphaSrcConst
= 0x22;
10089 for (i
= 0; i
< ARRAY_SIZE(blt_flags
); ++i
)
10091 fx
.dwFillColor
= 0x3300ff00;
10092 hr
= IDirectDrawSurface_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
10093 ok(SUCCEEDED(hr
), "Test %u: Got unexpected hr %#x.\n", i
, hr
);
10095 fx
.dwFillColor
= 0xccff0000;
10096 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
10097 ok(SUCCEEDED(hr
), "Test %u: Got unexpected hr %#x.\n", i
, hr
);
10099 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, NULL
, blt_flags
[i
] | DDBLT_WAIT
, &fx
);
10100 ok(SUCCEEDED(hr
), "Test %u: Got unexpected hr %#x.\n", i
, hr
);
10102 color
= get_surface_color(dst_surface
, 32, 32);
10103 ok(compare_color(color
, 0x0000ff00, 0), "Test %u: Got unexpected color 0x%08x.\n", i
, color
);
10106 IDirectDrawSurface_Release(dst_surface
);
10107 IDirectDrawSurface_Release(src_surface
);
10108 refcount
= IDirectDraw2_Release(ddraw
);
10109 ok(!refcount
, "DirectDraw has %u references left.\n", refcount
);
10110 DestroyWindow(window
);
10113 static void test_getdc(void)
10115 IDirectDrawSurface
*surface
, *surface2
, *tmp
;
10116 DDSURFACEDESC surface_desc
, map_desc
;
10117 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
10118 IDirectDraw2
*ddraw
;
10124 static const struct
10127 DDPIXELFORMAT format
;
10128 BOOL getdc_supported
;
10129 HRESULT alt_result
;
10133 {"D3DFMT_A8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
10134 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE
},
10135 {"D3DFMT_X8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
10136 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE
},
10137 {"D3DFMT_R5G6B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
10138 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE
},
10139 {"D3DFMT_X1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
10140 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE
},
10141 {"D3DFMT_A1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
10142 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE
},
10143 {"D3DFMT_A4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
10144 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
10145 {"D3DFMT_X4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
10146 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
10147 {"D3DFMT_A2R10G10B10", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
10148 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE
},
10149 {"D3DFMT_A8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
10150 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
10151 {"D3DFMT_X8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
10152 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
10153 {"D3DFMT_R3G3B2", {sizeof(test_data
->format
), DDPF_RGB
, 0, {8},
10154 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE
},
10155 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
10156 * This is not implemented in wine yet, so disable the test for now.
10157 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
10158 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
10159 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
10161 {"D3DFMT_L8", {sizeof(test_data
->format
), DDPF_LUMINANCE
, 0, {8},
10162 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10163 {"D3DFMT_A8L8", {sizeof(test_data
->format
), DDPF_ALPHAPIXELS
| DDPF_LUMINANCE
, 0, {16},
10164 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE
},
10165 {"D3DFMT_DXT1", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','1'), {0},
10166 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10167 {"D3DFMT_DXT2", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','2'), {0},
10168 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10169 {"D3DFMT_DXT3", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','3'), {0},
10170 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10171 {"D3DFMT_DXT4", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','4'), {0},
10172 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10173 {"D3DFMT_DXT5", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','5'), {0},
10174 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
10177 window
= create_window();
10178 ddraw
= create_ddraw();
10179 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10180 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10181 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10183 for (i
= 0; i
< ARRAY_SIZE(test_data
); ++i
)
10185 memset(&surface_desc
, 0, sizeof(surface_desc
));
10186 surface_desc
.dwSize
= sizeof(surface_desc
);
10187 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10188 surface_desc
.dwWidth
= 64;
10189 surface_desc
.dwHeight
= 64;
10190 surface_desc
.ddpfPixelFormat
= test_data
[i
].format
;
10191 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10193 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
10195 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10196 if (FAILED(hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
10198 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data
[i
].name
, hr
);
10203 dc
= (void *)0x1234;
10204 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10205 if (test_data
[i
].getdc_supported
)
10206 ok(SUCCEEDED(hr
) || broken(hr
== test_data
[i
].alt_result
|| ddraw_is_vmware(ddraw
)),
10207 "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10209 ok(FAILED(hr
), "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10213 unsigned int width_bytes
;
10219 type
= GetObjectType(dc
);
10220 ok(type
== OBJ_MEMDC
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
10221 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
10222 type
= GetObjectType(bitmap
);
10223 ok(type
== OBJ_BITMAP
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
10225 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
10226 ok(size
== sizeof(dib
), "Got unexpected size %d for format %s.\n", size
, test_data
[i
].name
);
10227 ok(!dib
.dsBm
.bmType
, "Got unexpected type %#x for format %s.\n",
10228 dib
.dsBm
.bmType
, test_data
[i
].name
);
10229 ok(dib
.dsBm
.bmWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
10230 dib
.dsBm
.bmWidth
, test_data
[i
].name
);
10231 ok(dib
.dsBm
.bmHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
10232 dib
.dsBm
.bmHeight
, test_data
[i
].name
);
10233 width_bytes
= ((dib
.dsBm
.bmWidth
* U1(test_data
[i
].format
).dwRGBBitCount
+ 31) >> 3) & ~3;
10234 ok(dib
.dsBm
.bmWidthBytes
== width_bytes
, "Got unexpected width bytes %d for format %s.\n",
10235 dib
.dsBm
.bmWidthBytes
, test_data
[i
].name
);
10236 ok(dib
.dsBm
.bmPlanes
== 1, "Got unexpected plane count %d for format %s.\n",
10237 dib
.dsBm
.bmPlanes
, test_data
[i
].name
);
10238 ok(dib
.dsBm
.bmBitsPixel
== U1(test_data
[i
].format
).dwRGBBitCount
,
10239 "Got unexpected bit count %d for format %s.\n",
10240 dib
.dsBm
.bmBitsPixel
, test_data
[i
].name
);
10241 ok(!!dib
.dsBm
.bmBits
, "Got unexpected bits %p for format %s.\n",
10242 dib
.dsBm
.bmBits
, test_data
[i
].name
);
10244 ok(dib
.dsBmih
.biSize
== sizeof(dib
.dsBmih
), "Got unexpected size %u for format %s.\n",
10245 dib
.dsBmih
.biSize
, test_data
[i
].name
);
10246 ok(dib
.dsBmih
.biWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
10247 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
10248 ok(dib
.dsBmih
.biHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
10249 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
10250 ok(dib
.dsBmih
.biPlanes
== 1, "Got unexpected plane count %u for format %s.\n",
10251 dib
.dsBmih
.biPlanes
, test_data
[i
].name
);
10252 ok(dib
.dsBmih
.biBitCount
== U1(test_data
[i
].format
).dwRGBBitCount
,
10253 "Got unexpected bit count %u for format %s.\n",
10254 dib
.dsBmih
.biBitCount
, test_data
[i
].name
);
10255 ok(dib
.dsBmih
.biCompression
== (U1(test_data
[i
].format
).dwRGBBitCount
== 16 ? BI_BITFIELDS
: BI_RGB
)
10256 || broken(U1(test_data
[i
].format
).dwRGBBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_BITFIELDS
),
10257 "Got unexpected compression %#x for format %s.\n",
10258 dib
.dsBmih
.biCompression
, test_data
[i
].name
);
10259 ok(!dib
.dsBmih
.biSizeImage
, "Got unexpected image size %u for format %s.\n",
10260 dib
.dsBmih
.biSizeImage
, test_data
[i
].name
);
10261 ok(!dib
.dsBmih
.biXPelsPerMeter
, "Got unexpected horizontal resolution %d for format %s.\n",
10262 dib
.dsBmih
.biXPelsPerMeter
, test_data
[i
].name
);
10263 ok(!dib
.dsBmih
.biYPelsPerMeter
, "Got unexpected vertical resolution %d for format %s.\n",
10264 dib
.dsBmih
.biYPelsPerMeter
, test_data
[i
].name
);
10265 ok(!dib
.dsBmih
.biClrUsed
, "Got unexpected used colour count %u for format %s.\n",
10266 dib
.dsBmih
.biClrUsed
, test_data
[i
].name
);
10267 ok(!dib
.dsBmih
.biClrImportant
, "Got unexpected important colour count %u for format %s.\n",
10268 dib
.dsBmih
.biClrImportant
, test_data
[i
].name
);
10270 if (dib
.dsBmih
.biCompression
== BI_BITFIELDS
)
10272 ok((dib
.dsBitfields
[0] == U2(test_data
[i
].format
).dwRBitMask
10273 && dib
.dsBitfields
[1] == U3(test_data
[i
].format
).dwGBitMask
10274 && dib
.dsBitfields
[2] == U4(test_data
[i
].format
).dwBBitMask
)
10275 || broken(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2]),
10276 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
10277 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
10281 ok(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2],
10282 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
10283 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
10285 ok(!dib
.dshSection
, "Got unexpected section %p for format %s.\n", dib
.dshSection
, test_data
[i
].name
);
10286 ok(!dib
.dsOffset
, "Got unexpected offset %u for format %s.\n", dib
.dsOffset
, test_data
[i
].name
);
10288 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10289 ok(hr
== DD_OK
, "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10293 ok(!dc
, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
10296 IDirectDrawSurface_Release(surface
);
10301 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
10302 if (FAILED(hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
10304 skip("Failed to create mip-mapped texture for format %s (hr %#x), skipping tests.\n",
10305 test_data
[i
].name
, hr
);
10309 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
10310 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10311 hr
= IDirectDrawSurface_GetAttachedSurface(tmp
, &caps
, &surface2
);
10312 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10313 IDirectDrawSurface_Release(tmp
);
10315 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10316 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10317 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10318 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10319 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10320 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10321 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10322 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10324 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10325 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10326 dc2
= (void *)0x1234;
10327 hr
= IDirectDrawSurface_GetDC(surface
, &dc2
);
10328 ok(hr
== DDERR_DCALREADYCREATED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10329 ok(dc2
== (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
10330 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10331 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10332 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10333 ok(hr
== DDERR_NODC
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10335 map_desc
.dwSize
= sizeof(map_desc
);
10336 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10337 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10338 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10339 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10340 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10341 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10342 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10343 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10345 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10346 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10347 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10348 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10349 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10350 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10352 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10353 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10354 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10355 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10356 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10357 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10358 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10359 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10361 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10362 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10363 hr
= IDirectDrawSurface_GetDC(surface2
, &dc2
);
10364 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10365 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc2
);
10366 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10367 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10368 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10370 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10371 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10372 hr
= IDirectDrawSurface_GetDC(surface
, &dc2
);
10373 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10374 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc2
);
10375 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10376 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10377 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10379 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10380 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10381 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10382 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10383 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10384 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10385 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10386 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10388 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10389 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10390 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10391 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10392 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10393 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10394 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10395 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10397 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10398 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10399 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10400 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10401 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10402 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10403 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10404 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10406 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10407 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10408 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10409 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10410 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10411 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10412 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10413 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10415 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10416 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10417 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
10418 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10419 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10420 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10421 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10422 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10424 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10425 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10426 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
10427 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10428 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10429 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10430 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
10431 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10432 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
10433 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10435 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10436 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10437 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
10438 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10439 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10440 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10441 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
10442 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
10443 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
10444 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
10446 IDirectDrawSurface_Release(surface2
);
10447 IDirectDrawSurface_Release(surface
);
10450 IDirectDraw2_Release(ddraw
);
10451 DestroyWindow(window
);
10454 static void test_draw_primitive(void)
10456 static WORD indices
[] = {0, 1, 2, 3};
10457 static D3DVERTEX quad
[] =
10459 {{-1.0f
}, {-1.0f
}, {0.0f
}},
10460 {{-1.0f
}, { 1.0f
}, {0.0f
}},
10461 {{ 1.0f
}, {-1.0f
}, {0.0f
}},
10462 {{ 1.0f
}, { 1.0f
}, {0.0f
}},
10464 IDirect3DViewport2
*viewport
;
10465 IDirect3DDevice2
*device
;
10466 IDirectDraw2
*ddraw
;
10472 window
= create_window();
10473 ddraw
= create_ddraw();
10474 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10475 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10477 skip("Failed to create a 3D device, skipping test.\n");
10478 IDirectDraw2_Release(ddraw
);
10479 DestroyWindow(window
);
10483 viewport
= create_viewport(device
, 0, 0, 640, 480);
10484 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
10485 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10487 hr
= IDirect3DDevice2_GetDirect3D(device
, &d3d
);
10488 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
10490 IDirect3D2_Release(d3d
);
10492 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, NULL
, 0, 0);
10493 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10494 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, 0);
10495 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10497 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, NULL
, 0, indices
, 4, 0);
10498 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10500 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, NULL
, 0, 0);
10501 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10502 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, 0);
10503 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10504 hr
= IDirect3DDevice2_DrawIndexedPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
, quad
, 4, indices
, 4, 0);
10505 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10507 destroy_viewport(device
, viewport
);
10508 refcount
= IDirect3DDevice2_Release(device
);
10509 ok(!refcount
, "Device has %u references left.\n", refcount
);
10510 IDirectDraw2_Release(ddraw
);
10511 DestroyWindow(window
);
10514 static void test_edge_antialiasing_blending(void)
10516 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10517 IDirect3DMaterial2
*green_background
;
10518 IDirect3DMaterial2
*red_background
;
10519 IDirectDrawSurface
*offscreen
, *ds
;
10520 D3DDEVICEDESC hal_desc
, hel_desc
;
10521 IDirect3DViewport2
*viewport
;
10522 DDSURFACEDESC surface_desc
;
10523 IDirect3DDevice2
*device
;
10524 IDirectDraw2
*ddraw
;
10530 static D3DMATRIX mat
=
10532 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10533 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10534 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10535 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10537 static D3DLVERTEX green_quad
[] =
10539 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10540 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10541 {{ 1.0f
}, {-1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10542 {{ 1.0f
}, { 1.0f
}, {0.1f
}, 0, {0x7f00ff00}},
10544 static D3DLVERTEX red_quad
[] =
10546 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xccff0000}},
10547 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xccff0000}},
10548 {{ 1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xccff0000}},
10549 {{ 1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xccff0000}},
10552 window
= create_window();
10553 ddraw
= create_ddraw();
10554 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10555 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10557 skip("Failed to create a 3D device.\n");
10558 DestroyWindow(window
);
10562 memset(&hal_desc
, 0, sizeof(hal_desc
));
10563 hal_desc
.dwSize
= sizeof(hal_desc
);
10564 memset(&hel_desc
, 0, sizeof(hel_desc
));
10565 hel_desc
.dwSize
= sizeof(hel_desc
);
10566 hr
= IDirect3DDevice2_GetCaps(device
, &hal_desc
, &hel_desc
);
10567 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
10568 trace("HAL line edge antialiasing support: %#x.\n",
10569 hal_desc
.dpcLineCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10570 trace("HAL triangle edge antialiasing support: %#x.\n",
10571 hal_desc
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10572 trace("HEL line edge antialiasing support: %#x.\n",
10573 hel_desc
.dpcLineCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10574 trace("HEL triangle edge antialiasing support: %#x.\n",
10575 hel_desc
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_ANTIALIASEDGES
);
10577 memset(&surface_desc
, 0, sizeof(surface_desc
));
10578 surface_desc
.dwSize
= sizeof(surface_desc
);
10579 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
10580 surface_desc
.dwWidth
= 640;
10581 surface_desc
.dwHeight
= 480;
10582 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
10583 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
10584 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
10585 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
10586 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10587 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10588 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10589 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
10590 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
10591 ok(hr
== D3D_OK
, "Creating the offscreen render target failed, hr %#x.\n", hr
);
10593 ds
= get_depth_stencil(device
);
10594 hr
= IDirectDrawSurface_AddAttachedSurface(offscreen
, ds
);
10595 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
10596 IDirectDrawSurface_Release(ds
);
10598 hr
= IDirect3DDevice2_SetRenderTarget(device
, offscreen
, 0);
10599 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
10601 red_background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 0.8f
);
10602 green_background
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.5f
);
10604 viewport
= create_viewport(device
, 0, 0, 640, 480);
10605 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
10606 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
10608 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
10609 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
10610 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
10611 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
10612 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
10613 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
10614 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
10615 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
10616 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
10617 ok(SUCCEEDED(hr
), "Failed to disable Z test, hr %#x.\n", hr
);
10618 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10619 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10620 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
10621 ok(SUCCEEDED(hr
), "Failed to disable stencil test, hr %#x.\n", hr
);
10622 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
10623 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
10624 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10625 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
10627 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
10628 ok(SUCCEEDED(hr
), "Failed to enable blending, hr %#x.\n", hr
);
10629 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
10630 ok(SUCCEEDED(hr
), "Failed to set src blend, hr %#x.\n", hr
);
10631 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_DESTALPHA
);
10632 ok(SUCCEEDED(hr
), "Failed to set dest blend, hr %#x.\n", hr
);
10634 viewport_set_background(device
, viewport
, red_background
);
10635 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10636 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10637 hr
= IDirect3DDevice2_BeginScene(device
);
10638 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10639 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10640 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10641 hr
= IDirect3DDevice2_EndScene(device
);
10642 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10643 color
= get_surface_color(offscreen
, 320, 240);
10644 ok(compare_color(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
10646 viewport_set_background(device
, viewport
, green_background
);
10647 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10648 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10649 hr
= IDirect3DDevice2_BeginScene(device
);
10650 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10651 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, red_quad
, 4, 0);
10652 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10653 hr
= IDirect3DDevice2_EndScene(device
);
10654 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10655 color
= get_surface_color(offscreen
, 320, 240);
10656 ok(compare_color(color
, 0x00cc7f00, 1), "Got unexpected color 0x%08x.\n", color
);
10658 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
10659 ok(SUCCEEDED(hr
), "Failed to disable blending, hr %#x.\n", hr
);
10661 viewport_set_background(device
, viewport
, red_background
);
10662 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10663 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10664 hr
= IDirect3DDevice2_BeginScene(device
);
10665 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10666 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10667 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10668 hr
= IDirect3DDevice2_EndScene(device
);
10669 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10670 color
= get_surface_color(offscreen
, 320, 240);
10671 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
10673 viewport_set_background(device
, viewport
, green_background
);
10674 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10675 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10676 hr
= IDirect3DDevice2_BeginScene(device
);
10677 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10678 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, red_quad
, 4, 0);
10679 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10680 hr
= IDirect3DDevice2_EndScene(device
);
10681 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10682 color
= get_surface_color(offscreen
, 320, 240);
10683 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
10685 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_EDGEANTIALIAS
, TRUE
);
10686 ok(SUCCEEDED(hr
), "Failed to enable edge antialiasing, hr %#x.\n", hr
);
10688 viewport_set_background(device
, viewport
, red_background
);
10689 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10690 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10691 hr
= IDirect3DDevice2_BeginScene(device
);
10692 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10693 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, green_quad
, 4, 0);
10694 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10695 hr
= IDirect3DDevice2_EndScene(device
);
10696 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10697 color
= get_surface_color(offscreen
, 320, 240);
10698 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
10700 viewport_set_background(device
, viewport
, green_background
);
10701 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
10702 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
10703 hr
= IDirect3DDevice2_BeginScene(device
);
10704 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10705 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, red_quad
, 4, 0);
10706 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10707 hr
= IDirect3DDevice2_EndScene(device
);
10708 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10709 color
= get_surface_color(offscreen
, 320, 240);
10710 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
10712 IDirectDrawSurface_Release(offscreen
);
10713 destroy_viewport(device
, viewport
);
10714 destroy_material(red_background
);
10715 destroy_material(green_background
);
10716 refcount
= IDirect3DDevice2_Release(device
);
10717 ok(!refcount
, "Device has %u references left.\n", refcount
);
10718 IDirectDraw2_Release(ddraw
);
10719 DestroyWindow(window
);
10722 /* TransformVertices always writes 32 bytes regardless of the input / output stride.
10723 * The stride is honored for navigating to the next vertex. 3 floats input position
10724 * are read, and 16 bytes extra vertex data are copied around. */
10725 struct transform_input
10727 float x
, y
, z
, unused1
; /* Position data, transformed. */
10728 DWORD v1
, v2
, v3
, v4
; /* Extra data, e.g. color and texture coords, copied. */
10732 struct transform_output
10735 DWORD v1
, v2
, v3
, v4
;
10736 DWORD unused3
, unused4
;
10739 static void test_transform_vertices(void)
10741 IDirect3DDevice2
*device
;
10742 IDirectDrawSurface
*rt
;
10743 IDirectDraw2
*ddraw
;
10748 IDirect3DViewport2
*viewport
;
10749 IDirect3DMaterial2
*background
;
10751 static struct transform_input position_tests
[] =
10753 { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
10754 { 1.0f
, 1.0f
, 1.0f
, 8.0f
, 6, 7, 8, 9, 10},
10755 {-1.0f
, -1.0f
, -1.0f
, 4.0f
, 11, 12, 13, 14, 15},
10756 { 0.5f
, 0.5f
, 0.5f
, 2.0f
, 16, 17, 18, 19, 20},
10757 {-0.5f
, -0.5f
, -0.5f
, 1.0f
, ~1U, ~2U, ~3U, ~4U, ~5U},
10758 {-0.5f
, -0.5f
, 0.0f
, 0.0f
, ~6U, ~7U, ~8U, ~9U, ~0U},
10760 static struct transform_input cliptest
[] =
10762 { 25.59f
, 25.59f
, 1.0f
, 0.0f
, 1, 2, 3, 4, 5},
10763 { 25.61f
, 25.61f
, 1.01f
, 0.0f
, 1, 2, 3, 4, 5},
10764 {-25.59f
, -25.59f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
10765 {-25.61f
, -25.61f
, -0.01f
, 0.0f
, 1, 2, 3, 4, 5},
10767 static struct transform_input offscreentest
[] =
10769 {128.1f
, 0.0f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
10771 struct transform_output out
[ARRAY_SIZE(position_tests
)];
10772 D3DHVERTEX out_h
[ARRAY_SIZE(position_tests
)];
10773 D3DTRANSFORMDATA transformdata
;
10774 static const D3DVIEWPORT vp_template
=
10776 sizeof(vp_template
), 0, 0, 256, 256, 5.0f
, 5.0f
, 256.0f
, 256.0f
, -25.0f
, 60.0f
10778 D3DVIEWPORT vp_data
=
10780 sizeof(vp_data
), 0, 0, 256, 256, 1.0f
, 1.0f
, 256.0f
, 256.0f
, 0.0f
, 1.0f
10782 D3DVIEWPORT2 vp2_data
;
10785 static D3DMATRIX mat_scale
=
10787 2.0f
, 0.0f
, 0.0f
, 0.0f
,
10788 0.0f
, 2.0f
, 0.0f
, 0.0f
,
10789 0.0f
, 0.0f
, 2.0f
, 0.0f
,
10790 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10794 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10795 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10796 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10797 1.0f
, 0.0f
, 0.0f
, 1.0f
,
10801 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10802 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10803 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10804 0.0f
, 1.0f
, 0.0f
, 1.0f
,
10808 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10809 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10810 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10811 0.0f
, 19.2f
, 0.0f
, 2.0f
,
10815 1.0f
, 0.0f
, 0.0f
, 0.0f
,
10816 0.0f
, 1.0f
, 0.0f
, 0.0f
,
10817 0.0f
, 0.0f
, 1.0f
, 0.0f
,
10818 0.0f
, 0.0f
, 0.0f
, 1.0f
,
10820 static D3DLVERTEX quad
[] =
10822 {{-0.75f
},{-0.5f
}, {0.0f
}, 0, {0xffff0000}},
10823 {{-0.75f
},{ 0.25f
}, {0.0f
}, 0, {0xffff0000}},
10824 {{ 0.5f
}, {-0.5f
}, {0.0f
}, 0, {0xffff0000}},
10825 {{ 0.5f
}, { 0.25f
}, {0.0f
}, 0, {0xffff0000}},
10827 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
10830 for (i
= 0; i
< ARRAY_SIZE(out
); ++i
)
10832 out
[i
].unused3
= 0xdeadbeef;
10833 out
[i
].unused4
= 0xcafecafe;
10836 window
= create_window();
10837 ddraw
= create_ddraw();
10838 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10839 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
10841 skip("Failed to create a 3D device, skipping test.\n");
10842 IDirectDraw2_Release(ddraw
);
10843 DestroyWindow(window
);
10846 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
10847 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10849 viewport
= create_viewport(device
, 0, 0, 256, 256);
10850 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10851 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10853 memset(&transformdata
, 0, sizeof(transformdata
));
10854 transformdata
.dwSize
= sizeof(transformdata
);
10855 transformdata
.lpIn
= position_tests
;
10856 transformdata
.dwInSize
= sizeof(position_tests
[0]);
10857 transformdata
.lpOut
= out
;
10858 transformdata
.dwOutSize
= sizeof(out
[0]);
10859 transformdata
.lpHOut
= NULL
;
10861 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10862 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10863 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10864 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10866 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10868 static const struct vec4 cmp
[] =
10870 {128.0f
, 128.0f
, 0.0f
, 1.0f
}, {129.0f
, 127.0f
, 1.0f
, 1.0f
}, {127.0f
, 129.0f
, -1.0f
, 1.0f
},
10871 {128.5f
, 127.5f
, 0.5f
, 1.0f
}, {127.5f
, 128.5f
, -0.5f
, 1.0f
}, {127.5f
, 128.5f
, 0.0f
, 1.0f
}
10874 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10875 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10876 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10877 ok(out
[i
].v1
== position_tests
[i
].v1
&& out
[i
].v2
== position_tests
[i
].v2
10878 && out
[i
].v3
== position_tests
[i
].v3
&& out
[i
].v4
== position_tests
[i
].v4
,
10879 "Vertex %u payload is %u %u %u %u.\n", i
, out
[i
].v1
, out
[i
].v2
, out
[i
].v3
, out
[i
].v4
);
10880 ok(out
[i
].unused3
== 0xdeadbeef && out
[i
].unused4
== 0xcafecafe,
10881 "Vertex %u unused data is %#x, %#x.\n", i
, out
[i
].unused3
, out
[i
].unused4
);
10884 vp_data
= vp_template
;
10885 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10886 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10887 offscreen
= 0xdeadbeef;
10888 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10889 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10890 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10891 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10893 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10895 static const struct vec4 cmp
[] =
10897 {128.0f
, 128.0f
, 0.0f
, 1.0f
}, {133.0f
, 123.0f
, 1.0f
, 1.0f
}, {123.0f
, 133.0f
, -1.0f
, 1.0f
},
10898 {130.5f
, 125.5f
, 0.5f
, 1.0f
}, {125.5f
, 130.5f
, -0.5f
, 1.0f
}, {125.5f
, 130.5f
, 0.0f
, 1.0f
}
10900 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10901 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10902 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10907 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10908 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10909 offscreen
= 0xdeadbeef;
10910 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10911 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
10912 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10913 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10914 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10916 static const struct vec4 cmp
[] =
10918 {138.0f
, 148.0f
, 0.0f
, 1.0f
}, {143.0f
, 143.0f
, 1.0f
, 1.0f
}, {133.0f
, 153.0f
, -1.0f
, 1.0f
},
10919 {140.5f
, 145.5f
, 0.5f
, 1.0f
}, {135.5f
, 150.5f
, -0.5f
, 1.0f
}, {135.5f
, 150.5f
, 0.0f
, 1.0f
}
10921 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10922 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10923 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10926 transformdata
.lpHOut
= out_h
;
10927 offscreen
= 0xdeadbeef;
10928 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
10929 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10930 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10931 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10932 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
10934 static const D3DHVERTEX cmp_h
[] =
10936 {0, { 0.0f
}, { 0.0f
}, { 0.0f
}}, {0, { 1.0f
}, { 1.0f
}, {1.0f
}},
10937 {D3DCLIP_FRONT
, {-1.0f
}, {-1.0f
}, {-1.0f
}}, {0, { 0.5f
}, { 0.5f
}, {0.5f
}},
10938 {D3DCLIP_FRONT
, {-0.5f
}, {-0.5f
}, {-0.5f
}}, {0, {-0.5f
}, {-0.5f
}, {0.0f
}}
10940 ok(compare_float(U1(cmp_h
[i
]).hx
, U1(out_h
[i
]).hx
, 4096)
10941 && compare_float(U2(cmp_h
[i
]).hy
, U2(out_h
[i
]).hy
, 4096)
10942 && compare_float(U3(cmp_h
[i
]).hz
, U3(out_h
[i
]).hz
, 4096)
10943 && cmp_h
[i
].dwFlags
== out_h
[i
].dwFlags
,
10944 "HVertex %u differs. Got %#x %f %f %f.\n", i
,
10945 out_h
[i
].dwFlags
, U1(out_h
[i
]).hx
, U2(out_h
[i
]).hy
, U3(out_h
[i
]).hz
);
10947 /* No scheme has been found behind those return values. It seems to be
10948 * whatever data windows has when throwing the vertex away. Modify the
10949 * input test vertices to test this more. Depending on the input data
10950 * it can happen that the z coord gets written into y, or similar things. */
10953 static const struct vec4 cmp
[] =
10955 {138.0f
, 148.0f
, 0.0f
, 1.0f
}, {143.0f
, 143.0f
, 1.0f
, 1.0f
}, { -1.0f
, -1.0f
, 0.5f
, 1.0f
},
10956 {140.5f
, 145.5f
, 0.5f
, 1.0f
}, { -0.5f
, -0.5f
, -0.5f
, 1.0f
}, {135.5f
, 150.5f
, 0.0f
, 1.0f
}
10958 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
10959 "Vertex %u differs. Got %f %f %f %f.\n", i
,
10960 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
10964 transformdata
.lpIn
= cliptest
;
10965 transformdata
.dwInSize
= sizeof(cliptest
[0]);
10966 offscreen
= 0xdeadbeef;
10967 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
10968 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10969 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10970 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10971 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
10973 static const DWORD flags
[] =
10976 D3DCLIP_RIGHT
| D3DCLIP_BACK
| D3DCLIP_TOP
,
10978 D3DCLIP_LEFT
| D3DCLIP_BOTTOM
| D3DCLIP_FRONT
,
10980 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
10983 vp_data
= vp_template
;
10984 vp_data
.dwWidth
= 10;
10985 vp_data
.dwHeight
= 480;
10986 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
10987 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
10988 offscreen
= 0xdeadbeef;
10989 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
10990 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
10991 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
10992 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
10993 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
10995 static const DWORD flags
[] =
10998 D3DCLIP_RIGHT
| D3DCLIP_BACK
,
11000 D3DCLIP_LEFT
| D3DCLIP_FRONT
,
11002 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
11005 vp_data
= vp_template
;
11006 vp_data
.dwWidth
= 256;
11007 vp_data
.dwHeight
= 256;
11008 vp_data
.dvScaleX
= 1;
11009 vp_data
.dvScaleY
= 1;
11010 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
11011 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
11012 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
11013 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11014 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11015 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
11016 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
11018 static const DWORD flags
[] =
11025 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
11028 /* Finally try to figure out how the DWORD dwOffscreen works.
11029 * It is a logical AND of the vertices' dwFlags members. */
11030 vp_data
= vp_template
;
11031 vp_data
.dwWidth
= 5;
11032 vp_data
.dwHeight
= 5;
11033 vp_data
.dvScaleX
= 10000.0f
;
11034 vp_data
.dvScaleY
= 10000.0f
;
11035 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
11036 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
11037 transformdata
.lpIn
= cliptest
;
11038 offscreen
= 0xdeadbeef;
11039 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11040 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11041 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11042 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
11044 offscreen
= 0xdeadbeef;
11045 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11046 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11047 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11048 ok(offscreen
== (D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
11049 offscreen
= 0xdeadbeef;
11050 hr
= IDirect3DViewport2_TransformVertices(viewport
, 2,
11051 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11052 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11053 ok(offscreen
== (D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
11054 hr
= IDirect3DViewport2_TransformVertices(viewport
, 3,
11055 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11056 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11057 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
11059 transformdata
.lpIn
= cliptest
+ 1;
11060 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11061 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11062 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11063 ok(offscreen
== (D3DCLIP_BACK
| D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
11065 transformdata
.lpIn
= cliptest
+ 2;
11066 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11067 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11068 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11069 ok(offscreen
== (D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
11070 offscreen
= 0xdeadbeef;
11071 hr
= IDirect3DViewport2_TransformVertices(viewport
, 2,
11072 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11073 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11074 ok(offscreen
== (D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
11076 transformdata
.lpIn
= cliptest
+ 3;
11077 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11078 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11079 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11080 ok(offscreen
== (D3DCLIP_FRONT
| D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
11082 transformdata
.lpIn
= offscreentest
;
11083 transformdata
.dwInSize
= sizeof(offscreentest
[0]);
11084 vp_data
= vp_template
;
11085 vp_data
.dwWidth
= 257;
11086 vp_data
.dwHeight
= 257;
11087 vp_data
.dvScaleX
= 1.0f
;
11088 vp_data
.dvScaleY
= 1.0f
;
11089 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
11090 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
11091 offscreen
= 0xdeadbeef;
11092 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11093 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11094 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11095 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
11097 vp_data
.dwWidth
= 256;
11098 vp_data
.dwHeight
= 256;
11099 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
11100 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
11101 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11102 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11103 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11104 ok(offscreen
== D3DCLIP_RIGHT
, "Offscreen is %x.\n", offscreen
);
11106 /* Test the effect of Matrices.
11108 * Basically the x coordinate ends up as ((x + 1) * 2 + 0) * 5 and
11109 * y as ((y + 0) * 2 + 1) * 5. The 5 comes from dvScaleX/Y, 2 from
11110 * the view matrix and the +1's from the world and projection matrix. */
11113 vp_data
.dwWidth
= 256;
11114 vp_data
.dwHeight
= 256;
11115 vp_data
.dvScaleX
= 5.0f
;
11116 vp_data
.dvScaleY
= 5.0f
;
11117 vp_data
.dvMinZ
= 0.0f
;
11118 vp_data
.dvMaxZ
= 1.0f
;
11119 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
11120 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
11122 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat_translate1
);
11123 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11124 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat_scale
);
11125 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11126 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat_translate2
);
11127 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11129 transformdata
.lpIn
= position_tests
;
11130 transformdata
.dwInSize
= sizeof(position_tests
[0]);
11131 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
11132 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11133 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11135 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
11137 static const struct vec4 cmp
[] =
11139 {138.0f
, 123.0f
, 0.0f
, 1.0f
}, {148.0f
, 113.0f
, 2.0f
, 1.0f
}, {128.0f
, 133.0f
, -2.0f
, 1.0f
},
11140 {143.0f
, 118.0f
, 1.0f
, 1.0f
}, {133.0f
, 128.0f
, -1.0f
, 1.0f
}, {133.0f
, 128.0f
, 0.0f
, 1.0f
}
11143 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
11144 "Vertex %u differs. Got %f %f %f %f.\n", i
,
11145 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
11148 /* Invalid flags. */
11149 offscreen
= 0xdeadbeef;
11150 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
11151 &transformdata
, 0, &offscreen
);
11152 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11153 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11155 /* NULL transform data. */
11156 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11157 NULL
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11158 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11159 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11160 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11161 NULL
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11162 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11163 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11165 /* NULL transform data and NULL dwOffscreen.
11167 * Valid transform data + NULL dwOffscreen -> crash. */
11168 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11169 NULL
, D3DTRANSFORM_UNCLIPPED
, NULL
);
11170 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11173 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11174 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11175 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11176 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
11177 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11178 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11179 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11180 ok(offscreen
== ~0U, "Offscreen is %x.\n", offscreen
);
11182 /* Invalid sizes. */
11183 offscreen
= 0xdeadbeef;
11184 transformdata
.dwSize
= sizeof(transformdata
) - 1;
11185 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11186 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11187 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11188 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11189 transformdata
.dwSize
= sizeof(transformdata
) + 1;
11190 hr
= IDirect3DViewport2_TransformVertices(viewport
, 1,
11191 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11192 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
11193 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
11195 /* NULL lpIn or lpOut -> crash, except when transforming 0 vertices. */
11196 transformdata
.dwSize
= sizeof(transformdata
);
11197 transformdata
.lpIn
= NULL
;
11198 transformdata
.lpOut
= NULL
;
11199 offscreen
= 0xdeadbeef;
11200 hr
= IDirect3DViewport2_TransformVertices(viewport
, 0,
11201 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11202 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11203 ok(offscreen
== ~0U, "Offscreen is %x.\n", offscreen
);
11205 /* Test how vertices are transformed during draws. */
11208 vp_data
.dwWidth
= 200;
11209 vp_data
.dwHeight
= 400;
11210 vp_data
.dvScaleX
= 20.0f
;
11211 vp_data
.dvScaleY
= 50.0f
;
11212 vp_data
.dvMinZ
= 0.0f
;
11213 vp_data
.dvMaxZ
= 1.0f
;
11214 hr
= IDirect3DViewport2_SetViewport(viewport
, &vp_data
);
11215 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
11216 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
11217 ok(SUCCEEDED(hr
), "Failed to activate the viewport, hr %#x.\n", hr
);
11219 ok(SUCCEEDED(hr
), "Failed to clear the render target, hr %#x.\n", hr
);
11220 background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 0.0f
);
11221 viewport_set_background(device
, viewport
, background
);
11222 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
11223 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
11225 hr
= IDirect3DDevice2_BeginScene(device
);
11226 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11227 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
11228 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11229 hr
= IDirect3DDevice2_EndScene(device
);
11230 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11232 color
= get_surface_color(rt
, 128, 143);
11233 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11234 color
= get_surface_color(rt
, 132, 143);
11235 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11236 color
= get_surface_color(rt
, 128, 147);
11237 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11238 color
= get_surface_color(rt
, 132, 147);
11239 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11241 color
= get_surface_color(rt
, 177, 217);
11242 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11243 color
= get_surface_color(rt
, 181, 217);
11244 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11245 color
= get_surface_color(rt
, 177, 221);
11246 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11247 color
= get_surface_color(rt
, 181, 221);
11248 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
11250 /* Test D3DVIEWPORT2 behavior. */
11251 vp2_data
.dwSize
= sizeof(vp2_data
);
11254 vp2_data
.dwWidth
= 200;
11255 vp2_data
.dwHeight
= 400;
11256 vp2_data
.dvClipX
= -0.5f
;
11257 vp2_data
.dvClipY
= 4.0f
;
11258 vp2_data
.dvClipWidth
= 5.0f
;
11259 vp2_data
.dvClipHeight
= 10.0f
;
11260 vp2_data
.dvMinZ
= 0.0f
;
11261 vp2_data
.dvMaxZ
= 2.0f
;
11262 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp2_data
);
11263 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
11264 transformdata
.lpIn
= position_tests
;
11265 transformdata
.lpOut
= out
;
11266 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
11267 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
11268 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11269 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
11271 static const struct vec4 cmp
[] =
11273 {120.0f
, 140.0f
, 0.0f
, 1.0f
}, {200.0f
, 60.0f
, 1.0f
, 1.0f
}, {40.0f
, 220.0f
, -1.0f
, 1.0f
},
11274 {160.0f
, 100.0f
, 0.5f
, 1.0f
}, { 80.0f
, 180.0f
, -0.5f
, 1.0f
}, {80.0f
, 180.0f
, 0.0f
, 1.0f
}
11277 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
11278 "Vertex %u differs. Got %f %f %f %f.\n", i
,
11279 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
11282 memset(&mat
, 0, sizeof(mat
));
11283 mat
.dwSize
= sizeof(mat
);
11284 U1(U(mat
).diffuse
).r
= 0.0f
;
11285 U2(U(mat
).diffuse
).g
= 1.0f
;
11286 U3(U(mat
).diffuse
).b
= 0.0f
;
11287 U4(U(mat
).diffuse
).a
= 0.0f
;
11288 hr
= IDirect3DMaterial2_SetMaterial(background
, &mat
);
11289 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
11290 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
11291 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
11293 hr
= IDirect3DDevice2_BeginScene(device
);
11294 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
11295 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
11296 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
11297 hr
= IDirect3DDevice2_EndScene(device
);
11298 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
11300 color
= get_surface_color(rt
, 58, 118);
11301 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11302 color
= get_surface_color(rt
, 62, 118);
11303 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11304 color
= get_surface_color(rt
, 58, 122);
11305 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11306 color
= get_surface_color(rt
, 62, 122);
11307 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11309 color
= get_surface_color(rt
, 157, 177);
11310 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
11311 color
= get_surface_color(rt
, 161, 177);
11312 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11313 color
= get_surface_color(rt
, 157, 181);
11314 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11315 color
= get_surface_color(rt
, 161, 181);
11316 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
11318 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat_identity
);
11319 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11320 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat_identity
);
11321 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11322 hr
= IDirect3DDevice2_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat_transform3
);
11323 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
11325 vp2_data
.dwX
= 0.0;
11326 vp2_data
.dwY
= 0.0;
11327 vp2_data
.dwWidth
= 1;
11328 vp2_data
.dwHeight
= 1;
11329 vp2_data
.dvClipX
= -12.8f
;
11330 vp2_data
.dvClipY
= 12.8f
+ mat_transform3
._42
/ mat_transform3
._44
;
11331 vp2_data
.dvClipWidth
= 25.6f
;
11332 vp2_data
.dvClipHeight
= 25.6f
;
11333 vp2_data
.dvMinZ
= 0.0f
;
11334 vp2_data
.dvMaxZ
= 0.5f
;
11335 hr
= IDirect3DViewport2_SetViewport2(viewport
, &vp2_data
);
11336 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
11337 transformdata
.lpIn
= cliptest
;
11338 transformdata
.dwInSize
= sizeof(cliptest
[0]);
11339 offscreen
= 0xdeadbeef;
11340 hr
= IDirect3DViewport2_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
11341 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
11342 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
11343 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
11344 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
11346 static const D3DHVERTEX cmp_h
[] =
11348 {0, { 25.59f
}, { 44.79f
}, { 1.0f
}},
11349 {D3DCLIP_RIGHT
| D3DCLIP_TOP
| D3DCLIP_BACK
, { 25.61f
}, { 44.81f
}, { 1.01f
}},
11350 {0, {-25.59f
}, {-6.39f
}, { 0.0f
}},
11351 {D3DCLIP_LEFT
| D3DCLIP_BOTTOM
| D3DCLIP_FRONT
,{-25.61f
}, {-6.41f
}, {-0.01f
}},
11353 ok(compare_float(U1(cmp_h
[i
]).hx
, U1(out_h
[i
]).hx
, 4096)
11354 && compare_float(U2(cmp_h
[i
]).hy
, U2(out_h
[i
]).hy
, 4096)
11355 && compare_float(U3(cmp_h
[i
]).hz
, U3(out_h
[i
]).hz
, 4096)
11356 && cmp_h
[i
].dwFlags
== out_h
[i
].dwFlags
,
11357 "HVertex %u differs. Got %#x %f %f %f.\n", i
,
11358 out_h
[i
].dwFlags
, U1(out_h
[i
]).hx
, U2(out_h
[i
]).hy
, U3(out_h
[i
]).hz
);
11361 IDirectDrawSurface_Release(rt
);
11362 destroy_viewport(device
, viewport
);
11363 IDirect3DMaterial2_Release(background
);
11364 refcount
= IDirect3DDevice_Release(device
);
11365 ok(!refcount
, "Device has %u references left.\n", refcount
);
11366 IDirectDraw2_Release(ddraw
);
11367 DestroyWindow(window
);
11370 static void test_display_mode_surface_pixel_format(void)
11372 unsigned int width
, height
, bpp
;
11373 IDirectDrawSurface
*surface
;
11374 DDSURFACEDESC surface_desc
;
11375 IDirectDraw2
*ddraw
;
11380 if (!(ddraw
= create_ddraw()))
11382 skip("Failed to create ddraw.\n");
11386 surface_desc
.dwSize
= sizeof(surface_desc
);
11387 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
11388 ok(SUCCEEDED(hr
), "Failed to get display mode, hr %#x.\n", hr
);
11389 width
= surface_desc
.dwWidth
;
11390 height
= surface_desc
.dwHeight
;
11392 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
11393 0, 0, width
, height
, NULL
, NULL
, NULL
, NULL
);
11394 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
11395 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11398 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 16, 0, 0)))
11400 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0)))
11402 if (SUCCEEDED(IDirectDraw2_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
11404 ok(bpp
, "Set display mode failed.\n");
11406 surface_desc
.dwSize
= sizeof(surface_desc
);
11407 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &surface_desc
);
11408 ok(SUCCEEDED(hr
), "Failed to get display mode, hr %#x.\n", hr
);
11409 ok(surface_desc
.dwWidth
== width
, "Got width %u, expected %u.\n", surface_desc
.dwWidth
, width
);
11410 ok(surface_desc
.dwHeight
== height
, "Got height %u, expected %u.\n", surface_desc
.dwHeight
, height
);
11411 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== bpp
, "Got bpp %u, expected %u.\n",
11412 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, bpp
);
11414 memset(&surface_desc
, 0, sizeof(surface_desc
));
11415 surface_desc
.dwSize
= sizeof(surface_desc
);
11416 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
11417 surface_desc
.dwBackBufferCount
= 1;
11418 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
;
11419 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
11420 ok(hr
== D3D_OK
, "Failed to create surface, hr %#x.\n", hr
);
11421 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
11422 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
11423 ok(surface_desc
.dwWidth
== width
, "Got width %u, expected %u.\n", surface_desc
.dwWidth
, width
);
11424 ok(surface_desc
.dwHeight
== height
, "Got height %u, expected %u.\n", surface_desc
.dwHeight
, height
);
11425 ok(surface_desc
.ddpfPixelFormat
.dwFlags
== DDPF_RGB
, "Got unexpected pixel format flags %#x.\n",
11426 surface_desc
.ddpfPixelFormat
.dwFlags
);
11427 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== bpp
, "Got bpp %u, expected %u.\n",
11428 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, bpp
);
11429 IDirectDrawSurface_Release(surface
);
11431 memset(&surface_desc
, 0, sizeof(surface_desc
));
11432 surface_desc
.dwSize
= sizeof(surface_desc
);
11433 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
11434 surface_desc
.dwWidth
= width
;
11435 surface_desc
.dwHeight
= height
;
11436 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11437 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
11438 ok(hr
== D3D_OK
, "Failed to create surface, hr %#x.\n", hr
);
11439 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
11440 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
11441 ok(surface_desc
.ddpfPixelFormat
.dwFlags
== DDPF_RGB
, "Got unexpected pixel format flags %#x.\n",
11442 surface_desc
.ddpfPixelFormat
.dwFlags
);
11443 ok(U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
== bpp
, "Got bpp %u, expected %u.\n",
11444 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
, bpp
);
11445 IDirectDrawSurface_Release(surface
);
11447 refcount
= IDirectDraw2_Release(ddraw
);
11448 ok(!refcount
, "DirectDraw has %u references left.\n", refcount
);
11449 DestroyWindow(window
);
11452 static void test_surface_desc_size(void)
11457 DDSURFACEDESC desc1
;
11458 DDSURFACEDESC2 desc2
;
11461 IDirectDrawSurface7
*surface7
;
11462 IDirectDrawSurface2
*surface2
;
11463 IDirectDrawSurface
*surface
;
11464 DDSURFACEDESC surface_desc
;
11465 HRESULT expected_hr
, hr
;
11466 IDirectDraw2
*ddraw
;
11470 static const struct
11477 {DDSCAPS_OFFSCREENPLAIN
, "offscreenplain"},
11478 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, "systemmemory texture"},
11479 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, "videomemory texture"},
11481 static const unsigned int desc_sizes
[] =
11483 sizeof(DDSURFACEDESC
),
11484 sizeof(DDSURFACEDESC2
),
11485 sizeof(DDSURFACEDESC
) + 1,
11486 sizeof(DDSURFACEDESC2
) + 1,
11487 2 * sizeof(DDSURFACEDESC
),
11488 2 * sizeof(DDSURFACEDESC2
),
11489 sizeof(DDSURFACEDESC
) - 1,
11490 sizeof(DDSURFACEDESC2
) - 1,
11491 sizeof(DDSURFACEDESC
) / 2,
11492 sizeof(DDSURFACEDESC2
) / 2,
11497 sizeof(desc
) - 100,
11500 if (!(ddraw
= create_ddraw()))
11502 skip("Failed to create ddraw.\n");
11505 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
11506 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11508 for (i
= 0; i
< ARRAY_SIZE(surface_caps
); ++i
)
11510 memset(&surface_desc
, 0, sizeof(surface_desc
));
11511 surface_desc
.dwSize
= sizeof(surface_desc
);
11512 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
11513 surface_desc
.ddsCaps
.dwCaps
= surface_caps
[i
].caps
;
11514 surface_desc
.dwHeight
= 128;
11515 surface_desc
.dwWidth
= 128;
11516 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
11518 skip("Failed to create surface, type %s.\n", surface_caps
[i
].name
);
11521 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface2
, (void **)&surface2
);
11522 ok(hr
== DD_OK
, "Failed to query IDirectDrawSurface2, hr %#x, type %s.\n", hr
, surface_caps
[i
].name
);
11523 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface7
, (void **)&surface7
);
11524 ok(hr
== DD_OK
, "Failed to query IDirectDrawSurface7, hr %#x, type %s.\n", hr
, surface_caps
[i
].name
);
11526 /* GetSurfaceDesc() */
11527 for (j
= 0; j
< ARRAY_SIZE(desc_sizes
); ++j
)
11529 memset(&desc
, 0, sizeof(desc
));
11530 desc
.dwSize
= desc_sizes
[j
];
11531 expected_hr
= desc
.dwSize
== sizeof(DDSURFACEDESC
) ? DD_OK
: DDERR_INVALIDPARAMS
;
11532 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &desc
.desc1
);
11533 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11534 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11536 memset(&desc
, 0, sizeof(desc
));
11537 desc
.dwSize
= desc_sizes
[j
];
11538 expected_hr
= desc
.dwSize
== sizeof(DDSURFACEDESC
) ? DD_OK
: DDERR_INVALIDPARAMS
;
11539 hr
= IDirectDrawSurface2_GetSurfaceDesc(surface2
, &desc
.desc1
);
11540 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11541 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11543 memset(&desc
, 0, sizeof(desc
));
11544 desc
.dwSize
= desc_sizes
[j
];
11545 expected_hr
= desc
.dwSize
== sizeof(DDSURFACEDESC2
) ? DD_OK
: DDERR_INVALIDPARAMS
;
11546 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface7
, &desc
.desc2
);
11547 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11548 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11552 for (j
= 0; j
< ARRAY_SIZE(desc_sizes
); ++j
)
11554 const BOOL valid_size
= desc_sizes
[j
] == sizeof(DDSURFACEDESC
)
11555 || desc_sizes
[j
] == sizeof(DDSURFACEDESC2
);
11556 DWORD expected_texture_stage
;
11558 memset(&desc
, 0, sizeof(desc
));
11559 desc
.dwSize
= desc_sizes
[j
];
11560 desc
.desc2
.dwTextureStage
= 0xdeadbeef;
11561 desc
.blob
[sizeof(DDSURFACEDESC2
)] = 0xef;
11562 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &desc
.desc1
, 0, 0);
11563 expected_hr
= valid_size
? DD_OK
: DDERR_INVALIDPARAMS
;
11564 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11565 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11566 ok(desc
.dwSize
== desc_sizes
[j
], "dwSize was changed from %u to %u, type %s.\n",
11567 desc_sizes
[j
], desc
.dwSize
, surface_caps
[i
].name
);
11568 ok(desc
.blob
[sizeof(DDSURFACEDESC2
)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
11569 desc
.blob
[sizeof(DDSURFACEDESC2
)], desc_sizes
[j
], surface_caps
[i
].name
);
11572 ok(desc
.desc1
.dwWidth
== 128, "Got unexpected width %u, dwSize %u, type %s.\n",
11573 desc
.desc1
.dwWidth
, desc_sizes
[j
], surface_caps
[i
].name
);
11574 ok(desc
.desc1
.dwHeight
== 128, "Got unexpected height %u, dwSize %u, type %s.\n",
11575 desc
.desc1
.dwHeight
, desc_sizes
[j
], surface_caps
[i
].name
);
11576 expected_texture_stage
= desc_sizes
[j
] >= sizeof(DDSURFACEDESC2
) ? 0 : 0xdeadbeef;
11577 todo_wine_if(!expected_texture_stage
)
11578 ok(desc
.desc2
.dwTextureStage
== expected_texture_stage
,
11579 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
11580 desc
.desc2
.dwTextureStage
, desc_sizes
[j
], surface_caps
[i
].name
);
11581 IDirectDrawSurface_Unlock(surface
, NULL
);
11584 memset(&desc
, 0, sizeof(desc
));
11585 desc
.dwSize
= desc_sizes
[j
];
11586 desc
.desc2
.dwTextureStage
= 0xdeadbeef;
11587 desc
.blob
[sizeof(DDSURFACEDESC2
)] = 0xef;
11588 hr
= IDirectDrawSurface2_Lock(surface2
, NULL
, &desc
.desc1
, 0, 0);
11589 expected_hr
= valid_size
? DD_OK
: DDERR_INVALIDPARAMS
;
11590 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11591 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11592 ok(desc
.dwSize
== desc_sizes
[j
], "dwSize was changed from %u to %u, type %s.\n",
11593 desc_sizes
[j
], desc
.dwSize
, surface_caps
[i
].name
);
11594 ok(desc
.blob
[sizeof(DDSURFACEDESC2
)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
11595 desc
.blob
[sizeof(DDSURFACEDESC2
)], desc_sizes
[j
], surface_caps
[i
].name
);
11598 ok(desc
.desc2
.dwWidth
== 128, "Got unexpected width %u, dwSize %u, type %s.\n",
11599 desc
.desc2
.dwWidth
, desc_sizes
[j
], surface_caps
[i
].name
);
11600 ok(desc
.desc2
.dwHeight
== 128, "Got unexpected height %u, dwSize %u, type %s.\n",
11601 desc
.desc2
.dwHeight
, desc_sizes
[j
], surface_caps
[i
].name
);
11602 expected_texture_stage
= desc_sizes
[j
] >= sizeof(DDSURFACEDESC2
) ? 0 : 0xdeadbeef;
11603 todo_wine_if(!expected_texture_stage
)
11604 ok(desc
.desc2
.dwTextureStage
== expected_texture_stage
,
11605 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
11606 desc
.desc2
.dwTextureStage
, desc_sizes
[j
], surface_caps
[i
].name
);
11607 IDirectDrawSurface2_Unlock(surface2
, NULL
);
11610 memset(&desc
, 0, sizeof(desc
));
11611 desc
.dwSize
= desc_sizes
[j
];
11612 desc
.desc2
.dwTextureStage
= 0xdeadbeef;
11613 desc
.blob
[sizeof(DDSURFACEDESC2
)] = 0xef;
11614 hr
= IDirectDrawSurface7_Lock(surface7
, NULL
, &desc
.desc2
, 0, 0);
11615 expected_hr
= valid_size
? DD_OK
: DDERR_INVALIDPARAMS
;
11616 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, dwSize %u, type %s.\n",
11617 hr
, expected_hr
, desc_sizes
[j
], surface_caps
[i
].name
);
11618 ok(desc
.dwSize
== desc_sizes
[j
], "dwSize was changed from %u to %u, type %s.\n",
11619 desc_sizes
[j
], desc
.dwSize
, surface_caps
[i
].name
);
11620 ok(desc
.blob
[sizeof(DDSURFACEDESC2
)] == 0xef, "Got unexpected byte %02x, dwSize %u, type %s.\n",
11621 desc
.blob
[sizeof(DDSURFACEDESC2
)], desc_sizes
[j
], surface_caps
[i
].name
);
11624 ok(desc
.desc2
.dwWidth
== 128, "Got unexpected width %u, dwSize %u, type %s.\n",
11625 desc
.desc2
.dwWidth
, desc_sizes
[j
], surface_caps
[i
].name
);
11626 ok(desc
.desc2
.dwHeight
== 128, "Got unexpected height %u, dwSize %u, type %s.\n",
11627 desc
.desc2
.dwHeight
, desc_sizes
[j
], surface_caps
[i
].name
);
11628 expected_texture_stage
= desc_sizes
[j
] >= sizeof(DDSURFACEDESC2
) ? 0 : 0xdeadbeef;
11629 ok(desc
.desc2
.dwTextureStage
== expected_texture_stage
,
11630 "Got unexpected texture stage %#x, dwSize %u, type %s.\n",
11631 desc
.desc2
.dwTextureStage
, desc_sizes
[j
], surface_caps
[i
].name
);
11632 IDirectDrawSurface7_Unlock(surface7
, NULL
);
11636 IDirectDrawSurface7_Release(surface7
);
11637 IDirectDrawSurface2_Release(surface2
);
11638 IDirectDrawSurface_Release(surface
);
11641 /* GetDisplayMode() */
11642 for (j
= 0; j
< ARRAY_SIZE(desc_sizes
); ++j
)
11644 memset(&desc
, 0xcc, sizeof(desc
));
11645 desc
.dwSize
= desc_sizes
[j
];
11646 expected_hr
= (desc
.dwSize
== sizeof(DDSURFACEDESC
) || desc
.dwSize
== sizeof(DDSURFACEDESC2
))
11647 ? DD_OK
: DDERR_INVALIDPARAMS
;
11648 hr
= IDirectDraw2_GetDisplayMode(ddraw
, &desc
.desc1
);
11649 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, size %u.\n", hr
, expected_hr
, desc_sizes
[j
]);
11652 ok(desc
.dwSize
== sizeof(DDSURFACEDESC
), "Wrong size %u for %u.\n", desc
.dwSize
, desc_sizes
[j
]);
11653 ok(desc
.blob
[desc_sizes
[j
]] == 0xcc, "Overflow for size %u.\n", desc_sizes
[j
]);
11654 ok(desc
.blob
[desc_sizes
[j
] - 1] != 0xcc, "Struct not cleared for size %u.\n", desc_sizes
[j
]);
11658 refcount
= IDirectDraw2_Release(ddraw
);
11659 ok(!refcount
, "DirectDraw has %u references left.\n", refcount
);
11662 static void test_ck_operation(void)
11664 IDirectDrawSurface2
*src
, *dst
;
11665 IDirectDrawSurface7
*src7
, *dst7
;
11666 IDirectDrawSurface
*surface1
;
11667 DDSURFACEDESC surface_desc
;
11668 IDirectDraw2
*ddraw
;
11677 window
= create_window();
11678 ddraw
= create_ddraw();
11679 ok(!!ddraw
, "Failed to create a ddraw object.\n");
11680 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
11681 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
11683 memset(&surface_desc
, 0, sizeof(surface_desc
));
11684 surface_desc
.dwSize
= sizeof(surface_desc
);
11685 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
11686 surface_desc
.dwWidth
= 4;
11687 surface_desc
.dwHeight
= 1;
11688 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11689 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
11690 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
11691 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
11692 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
11693 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
11694 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
11695 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
11696 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&dst
);
11697 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface2, hr %#x.\n", hr
);
11698 IDirectDrawSurface_Release(surface1
);
11700 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
11701 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff00ff;
11702 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff00ff;
11703 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
11704 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
11705 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&src
);
11706 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface2, hr %#x.\n", hr
);
11707 IDirectDrawSurface_Release(surface1
);
11709 hr
= IDirectDrawSurface2_Lock(src
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11710 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11711 ok(!(surface_desc
.dwFlags
& DDSD_LPSURFACE
), "Surface desc has LPSURFACE Flags set.\n");
11712 color
= surface_desc
.lpSurface
;
11713 color
[0] = 0x77010203;
11714 color
[1] = 0x00010203;
11715 color
[2] = 0x77ff00ff;
11716 color
[3] = 0x00ff00ff;
11717 hr
= IDirectDrawSurface2_Unlock(src
, NULL
);
11718 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11720 for (i
= 0; i
< 2; ++i
)
11722 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11723 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11724 color
= surface_desc
.lpSurface
;
11725 color
[0] = 0xcccccccc;
11726 color
[1] = 0xcccccccc;
11727 color
[2] = 0xcccccccc;
11728 color
[3] = 0xcccccccc;
11729 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11730 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11734 hr
= IDirectDrawSurface2_BltFast(dst
, 0, 0, src
, NULL
, DDBLTFAST_SRCCOLORKEY
);
11735 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11739 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
, NULL
);
11740 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11743 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
| DDLOCK_READONLY
, NULL
);
11744 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11745 ok(!(surface_desc
.dwFlags
& DDSD_LPSURFACE
), "Surface desc has LPSURFACE Flags set.\n");
11746 color
= surface_desc
.lpSurface
;
11747 /* Different behavior on some drivers / windows versions. Some versions ignore the X channel when
11748 * color keying, but copy it to the destination surface. Others (sysmem surfaces) apply it for
11749 * color keying, but do not copy it into the destination surface. Nvidia neither uses it for
11750 * color keying nor copies it. */
11751 ok((color
[0] == 0x77010203 && color
[1] == 0x00010203
11752 && color
[2] == 0xcccccccc && color
[3] == 0xcccccccc) /* AMD, Wine */
11753 || broken(color
[0] == 0x00010203 && color
[1] == 0x00010203
11754 && color
[2] == 0x00ff00ff && color
[3] == 0xcccccccc) /* Sysmem surfaces? */
11755 || broken(color
[0] == 0x00010203 && color
[1] == 0x00010203
11756 && color
[2] == 0xcccccccc && color
[3] == 0xcccccccc) /* Nvidia */
11757 || broken(color
[0] == 0xff010203 && color
[1] == 0xff010203
11758 && color
[2] == 0xcccccccc && color
[3] == 0xcccccccc) /* Testbot */,
11759 "Destination data after blitting is %08x %08x %08x %08x, i=%u.\n",
11760 color
[0], color
[1], color
[2], color
[3], i
);
11761 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11762 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11765 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11766 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
11767 ok(ckey
.dwColorSpaceLowValue
== 0x00ff00ff && ckey
.dwColorSpaceHighValue
== 0x00ff00ff,
11768 "Got unexpected color key low=%08x high=%08x.\n", ckey
.dwColorSpaceLowValue
, ckey
.dwColorSpaceHighValue
);
11770 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
11771 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11772 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11774 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0;
11775 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11776 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
11777 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00 && ckey
.dwColorSpaceHighValue
== 0x0000ff00,
11778 "Got unexpected color key low=%08x high=%08x.\n", ckey
.dwColorSpaceLowValue
, ckey
.dwColorSpaceHighValue
);
11780 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0;
11781 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0;
11782 hr
= IDirectDrawSurface2_GetSurfaceDesc(src
, &surface_desc
);
11783 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
11784 ok(surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
== 0x0000ff00
11785 && surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
== 0x0000ff00,
11786 "Got unexpected color key low=%08x high=%08x.\n", surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
,
11787 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
);
11789 /* Test SetColorKey with dwColorSpaceHighValue < dwColorSpaceLowValue */
11790 ckey
.dwColorSpaceLowValue
= 0x000000ff;
11791 ckey
.dwColorSpaceHighValue
= 0x00000000;
11792 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11793 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11795 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0;
11796 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11797 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
11798 ok(ckey
.dwColorSpaceLowValue
== 0x000000ff && ckey
.dwColorSpaceHighValue
== 0x000000ff,
11799 "Got unexpected color key low=%08x high=%08x.\n", ckey
.dwColorSpaceLowValue
, ckey
.dwColorSpaceHighValue
);
11801 ckey
.dwColorSpaceLowValue
= 0x000000ff;
11802 ckey
.dwColorSpaceHighValue
= 0x00000001;
11803 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11804 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11806 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0;
11807 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11808 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
11809 ok(ckey
.dwColorSpaceLowValue
== 0x000000ff && ckey
.dwColorSpaceHighValue
== 0x000000ff,
11810 "Got unexpected color key low=%08x high=%08x.\n", ckey
.dwColorSpaceLowValue
, ckey
.dwColorSpaceHighValue
);
11812 ckey
.dwColorSpaceLowValue
= 0x000000fe;
11813 ckey
.dwColorSpaceHighValue
= 0x000000fd;
11814 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11815 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11817 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0;
11818 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11819 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
11820 ok(ckey
.dwColorSpaceLowValue
== 0x000000fe && ckey
.dwColorSpaceHighValue
== 0x000000fe,
11821 "Got unexpected color key low=%08x high=%08x.\n", ckey
.dwColorSpaceLowValue
, ckey
.dwColorSpaceHighValue
);
11823 IDirectDrawSurface2_Release(src
);
11824 IDirectDrawSurface2_Release(dst
);
11826 /* Test source and destination keys and where they are read from. Use a surface with alpha
11827 * to avoid driver-dependent content in the X channel. */
11828 memset(&surface_desc
, 0, sizeof(surface_desc
));
11829 surface_desc
.dwSize
= sizeof(surface_desc
);
11830 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
11831 surface_desc
.dwWidth
= 6;
11832 surface_desc
.dwHeight
= 1;
11833 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
11834 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
11835 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
11836 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
11837 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
11838 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
11839 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
11840 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
11841 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
11842 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&dst
);
11843 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface2, hr %#x.\n", hr
);
11844 IDirectDrawSurface_Release(surface1
);
11846 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
11847 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
11848 hr
= IDirectDrawSurface_QueryInterface(surface1
, &IID_IDirectDrawSurface2
, (void **)&src
);
11849 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface2, hr %#x.\n", hr
);
11850 IDirectDrawSurface_Release(surface1
);
11852 ckey
.dwColorSpaceLowValue
= 0x0000ff00;
11853 ckey
.dwColorSpaceHighValue
= 0x0000ff00;
11854 hr
= IDirectDrawSurface2_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
11855 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11856 ckey
.dwColorSpaceLowValue
= 0x00ff0000;
11857 ckey
.dwColorSpaceHighValue
= 0x00ff0000;
11858 hr
= IDirectDrawSurface2_SetColorKey(dst
, DDCKEY_DESTBLT
, &ckey
);
11859 ok(SUCCEEDED(hr
) || hr
== DDERR_NOCOLORKEYHW
, "Failed to set color key, hr %#x.\n", hr
);
11862 /* Nvidia reject dest keys, AMD allows them. This applies to vidmem and sysmem surfaces. */
11863 skip("Failed to set destination color key, skipping related tests.\n");
11867 ckey
.dwColorSpaceLowValue
= 0x000000ff;
11868 ckey
.dwColorSpaceHighValue
= 0x000000ff;
11869 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
11870 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11871 ckey
.dwColorSpaceLowValue
= 0x000000aa;
11872 ckey
.dwColorSpaceHighValue
= 0x000000aa;
11873 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_DESTBLT
, &ckey
);
11874 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
11876 memset(&fx
, 0, sizeof(fx
));
11877 fx
.dwSize
= sizeof(fx
);
11878 fx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 0x00110000;
11879 fx
.ddckSrcColorkey
.dwColorSpaceLowValue
= 0x00110000;
11880 fx
.ddckDestColorkey
.dwColorSpaceHighValue
= 0x00001100;
11881 fx
.ddckDestColorkey
.dwColorSpaceLowValue
= 0x00001100;
11883 hr
= IDirectDrawSurface2_Lock(src
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11884 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11885 color
= surface_desc
.lpSurface
;
11886 color
[0] = 0x000000ff; /* Applies to src blt key in src surface. */
11887 color
[1] = 0x000000aa; /* Applies to dst blt key in src surface. */
11888 color
[2] = 0x00ff0000; /* Dst color key in dst surface. */
11889 color
[3] = 0x0000ff00; /* Src color key in dst surface. */
11890 color
[4] = 0x00001100; /* Src color key in ddbltfx. */
11891 color
[5] = 0x00110000; /* Dst color key in ddbltfx. */
11892 hr
= IDirectDrawSurface2_Unlock(src
, NULL
);
11893 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11895 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11896 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11897 color
= surface_desc
.lpSurface
;
11898 color
[0] = color
[1] = color
[2] = color
[3] = color
[4] = color
[5] = 0x55555555;
11899 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11900 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11902 /* Test a blit without keying. */
11903 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, 0, &fx
);
11904 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11906 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11907 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11908 color
= surface_desc
.lpSurface
;
11909 /* Should have copied src data unmodified to dst. */
11910 ok(color
[0] == 0x000000ff && color
[1] == 0x000000aa && color
[2] == 0x00ff0000 &&
11911 color
[3] == 0x0000ff00 && color
[4] == 0x00001100 && color
[5] == 0x00110000,
11912 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11913 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11915 color
[0] = color
[1] = color
[2] = color
[3] = color
[4] = color
[5] = 0x55555555;
11916 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11917 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11920 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
, &fx
);
11921 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11923 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11924 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11925 color
= surface_desc
.lpSurface
;
11926 /* Src key applied to color[0]. It is unmodified, the others are copied. */
11927 ok(color
[0] == 0x55555555 && color
[1] == 0x000000aa && color
[2] == 0x00ff0000 &&
11928 color
[3] == 0x0000ff00 && color
[4] == 0x00001100 && color
[5] == 0x00110000,
11929 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11930 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11932 color
[0] = color
[1] = color
[2] = color
[3] = color
[4] = color
[5] = 0x55555555;
11933 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11934 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11936 /* Src override. */
11937 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRCOVERRIDE
, &fx
);
11938 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11940 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11941 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11942 color
= surface_desc
.lpSurface
;
11943 /* Override key applied to color[5]. It is unmodified, the others are copied. */
11944 ok(color
[0] == 0x000000ff && color
[1] == 0x000000aa && color
[2] == 0x00ff0000 &&
11945 color
[3] == 0x0000ff00 && color
[4] == 0x00001100 && color
[5] == 0x55555555,
11946 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11947 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11949 color
[0] = color
[1] = color
[2] = color
[3] = color
[4] = color
[5] = 0x55555555;
11950 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11951 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11953 /* Src override AND src key. That is not supposed to work. */
11954 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_KEYSRCOVERRIDE
, &fx
);
11955 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
11957 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11958 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11959 color
= surface_desc
.lpSurface
;
11960 /* Ensure the destination was not changed. */
11961 ok(color
[0] == 0x55555555 && color
[1] == 0x55555555 && color
[2] == 0x55555555 &&
11962 color
[3] == 0x55555555 && color
[4] == 0x55555555 && color
[5] == 0x55555555,
11963 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11964 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11966 /* Use different dst colors for the dst key test. */
11967 color
[0] = 0x00ff0000; /* Dest key in dst surface. */
11968 color
[1] = 0x00ff0000; /* Dest key in dst surface. */
11969 color
[2] = 0x00001100; /* Dest key in override. */
11970 color
[3] = 0x00001100; /* Dest key in override. */
11971 color
[4] = 0x000000aa; /* Dest key in src surface. */
11972 color
[5] = 0x000000aa; /* Dest key in src surface. */
11973 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11974 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11976 /* Dest key blit. The key is taken from the SOURCE surface in v2! */
11977 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDEST
, &fx
);
11978 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
11980 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
11981 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
11982 color
= surface_desc
.lpSurface
;
11983 /* Dst key applied to color[4,5], they are the only changed pixels. */
11984 ok(color
[0] == 0x00ff0000 && color
[1] == 0x00ff0000 && color
[2] == 0x00001100 &&
11985 color
[3] == 0x00001100 && color
[4] == 0x00001100 && color
[5] == 0x00110000,
11986 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
11987 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
11989 color
[0] = 0x00ff0000; /* Dest key in dst surface. */
11990 color
[1] = 0x00ff0000; /* Dest key in dst surface. */
11991 color
[2] = 0x00001100; /* Dest key in override. */
11992 color
[3] = 0x00001100; /* Dest key in override. */
11993 color
[4] = 0x000000aa; /* Dest key in src surface. */
11994 color
[5] = 0x000000aa; /* Dest key in src surface. */
11995 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
11996 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
11998 /* What happens with a QI'd newer version of the interface? It takes the key
11999 * from the destination surface. */
12000 hr
= IDirectDrawSurface2_QueryInterface(src
, &IID_IDirectDrawSurface7
, (void **)&src7
);
12001 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr
);
12002 hr
= IDirectDrawSurface2_QueryInterface(dst
, &IID_IDirectDrawSurface7
, (void **)&dst7
);
12003 ok(SUCCEEDED(hr
), "Failed to query IDirectDrawSurface interface, hr %#x.\n", hr
);
12005 hr
= IDirectDrawSurface7_Blt(dst7
, NULL
, src7
, NULL
, DDBLT_KEYDEST
, &fx
);
12006 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
12008 IDirectDrawSurface7_Release(dst7
);
12009 IDirectDrawSurface7_Release(src7
);
12011 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
12012 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
12013 color
= surface_desc
.lpSurface
;
12014 /* Dst key applied to color[0,1], they are the only changed pixels. */
12015 todo_wine
ok(color
[0] == 0x000000ff && color
[1] == 0x000000aa && color
[2] == 0x00001100 &&
12016 color
[3] == 0x00001100 && color
[4] == 0x000000aa && color
[5] == 0x000000aa,
12017 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12018 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
12020 color
[0] = 0x00ff0000; /* Dest key in dst surface. */
12021 color
[1] = 0x00ff0000; /* Dest key in dst surface. */
12022 color
[2] = 0x00001100; /* Dest key in override. */
12023 color
[3] = 0x00001100; /* Dest key in override. */
12024 color
[4] = 0x000000aa; /* Dest key in src surface. */
12025 color
[5] = 0x000000aa; /* Dest key in src surface. */
12026 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
12027 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
12029 /* Dest override key blit. */
12030 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDESTOVERRIDE
, &fx
);
12031 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
12033 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
12034 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
12035 color
= surface_desc
.lpSurface
;
12036 /* Dst key applied to color[2,3], they are the only changed pixels. */
12037 ok(color
[0] == 0x00ff0000 && color
[1] == 0x00ff0000 && color
[2] == 0x00ff0000 &&
12038 color
[3] == 0x0000ff00 && color
[4] == 0x000000aa && color
[5] == 0x000000aa,
12039 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12040 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
12042 color
[0] = 0x00ff0000; /* Dest key in dst surface. */
12043 color
[1] = 0x00ff0000; /* Dest key in dst surface. */
12044 color
[2] = 0x00001100; /* Dest key in override. */
12045 color
[3] = 0x00001100; /* Dest key in override. */
12046 color
[4] = 0x000000aa; /* Dest key in src surface. */
12047 color
[5] = 0x000000aa; /* Dest key in src surface. */
12048 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
12049 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
12051 /* Dest override together with surface key. Supposed to fail. */
12052 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDEST
| DDBLT_KEYDESTOVERRIDE
, &fx
);
12053 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
12055 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
12056 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
12057 color
= surface_desc
.lpSurface
;
12058 /* Destination is unchanged. */
12059 ok(color
[0] == 0x00ff0000 && color
[1] == 0x00ff0000 && color
[2] == 0x00001100 &&
12060 color
[3] == 0x00001100 && color
[4] == 0x000000aa && color
[5] == 0x000000aa,
12061 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12062 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
12063 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
12064 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
12066 /* Source and destination key. This is driver dependent. New HW treats it like
12067 * DDBLT_KEYSRC. Older HW and some software renderers apply both keys. */
12070 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDEST
| DDBLT_KEYSRC
, &fx
);
12071 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
12073 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
12074 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
12075 color
= surface_desc
.lpSurface
;
12076 /* Color[0] is filtered by the src key, 2-5 are filtered by the dst key, if
12077 * the driver applies it. */
12078 ok(color
[0] == 0x00ff0000 && color
[1] == 0x000000aa && color
[2] == 0x00ff0000 &&
12079 color
[3] == 0x0000ff00 && color
[4] == 0x00001100 && color
[5] == 0x00110000,
12080 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12081 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
12083 color
[0] = 0x00ff0000; /* Dest key in dst surface. */
12084 color
[1] = 0x00ff0000; /* Dest key in dst surface. */
12085 color
[2] = 0x00001100; /* Dest key in override. */
12086 color
[3] = 0x00001100; /* Dest key in override. */
12087 color
[4] = 0x000000aa; /* Dest key in src surface. */
12088 color
[5] = 0x000000aa; /* Dest key in src surface. */
12089 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
12090 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
12093 /* Override keys without ddbltfx parameter fail */
12094 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDESTOVERRIDE
, NULL
);
12095 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
12096 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRCOVERRIDE
, NULL
);
12097 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
12099 /* Try blitting without keys in the source surface. */
12100 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
12101 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
12102 hr
= IDirectDrawSurface2_SetColorKey(src
, DDCKEY_DESTBLT
, NULL
);
12103 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
12105 /* That fails now. Do not bother to check that the data is unmodified. */
12106 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
, &fx
);
12107 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
12109 /* Surprisingly this still works. It uses the old key from the src surface. */
12110 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDEST
, &fx
);
12111 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
12113 hr
= IDirectDrawSurface2_Lock(dst
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
12114 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
12115 color
= surface_desc
.lpSurface
;
12116 /* Dst key applied to color[4,5], they are the only changed pixels. */
12117 ok(color
[0] == 0x00ff0000 && color
[1] == 0x00ff0000 && color
[2] == 0x00001100 &&
12118 color
[3] == 0x00001100 && color
[4] == 0x00001100 && color
[5] == 0x00110000,
12119 "Got unexpected content %08x %08x %08x %08x %08x %08x.\n",
12120 color
[0], color
[1], color
[2], color
[3], color
[4], color
[5]);
12121 hr
= IDirectDrawSurface2_Unlock(dst
, NULL
);
12122 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
12124 /* This returns DDERR_NOCOLORKEY as expected. */
12125 hr
= IDirectDrawSurface2_GetColorKey(src
, DDCKEY_DESTBLT
, &ckey
);
12126 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
12128 /* GetSurfaceDesc returns a zeroed key as expected. */
12129 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x12345678;
12130 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x12345678;
12131 hr
= IDirectDrawSurface2_GetSurfaceDesc(src
, &surface_desc
);
12132 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
12133 ok(!surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
12134 && !surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
,
12135 "Got unexpected color key low=%08x high=%08x.\n", surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
,
12136 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
);
12138 /* Try blitting without keys in the destination surface. */
12139 hr
= IDirectDrawSurface2_SetColorKey(dst
, DDCKEY_SRCBLT
, NULL
);
12140 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
12141 hr
= IDirectDrawSurface2_SetColorKey(dst
, DDCKEY_DESTBLT
, NULL
);
12142 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
12144 /* This fails, as sanity would dictate. */
12145 hr
= IDirectDrawSurface2_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYDEST
, &fx
);
12146 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
12149 IDirectDrawSurface2_Release(src
);
12150 IDirectDrawSurface2_Release(dst
);
12151 refcount
= IDirectDraw2_Release(ddraw
);
12152 ok(!refcount
, "DirectDraw has %u references left.\n", refcount
);
12153 DestroyWindow(window
);
12156 static void test_depth_readback(void)
12158 DWORD depth
, expected_depth
, max_diff
;
12159 IDirect3DMaterial2
*blue_background
;
12160 IDirectDrawSurface
*rt
, *ds
;
12161 IDirect3DViewport2
*viewport
;
12162 DDSURFACEDESC surface_desc
;
12163 IDirect3DDevice2
*device
;
12164 unsigned int i
, x
, y
;
12165 IDirectDraw2
*ddraw
;
12171 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
12172 static D3DLVERTEX quad
[] =
12174 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xff00ff00}},
12175 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
12176 {{ 1.0f
}, {-1.0f
}, {1.0f
}, 0, {0xff00ff00}},
12177 {{ 1.0f
}, { 1.0f
}, {0.9f
}, 0, {0xff00ff00}},
12180 static const struct
12182 unsigned int z_depth
, z_mask
;
12191 window
= create_window();
12192 ok(!!window
, "Failed to create a window.\n");
12193 ddraw
= create_ddraw();
12194 ok(!!ddraw
, "Failed to create a ddraw object.\n");
12195 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
12197 skip("Failed to create a D3D device, skipping tests.\n");
12198 IDirectDraw2_Release(ddraw
);
12199 DestroyWindow(window
);
12203 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
12204 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
12205 blue_background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
12206 viewport
= create_viewport(device
, 0, 0, 640, 480);
12207 viewport_set_background(device
, viewport
, blue_background
);
12208 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
12209 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
12211 hr
= IDirect3DDevice2_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
12212 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
12214 ds
= get_depth_stencil(device
);
12215 hr
= IDirectDrawSurface_DeleteAttachedSurface(rt
, 0, ds
);
12216 ok(SUCCEEDED(hr
), "Failed to detach depth buffer, hr %#x.\n", hr
);
12217 IDirectDrawSurface_Release(ds
);
12219 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
12221 memset(&surface_desc
, 0, sizeof(surface_desc
));
12222 surface_desc
.dwSize
= sizeof(surface_desc
);
12223 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
12224 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
;
12225 U2(surface_desc
).dwZBufferBitDepth
= tests
[i
].z_depth
;
12226 surface_desc
.dwWidth
= 640;
12227 surface_desc
.dwHeight
= 480;
12228 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
12231 skip("Format %u not supported, skipping test.\n", i
);
12235 hr
= IDirectDrawSurface_AddAttachedSurface(rt
, ds
);
12236 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
12237 hr
= IDirect3DDevice2_SetRenderTarget(device
, rt
, 0);
12238 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
12240 hr
= IDirect3DViewport2_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
12241 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12242 hr
= IDirect3DDevice2_BeginScene(device
);
12243 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
12244 hr
= IDirect3DDevice2_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DVT_LVERTEX
, quad
, 4, 0);
12245 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
12246 hr
= IDirect3DDevice2_EndScene(device
);
12247 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
12249 memset(&surface_desc
, 0, sizeof(surface_desc
));
12250 surface_desc
.dwSize
= sizeof(surface_desc
);
12251 hr
= IDirectDrawSurface_Lock(ds
, NULL
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
12252 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
12254 for (y
= 60; y
< 480; y
+= 120)
12256 for (x
= 80; x
< 640; x
+= 160)
12258 ptr
= (BYTE
*)surface_desc
.lpSurface
12259 + y
* U1(surface_desc
).lPitch
12260 + x
* (tests
[i
].z_depth
== 16 ? 2 : 4);
12261 depth
= *((DWORD
*)ptr
) & tests
[i
].z_mask
;
12262 expected_depth
= (x
* (0.9 / 640.0) + y
* (0.1 / 480.0)) * tests
[i
].z_mask
;
12263 max_diff
= ((0.5f
* 0.9f
) / 640.0f
) * tests
[i
].z_mask
;
12264 ok(abs(expected_depth
- depth
) <= max_diff
,
12265 "Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
12266 i
, depth
, expected_depth
- depth
, expected_depth
, max_diff
, x
, y
);
12270 hr
= IDirectDrawSurface_Unlock(ds
, NULL
);
12271 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
12273 hr
= IDirectDrawSurface_DeleteAttachedSurface(rt
, 0, ds
);
12274 ok(SUCCEEDED(hr
), "Failed to detach depth buffer, hr %#x.\n", hr
);
12275 IDirectDrawSurface_Release(ds
);
12278 destroy_viewport(device
, viewport
);
12279 destroy_material(blue_background
);
12280 IDirectDrawSurface_Release(rt
);
12281 refcount
= IDirect3DDevice2_Release(device
);
12282 ok(!refcount
, "Device has %u references left.\n", refcount
);
12283 IDirectDraw2_Release(ddraw
);
12284 DestroyWindow(window
);
12287 static void test_clear(void)
12289 D3DRECT rect_negneg
, rect_full
= {{0}, {0}, {640}, {480}};
12290 IDirect3DViewport2
*viewport
, *viewport2
, *viewport3
;
12291 IDirect3DMaterial2
*white
, *red
, *green
, *blue
;
12292 IDirect3DDevice2
*device
;
12293 IDirectDrawSurface
*rt
;
12294 IDirectDraw2
*ddraw
;
12301 window
= create_window();
12302 ddraw
= create_ddraw();
12303 ok(!!ddraw
, "Failed to create a ddraw object.\n");
12304 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
12306 skip("Failed to create a 3D device, skipping test.\n");
12307 IDirectDraw2_Release(ddraw
);
12308 DestroyWindow(window
);
12311 hr
= IDirect3DDevice2_GetRenderTarget(device
, &rt
);
12312 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
12314 viewport
= create_viewport(device
, 0, 0, 640, 480);
12315 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
12316 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
12318 white
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
12319 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
12320 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
12321 blue
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
12323 viewport_set_background(device
, viewport
, white
);
12324 hr
= IDirect3DViewport2_Clear(viewport
, 1, &rect_full
, D3DCLEAR_TARGET
);
12325 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12327 /* Positive x, negative y. */
12328 U1(rect
[0]).x1
= 0;
12329 U2(rect
[0]).y1
= 480;
12330 U3(rect
[0]).x2
= 320;
12331 U4(rect
[0]).y2
= 240;
12333 /* Positive x, positive y. */
12334 U1(rect
[1]).x1
= 0;
12335 U2(rect
[1]).y1
= 0;
12336 U3(rect
[1]).x2
= 320;
12337 U4(rect
[1]).y2
= 240;
12339 /* Clear 2 rectangles with one call. Unlike d3d8/9, the refrast does not
12340 * refuse negative rectangles, but it will not clear them either. */
12341 viewport_set_background(device
, viewport
, red
);
12342 hr
= IDirect3DViewport2_Clear(viewport
, 2, rect
, D3DCLEAR_TARGET
);
12343 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12345 color
= get_surface_color(rt
, 160, 360);
12346 ok(compare_color(color
, 0x00ffffff, 0), "Clear rectangle 3 (pos, neg) has color 0x%08x.\n", color
);
12347 color
= get_surface_color(rt
, 160, 120);
12348 ok(compare_color(color
, 0x00ff0000, 0), "Clear rectangle 1 (pos, pos) has color 0x%08x.\n", color
);
12349 color
= get_surface_color(rt
, 480, 360);
12350 ok(compare_color(color
, 0x00ffffff, 0), "Clear rectangle 4 (NULL) has color 0x%08x.\n", color
);
12351 color
= get_surface_color(rt
, 480, 120);
12352 ok(compare_color(color
, 0x00ffffff, 0), "Clear rectangle 4 (neg, neg) has color 0x%08x.\n", color
);
12354 viewport_set_background(device
, viewport
, white
);
12355 hr
= IDirect3DViewport2_Clear(viewport
, 1, &rect_full
, D3DCLEAR_TARGET
);
12356 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12358 /* negative x, negative y.
12359 * Also ignored, except on WARP, which clears the entire screen. */
12360 rect_negneg
.x1
= 640;
12361 rect_negneg
.y1
= 240;
12362 rect_negneg
.x2
= 320;
12363 rect_negneg
.y2
= 0;
12364 viewport_set_background(device
, viewport
, green
);
12365 hr
= IDirect3DViewport2_Clear(viewport
, 1, &rect_negneg
, D3DCLEAR_TARGET
);
12366 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12368 color
= get_surface_color(rt
, 160, 360);
12369 ok(compare_color(color
, 0x00ffffff, 0)
12370 || broken(ddraw_is_warp(ddraw
) && compare_color(color
, 0x0000ff00, 0)),
12371 "Got unexpected color 0x%08x.\n", color
);
12372 color
= get_surface_color(rt
, 160, 120);
12373 ok(compare_color(color
, 0x00ffffff, 0)
12374 || broken(ddraw_is_warp(ddraw
) && compare_color(color
, 0x0000ff00, 0)),
12375 "Got unexpected color 0x%08x.\n", color
);
12376 color
= get_surface_color(rt
, 480, 360);
12377 ok(compare_color(color
, 0x00ffffff, 0)
12378 || broken(ddraw_is_warp(ddraw
) && compare_color(color
, 0x0000ff00, 0)),
12379 "Got unexpected color 0x%08x.\n", color
);
12380 color
= get_surface_color(rt
, 480, 120);
12381 ok(compare_color(color
, 0x00ffffff, 0)
12382 || broken(ddraw_is_warp(ddraw
) && compare_color(color
, 0x0000ff00, 0)),
12383 "Got unexpected color 0x%08x.\n", color
);
12385 /* Test how the viewport affects clears. */
12386 viewport_set_background(device
, viewport
, white
);
12387 hr
= IDirect3DViewport2_Clear(viewport
, 1, &rect_full
, D3DCLEAR_TARGET
);
12388 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12390 viewport2
= create_viewport(device
, 160, 120, 160, 120);
12391 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport2
);
12392 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
12394 viewport_set_background(device
, viewport2
, blue
);
12395 hr
= IDirect3DViewport2_Clear(viewport2
, 1, &rect_full
, D3DCLEAR_TARGET
);
12396 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12398 viewport3
= create_viewport(device
, 320, 240, 320, 240);
12399 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport3
);
12400 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
12402 U1(rect
[0]).x1
= 160;
12403 U2(rect
[0]).y1
= 120;
12404 U3(rect
[0]).x2
= 480;
12405 U4(rect
[0]).y2
= 360;
12406 viewport_set_background(device
, viewport3
, green
);
12407 hr
= IDirect3DViewport2_Clear(viewport3
, 1, &rect
[0], D3DCLEAR_TARGET
);
12408 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12410 hr
= IDirect3DDevice2_SetCurrentViewport(device
, viewport
);
12411 ok(SUCCEEDED(hr
), "Failed to set current viewport, hr %#x.\n", hr
);
12413 color
= get_surface_color(rt
, 158, 118);
12414 ok(compare_color(color
, 0x00ffffff, 0), "(158, 118) has color 0x%08x.\n", color
);
12415 color
= get_surface_color(rt
, 162, 118);
12416 ok(compare_color(color
, 0x00ffffff, 0), "(162, 118) has color 0x%08x.\n", color
);
12417 color
= get_surface_color(rt
, 158, 122);
12418 ok(compare_color(color
, 0x00ffffff, 0), "(158, 122) has color 0x%08x.\n", color
);
12419 color
= get_surface_color(rt
, 162, 122);
12420 ok(compare_color(color
, 0x000000ff, 0), "(162, 122) has color 0x%08x.\n", color
);
12422 color
= get_surface_color(rt
, 318, 238);
12423 ok(compare_color(color
, 0x000000ff, 0), "(318, 238) has color 0x%08x.\n", color
);
12424 color
= get_surface_color(rt
, 322, 238);
12425 ok(compare_color(color
, 0x00ffffff, 0), "(322, 238) has color 0x%08x.\n", color
);
12426 color
= get_surface_color(rt
, 318, 242);
12427 ok(compare_color(color
, 0x00ffffff, 0), "(318, 242) has color 0x%08x.\n", color
);
12428 color
= get_surface_color(rt
, 322, 242);
12429 ok(compare_color(color
, 0x0000ff00, 0), "(322, 242) has color 0x%08x.\n", color
);
12431 color
= get_surface_color(rt
, 478, 358);
12432 ok(compare_color(color
, 0x0000ff00, 0), "(478, 358) has color 0x%08x.\n", color
);
12433 color
= get_surface_color(rt
, 482, 358);
12434 ok(compare_color(color
, 0x00ffffff, 0), "(482, 358) has color 0x%08x.\n", color
);
12435 color
= get_surface_color(rt
, 478, 362);
12436 ok(compare_color(color
, 0x00ffffff, 0), "(478, 362) has color 0x%08x.\n", color
);
12437 color
= get_surface_color(rt
, 482, 362);
12438 ok(compare_color(color
, 0x00ffffff, 0), "(482, 362) has color 0x%08x.\n", color
);
12440 /* The clear rectangle is rendertarget absolute, not relative to the
12442 hr
= IDirect3DViewport2_Clear(viewport
, 1, &rect_full
, D3DCLEAR_TARGET
);
12443 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12444 U1(rect
[0]).x1
= 330;
12445 U2(rect
[0]).y1
= 250;
12446 U3(rect
[0]).x2
= 340;
12447 U4(rect
[0]).y2
= 260;
12448 hr
= IDirect3DViewport2_Clear(viewport3
, 1, &rect
[0], D3DCLEAR_TARGET
);
12449 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
12451 color
= get_surface_color(rt
, 328, 248);
12452 ok(compare_color(color
, 0x00ffffff, 0), "(328, 248) has color 0x%08x.\n", color
);
12453 color
= get_surface_color(rt
, 332, 248);
12454 ok(compare_color(color
, 0x00ffffff, 0), "(332, 248) has color 0x%08x.\n", color
);
12455 color
= get_surface_color(rt
, 328, 252);
12456 ok(compare_color(color
, 0x00ffffff, 0), "(328, 252) has color 0x%08x.\n", color
);
12457 color
= get_surface_color(rt
, 332, 252);
12458 ok(compare_color(color
, 0x0000ff00, 0), "(332, 252) has color 0x%08x.\n", color
);
12460 color
= get_surface_color(rt
, 338, 248);
12461 ok(compare_color(color
, 0x00ffffff, 0), "(338, 248) has color 0x%08x.\n", color
);
12462 color
= get_surface_color(rt
, 342, 248);
12463 ok(compare_color(color
, 0x00ffffff, 0), "(342, 248) has color 0x%08x.\n", color
);
12464 color
= get_surface_color(rt
, 338, 252);
12465 ok(compare_color(color
, 0x0000ff00, 0), "(338, 252) has color 0x%08x.\n", color
);
12466 color
= get_surface_color(rt
, 342, 252);
12467 ok(compare_color(color
, 0x00ffffff, 0), "(342, 252) has color 0x%08x.\n", color
);
12469 color
= get_surface_color(rt
, 328, 258);
12470 ok(compare_color(color
, 0x00ffffff, 0), "(328, 258) has color 0x%08x.\n", color
);
12471 color
= get_surface_color(rt
, 332, 258);
12472 ok(compare_color(color
, 0x0000ff00, 0), "(332, 258) has color 0x%08x.\n", color
);
12473 color
= get_surface_color(rt
, 328, 262);
12474 ok(compare_color(color
, 0x00ffffff, 0), "(328, 262) has color 0x%08x.\n", color
);
12475 color
= get_surface_color(rt
, 332, 262);
12476 ok(compare_color(color
, 0x00ffffff, 0), "(332, 262) has color 0x%08x.\n", color
);
12478 color
= get_surface_color(rt
, 338, 258);
12479 ok(compare_color(color
, 0x0000ff00, 0), "(338, 258) has color 0x%08x.\n", color
);
12480 color
= get_surface_color(rt
, 342, 258);
12481 ok(compare_color(color
, 0x00ffffff, 0), "(342, 258) has color 0x%08x.\n", color
);
12482 color
= get_surface_color(rt
, 338, 262);
12483 ok(compare_color(color
, 0x00ffffff, 0), "(338, 262) has color 0x%08x.\n", color
);
12484 color
= get_surface_color(rt
, 342, 262);
12485 ok(compare_color(color
, 0x00ffffff, 0), "(342, 262) has color 0x%08x.\n", color
);
12487 /* COLORWRITEENABLE, SRGBWRITEENABLE and scissor rectangles do not exist
12490 IDirect3DViewport2_Release(viewport3
);
12491 IDirect3DViewport2_Release(viewport2
);
12492 IDirect3DViewport2_Release(viewport
);
12493 IDirect3DMaterial2_Release(white
);
12494 IDirect3DMaterial2_Release(red
);
12495 IDirect3DMaterial2_Release(green
);
12496 IDirect3DMaterial2_Release(blue
);
12497 IDirectDrawSurface_Release(rt
);
12498 refcount
= IDirect3DDevice2_Release(device
);
12499 ok(!refcount
, "Device has %u references left.\n", refcount
);
12500 refcount
= IDirectDraw2_Release(ddraw
);
12501 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
12502 DestroyWindow(window
);
12507 DDDEVICEIDENTIFIER identifier
;
12508 DEVMODEW current_mode
;
12509 IDirectDraw2
*ddraw
;
12512 if (!(ddraw
= create_ddraw()))
12514 skip("Failed to create a ddraw object, skipping tests.\n");
12518 if (ddraw_get_identifier(ddraw
, &identifier
))
12520 trace("Driver string: \"%s\"\n", identifier
.szDriver
);
12521 trace("Description string: \"%s\"\n", identifier
.szDescription
);
12522 trace("Driver version %d.%d.%d.%d\n",
12523 HIWORD(U(identifier
.liDriverVersion
).HighPart
), LOWORD(U(identifier
.liDriverVersion
).HighPart
),
12524 HIWORD(U(identifier
.liDriverVersion
).LowPart
), LOWORD(U(identifier
.liDriverVersion
).LowPart
));
12526 IDirectDraw2_Release(ddraw
);
12528 memset(¤t_mode
, 0, sizeof(current_mode
));
12529 current_mode
.dmSize
= sizeof(current_mode
);
12530 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
12531 registry_mode
.dmSize
= sizeof(registry_mode
);
12532 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
12533 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
12534 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
12536 skip("Current mode does not match registry mode, skipping test.\n");
12540 if ((dwmapi
= LoadLibraryA("dwmapi.dll")))
12541 pDwmIsCompositionEnabled
= (void *)GetProcAddress(dwmapi
, "DwmIsCompositionEnabled");
12543 test_coop_level_create_device_window();
12544 test_clipper_blt();
12545 test_coop_level_d3d_state();
12546 test_surface_interface_mismatch();
12547 test_coop_level_threaded();
12549 test_texture_load_ckey();
12558 test_window_style();
12559 test_redundant_mode_set();
12560 test_coop_level_mode_set();
12561 test_coop_level_mode_set_multi();
12563 test_coop_level_surf_create();
12564 test_coop_level_multi_window();
12565 test_clear_rect_count();
12566 test_coop_level_versions();
12567 test_lighting_interface_versions();
12568 test_coop_level_activateapp();
12569 test_unsupported_formats();
12571 test_primary_caps();
12572 test_surface_lock();
12573 test_surface_discard();
12575 test_set_surface_desc();
12576 test_user_memory_getdc();
12577 test_sysmem_overlay();
12578 test_primary_palette();
12579 test_surface_attachment();
12580 test_pixel_format();
12581 test_create_surface_pitch();
12583 test_palette_complex();
12587 test_specular_lighting();
12588 test_palette_gdi();
12589 test_palette_alpha();
12590 test_lost_device();
12591 test_surface_desc_lock();
12592 test_texturemapblend();
12593 test_viewport_clear_rect();
12595 test_colorkey_precision();
12596 test_range_colorkey();
12598 test_lockrect_invalid();
12599 test_yv12_overlay();
12600 test_offscreen_overlay();
12601 test_overlay_rect();
12603 test_blt_z_alpha();
12605 test_draw_primitive();
12606 test_edge_antialiasing_blending();
12607 test_transform_vertices();
12608 test_display_mode_surface_pixel_format();
12609 test_surface_desc_size();
12610 test_ck_operation();
12611 test_depth_readback();